|
|
@@ -38,24 +38,26 @@ const store = new Vuex.Store({
|
|
|
actions: {
|
|
|
// 修改 action 以正确传递参数
|
|
|
initLiveWs({ commit, state }, { liveWsUrl, liveId, userId }) {
|
|
|
+ const normalizedLiveId = String(liveId);
|
|
|
// 如果已经存在对应 liveId 的连接,先关闭它
|
|
|
- if (state.liveWs[liveId]) {
|
|
|
- state.liveWs[liveId].close();
|
|
|
+ if (state.liveWs[normalizedLiveId]) {
|
|
|
+ state.liveWs[normalizedLiveId].close();
|
|
|
}
|
|
|
|
|
|
// 创建新的 WebSocket 连接
|
|
|
- const ws = new LiveWS(liveWsUrl, liveId, userId);
|
|
|
+ const ws = new LiveWS(liveWsUrl, normalizedLiveId, userId);
|
|
|
|
|
|
// 提交到 mutation
|
|
|
- commit('setLiveWs', { ws, liveId });
|
|
|
+ commit('setLiveWs', { ws, liveId: normalizedLiveId });
|
|
|
|
|
|
return ws;
|
|
|
},
|
|
|
// 添加关闭特定 WebSocket 连接的 action
|
|
|
closeLiveWs({ commit, state }, liveId) {
|
|
|
- if (state.liveWs[liveId]) {
|
|
|
- state.liveWs[liveId].close();
|
|
|
- commit('removeLiveWs', liveId);
|
|
|
+ const normalizedLiveId = String(liveId);
|
|
|
+ if (state.liveWs[normalizedLiveId]) {
|
|
|
+ state.liveWs[normalizedLiveId].close();
|
|
|
+ commit('removeLiveWs', normalizedLiveId);
|
|
|
}
|
|
|
}
|
|
|
}
|