socket修改

This commit is contained in:
tdg930622 2025-01-15 14:20:01 +08:00
parent 40331ae769
commit f6d91a08f6
3 changed files with 9 additions and 5 deletions

View File

@ -176,6 +176,8 @@ export default {
sessionStorage.setItem('userInfo', JSON.stringify(res.user))
this.$store.commit('setUserInfo', res.user)
let socketUrl = `wss://mediate.dev.trydotec.com/mediate/ws/websocket`;
this.$stompSocket.initStomp(socketUrl,a => this.socketSucc(a), b => this.socketErr(b));
if (res.user.resources.length > 0) {
let url = "/workbench";
// let data= res.user.resources[0].children[0]
@ -186,7 +188,6 @@ export default {
// }
this.$store.commit('setRoutes', url)
this.$router.push(url)
this.$stompSocket.initStomp(a => this.socketSucc(a), b => this.socketErr(b));
} else {
this.$message.warning('未赋予数据权限!')
}

View File

@ -1,13 +1,13 @@
import {Client,Message }from '@stomp/stompjs';
let client = null;
let url = 'wss://mediate.dev.trydotec.com/mediate/ws/websocket';
// let url = `wss://mediate.dev.trydotec.com/mediate/ws/websocket`;
let subscriptionMap = {};
const socketClass = {
// 初始化
initStomp(succ, err) {
console.log('----过来了')
initStomp(url, succ, err) {
// console.log('----过来了')
client = new Client({
brokerURL: url,
debug: function (str) {
@ -29,7 +29,7 @@ const socketClass = {
publish(data) {
// data
// {
// destination: '/topic/general',
// destination: '/topic/video-room/{roomid}',
// body: 'Hello world',
// headers: { priority: '9' },
// }
@ -38,6 +38,7 @@ const socketClass = {
},
// 订阅
subscription(url, callback) {
// url: /topic/video-room/{roomid}
// callback = function (message) {
// // called when the client receives a STOMP message from the server
// if (message.body) {
@ -51,6 +52,7 @@ const socketClass = {
},
// 取消订阅
unsubscribe(url) {
// url: /topic/video-room/{roomid}
if (!client)return;
if (url){
const a = subscriptionMap[url];

View File

@ -0,0 +1 @@
import fetchApi from "@/services/fetchApi";