|
@@ -454,7 +454,7 @@ export default {
|
|
|
return `msg-${index}-${m.userId || 'unknown'}`;
|
|
return `msg-${index}-${m.userId || 'unknown'}`;
|
|
|
},
|
|
},
|
|
|
ensureSocket() {
|
|
ensureSocket() {
|
|
|
- if (!this.socket || !this.socket.ws || this.socket.ws.readyState !== WebSocket.OPEN) {
|
|
|
|
|
|
|
+ if (!this.socket) {
|
|
|
this.$message.error('WebSocket 未连接,请稍后重试');
|
|
this.$message.error('WebSocket 未连接,请稍后重试');
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
@@ -718,8 +718,9 @@ export default {
|
|
|
this.newMsg = '';
|
|
this.newMsg = '';
|
|
|
},
|
|
},
|
|
|
handleWsMessage(event) {
|
|
handleWsMessage(event) {
|
|
|
- let { code, data } = JSON.parse(event.data)
|
|
|
|
|
- if (code === 200) {
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ let { code, data } = JSON.parse(event.data)
|
|
|
|
|
+ if (code === 200) {
|
|
|
let { cmd } = data
|
|
let { cmd } = data
|
|
|
if (cmd === 'sendMsg') {
|
|
if (cmd === 'sendMsg') {
|
|
|
let message = JSON.parse(data.data)
|
|
let message = JSON.parse(data.data)
|
|
@@ -814,6 +815,9 @@ export default {
|
|
|
} else if (cmd === 'globalVisible') {
|
|
} else if (cmd === 'globalVisible') {
|
|
|
this.globalVisible = Number(data.status) === 1 || data.status === true;
|
|
this.globalVisible = Number(data.status) === 1 || data.status === true;
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ console.error('WebSocket message parse error:', e);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
getLive(){
|
|
getLive(){
|
|
@@ -859,16 +863,16 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
connectWebSocket() {
|
|
connectWebSocket() {
|
|
|
|
|
+ const liveId = String(this.liveId);
|
|
|
this.$store.dispatch('initLiveWs', {
|
|
this.$store.dispatch('initLiveWs', {
|
|
|
liveWsUrl: this.liveWsUrl,
|
|
liveWsUrl: this.liveWsUrl,
|
|
|
- liveId: this.liveId,
|
|
|
|
|
|
|
+ liveId,
|
|
|
userId: this.userId
|
|
userId: this.userId
|
|
|
- }).then((ws) => {
|
|
|
|
|
- this.socket = ws || this.$store.state.liveWs[this.liveId]
|
|
|
|
|
- if (this.socket) {
|
|
|
|
|
- this.socket.onmessage = (event) => this.handleWsMessage(event)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ this.socket = this.$store.state.liveWs[liveId];
|
|
|
|
|
+ if (this.socket) {
|
|
|
|
|
+ this.socket.onmessage = (event) => this.handleWsMessage(event);
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
changeUserState(u) {
|
|
changeUserState(u) {
|
|
|
const displayList = this[`${this.currentTab}DisplayList`];
|
|
const displayList = this[`${this.currentTab}DisplayList`];
|