|
@@ -34,6 +34,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
|
|
|
// 方法
|
|
|
actions: {
|
|
|
+ // 初始化socket
|
|
|
startHeartbeat() {
|
|
|
const self = this;
|
|
|
const _num = this.heartCheck.num;
|
|
@@ -70,7 +71,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
clearTimeout(this.heartCheck.serverTimeoutObj);
|
|
|
this.heartCheck.num = 3;
|
|
|
},
|
|
|
-
|
|
|
+ // 链接ws
|
|
|
connect(userUuid) {
|
|
|
console.log("开始连接...");
|
|
|
this.disconnect(); // 确保先断开现有连接
|
|
@@ -103,7 +104,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
this.reconnect();
|
|
|
};
|
|
|
},
|
|
|
-
|
|
|
+ // 处理消息
|
|
|
handleMessage(data) {
|
|
|
const MessageType = protobuf.lookupType("protocol.Message");
|
|
|
const reader = new FileReader();
|
|
@@ -140,7 +141,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
|
|
|
reader.readAsArrayBuffer(data);
|
|
|
},
|
|
|
-
|
|
|
+ // 处理WebRTC消息
|
|
|
webrtcConnection() {
|
|
|
if (!this.peer) return;
|
|
|
|
|
@@ -168,7 +169,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
-
|
|
|
+ // 断线重连
|
|
|
reconnect() {
|
|
|
if (
|
|
|
this.lockConnection ||
|
|
@@ -189,7 +190,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
this.lockConnection = false;
|
|
|
}, this.reconnectInterval);
|
|
|
},
|
|
|
-
|
|
|
+ // 重连
|
|
|
disconnect() {
|
|
|
if (this.socket) {
|
|
|
this.resetHeartbeat();
|
|
@@ -202,7 +203,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
}
|
|
|
this.reconnectAttempts = 0;
|
|
|
},
|
|
|
-
|
|
|
+ // 发送消息
|
|
|
sendMessage(messageData) {
|
|
|
if (!this.socket || this.socket.readyState !== WebSocket.OPEN) {
|
|
|
console.error("WebSocket未连接");
|
|
@@ -227,7 +228,7 @@ export const useWebSocketStore = defineStore("webSocketStore", {
|
|
|
return false;
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
+ // 发送WebRTC消息
|
|
|
dealWebRtcMessage(message) {
|
|
|
// 实现WebRTC消息处理逻辑
|
|
|
},
|