|
@@ -51,6 +51,12 @@
|
51
|
51
|
</div>
|
52
|
52
|
</div>
|
53
|
53
|
</minePupop>
|
|
54
|
+ <audio ref="orderSuccessMp3" id="orderSuccessMp3" muted>
|
|
55
|
+ <source src="@/assets/audio/order_success.mp3" />
|
|
56
|
+ </audio>
|
|
57
|
+ <audio ref="orderReadyMp3" id="orderReadyMp3" muted>
|
|
58
|
+ <source src="@/assets/audio/order_ready.mp3" />
|
|
59
|
+ </audio>
|
54
|
60
|
</div>
|
55
|
61
|
</template>
|
56
|
62
|
|
|
@@ -79,31 +85,39 @@ export default {
|
79
|
85
|
created () {
|
80
|
86
|
this.getUserInfo()
|
81
|
87
|
|
82
|
|
- console.log('开始连接...')
|
83
|
|
- let token = this.$store.state.comVal.token || localStorage.getItem('token')
|
84
|
|
- //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
|
85
|
|
- this.wsInstance = new WebSocket(`wss://ws.ijolijoli.com?access_token=${token}`);
|
86
|
|
- this.wsInstance.onopen = () => {
|
87
|
|
- //当WebSocket创建成功时,触发onopen事件
|
88
|
|
- console.log("连接成功");
|
89
|
|
- this.timer = setInterval(() => {
|
90
|
|
- this.wsInstance.send(JSON.stringify({type:'ping'}));
|
91
|
|
- }, 30000);
|
92
|
|
- }
|
93
|
|
- this.wsInstance.onmessage = (e) => {
|
94
|
|
- //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
95
|
|
- console.log('收到消息',e.data)
|
96
|
|
- let data = JSON.parse(e.data);
|
97
|
|
- console.log(data)
|
98
|
|
- }
|
99
|
|
- this.wsInstance.onclose = (e) => {
|
100
|
|
- //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
101
|
|
- console.log("连接已关闭");
|
102
|
|
- }
|
103
|
|
- this.wsInstance.onerror = (e) => {
|
104
|
|
- //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
105
|
|
- console.log(e);
|
|
88
|
+ console.log('开始连接...')
|
|
89
|
+ let token = this.$store.state.comVal.token || localStorage.getItem('token')
|
|
90
|
+ //申请一个WebSocket对象,参数是服务端地址,同http协议使用http://开头一样,WebSocket协议的url使用ws://开头,另外安全的WebSocket协议使用wss://开头
|
|
91
|
+ this.wsInstance = new WebSocket(`wss://ws.ijolijoli.com?access_token=${token}`);
|
|
92
|
+ this.wsInstance.onopen = () => {
|
|
93
|
+ //当WebSocket创建成功时,触发onopen事件
|
|
94
|
+ console.log("连接成功");
|
|
95
|
+ this.timer = setInterval(() => {
|
|
96
|
+ this.wsInstance.send(JSON.stringify({type:'ping'}));
|
|
97
|
+ }, 30000);
|
|
98
|
+ }
|
|
99
|
+ this.wsInstance.onmessage = (e) => {
|
|
100
|
+ //当客户端收到服务端发来的消息时,触发onmessage事件,参数e.data包含server传递过来的数据
|
|
101
|
+ console.log('收到消息',e.data)
|
|
102
|
+ let data = JSON.parse(e.data);
|
|
103
|
+ if (data.data.type === 'order_success') {
|
|
104
|
+ console.log('预约成功信息播报')
|
|
105
|
+ this.$refs.orderSuccessMp3.play()
|
|
106
|
+ } else if (data.data.type === 'order_ready') {
|
|
107
|
+ // TODO: 播报动态语音还是固定的语音有待产品商榷
|
|
108
|
+ console.log('项目即将开始信息播报')
|
|
109
|
+ this.$refs.orderReadyMp3.play()
|
106
|
110
|
}
|
|
111
|
+ console.log(data)
|
|
112
|
+ }
|
|
113
|
+ this.wsInstance.onclose = (e) => {
|
|
114
|
+ //当客户端收到服务端发送的关闭连接请求时,触发onclose事件
|
|
115
|
+ console.log("连接已关闭");
|
|
116
|
+ }
|
|
117
|
+ this.wsInstance.onerror = (e) => {
|
|
118
|
+ //如果出现连接、处理、接收、发送数据失败的时候触发onerror事件
|
|
119
|
+ console.log(e);
|
|
120
|
+ }
|
107
|
121
|
},
|
108
|
122
|
components: {
|
109
|
123
|
leftMenu,
|