Skip to content

Commit 88f8757

Browse files
committed
refactor(Websocket): 移除未使用的 tenant 计算属性并优化 WebSocket URI 生成
1 parent 500702f commit 88f8757

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/components/Websocket/index.vue

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ const token = computed(() => {
3232
return Session.getToken();
3333
});
3434
35-
const tenant = computed(() => {
36-
return Session.getTenant();
37-
});
38-
3935
onMounted(() => {
4036
initWebSocket();
4137
});
@@ -50,7 +46,9 @@ const initWebSocket = () => {
5046
let host = window.location.host;
5147
// baseURL
5248
let baseURL = import.meta.env.VITE_API_URL;
53-
let wsUri = `ws://${host}${baseURL}${other.adaptationUrl(props.uri)}?access_token=${token.value}&TENANT-ID=${tenant.value}`;
49+
// 自动判断协议:如果当前页面是 https,则使用 wss,否则使用 ws
50+
let protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
51+
let wsUri = `${protocol}//${host}${baseURL}${other.adaptationUrl(props.uri)}?access_token=${token.value}`;
5452
// 建立连接
5553
state.webSocket = new WebSocket(wsUri);
5654
// 连接成功

0 commit comments

Comments
 (0)