房间的订阅代码调整
This commit is contained in:
parent
f9bca1759d
commit
e0824e33a0
@ -221,6 +221,8 @@ const socket = {
|
||||
|
||||
permissionOver: {}, // 权限结束
|
||||
|
||||
roomIsSubscribe:false, // 房间是否订阅
|
||||
|
||||
tipOperateCount: 0, // 任务结束提示消息
|
||||
realDeviceInfo: 0, // 真实设备信息
|
||||
beLogoutCount: 0 // 被登出
|
||||
@ -276,6 +278,9 @@ const socket = {
|
||||
|
||||
setRoomInvite: (state, roomInvite) => {
|
||||
state.roomInvite = roomInvite;
|
||||
},
|
||||
setRoomSubscribe:(state, roomIsSubscribe)=>{
|
||||
state.roomIsSubscribe = roomIsSubscribe;
|
||||
}
|
||||
},
|
||||
|
||||
@ -337,6 +342,9 @@ const socket = {
|
||||
|
||||
pushMsgQueue: ({ commit }, msg) => {
|
||||
commit('pushMsgQueue', msg);
|
||||
},
|
||||
setRoomSubscribe:({ commit }, msg) => {
|
||||
commit('setRoomSubscribe', msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -149,7 +149,7 @@ StompClient.prototype = {
|
||||
if (subscription && subscription.sub) {
|
||||
subscription.sub.unsubscribe();
|
||||
this.subscribeMap.delete(topic);
|
||||
console.log('取消订阅');
|
||||
console.log('取消订阅:' + topic);
|
||||
} else if (subscription) {
|
||||
this.subscribeMap.delete(topic);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import store from '@/store';
|
||||
|
||||
export const displayTopic = '/user/queue/simulation'; // 其他仿真topic
|
||||
export const perpetualTopic = '/user/topic/message'; // 公用topic
|
||||
export const roomTopic = '/user/queue/room'; // 房间topic
|
||||
|
||||
// 建立连接并订阅地址
|
||||
export function creatSubscribe(topic, header) {
|
||||
|
@ -26,6 +26,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { creatSubscribe, clearSubscribe, roomTopic} from '@/utils/stomp';
|
||||
import MapSystemDraft from '@/views/mapsystem/index';
|
||||
import MenuDemonJoint from './menuDemon';
|
||||
import MenuDemonSchema from './menuSchema';
|
||||
@ -159,6 +161,7 @@ export default {
|
||||
async mounted() {
|
||||
await this.setWindowSize();
|
||||
await this.initLoadData();
|
||||
await this.subscribe();
|
||||
},
|
||||
async beforeDestroy() {
|
||||
await this.clearAllTimer();
|
||||
@ -390,6 +393,18 @@ export default {
|
||||
this.$store.dispatch('config/resize', { width: this.width, height: this.height });
|
||||
this.$store.dispatch('training/updateOffsetStationCode', { offsetStationCode: this.offsetStationCode });
|
||||
});
|
||||
},
|
||||
async subscribe() {
|
||||
if (!this.$store.state.socket.roomIsSubscribe) {
|
||||
this.clearSubscribe();
|
||||
const header = { group: this.group || '', 'X-Token': getToken() };
|
||||
creatSubscribe(`${roomTopic}\/${this.group}`, header);
|
||||
await this.$store.dispatch('socket/setRoomSubscribe', true);
|
||||
}
|
||||
},
|
||||
async clearSubscribe() {
|
||||
clearSubscribe(`${roomTopic}\/${this.group}`);
|
||||
await this.$store.dispatch('socket/setRoomSubscribe', false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -382,6 +382,7 @@ export default {
|
||||
try {
|
||||
this.disabled = true;
|
||||
await putJointTrainingExit(this.group);
|
||||
this.$emit('clearSubscribe');
|
||||
this.$router.go(-1);
|
||||
} catch (error) {
|
||||
this.disabled = false;
|
||||
|
@ -26,6 +26,7 @@
|
||||
:door-list="doorList"
|
||||
@message="messageInfo"
|
||||
@joinTraining="jumpInSimulation"
|
||||
@clearSubscribe="clearSubscribe"
|
||||
/>
|
||||
<e-chat
|
||||
class="room__container--chat"
|
||||
@ -40,6 +41,8 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getToken } from '@/utils/auth';
|
||||
import { creatSubscribe, clearSubscribe, roomTopic} from '@/utils/stomp';
|
||||
import eMembers from './e-members';
|
||||
import eChat from './e-chat';
|
||||
import eRoles from './e-roles';
|
||||
@ -121,6 +124,7 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
async loadInit() {
|
||||
await this.subscribe();
|
||||
await this.getRoomInfo();
|
||||
await this.getUserList();
|
||||
await this.getStandList();
|
||||
@ -188,11 +192,14 @@ export default {
|
||||
Object.assign(this.room, room);
|
||||
switch (room.state) {
|
||||
case '03': // 房间销毁
|
||||
{ this.clearSubscribe();
|
||||
this.$router.go(-1);
|
||||
break;
|
||||
break; }
|
||||
case '02': // 开始仿真
|
||||
{
|
||||
// this.clearSubscribe();
|
||||
await this.jumpInSimulation();
|
||||
break;
|
||||
break; }
|
||||
}
|
||||
|
||||
// 清空房间信息
|
||||
@ -272,6 +279,18 @@ export default {
|
||||
},
|
||||
messageInfo(info) {
|
||||
this.$message({ showClose: true, ...info });
|
||||
},
|
||||
async subscribe() {
|
||||
if (!this.$store.state.socket.roomIsSubscribe) {
|
||||
this.clearSubscribe();
|
||||
const header = { group: this.group || '', 'X-Token': getToken() };
|
||||
creatSubscribe(`${roomTopic}\/${this.group}`, header);
|
||||
await this.$store.dispatch('socket/setRoomSubscribe', true);
|
||||
}
|
||||
},
|
||||
async clearSubscribe() {
|
||||
clearSubscribe(`${roomTopic}\/${this.group}`);
|
||||
await this.$store.dispatch('socket/setRoomSubscribe', false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user