fix: 修复重连问题

This commit is contained in:
song_xiao_lin
2024-05-08 15:53:46 +08:00
parent 5ab87eec74
commit 98e585680a
3 changed files with 34 additions and 20 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
console.info("Start to connect websocket")
const host = msg['host'] || "127.0.0.1"
const port = msg['port'] || 11212
websocketManager.connectWebsocket(`ws://${host}:${port}/?token=${"a"}`)
websocketManager.connectWebsocket(`ws://${host}:${port}/?token=${"a"}`, port)
break;
case ActionType.DISCONNECT:
websocketManager.disconnectWebsocket();
+3 -3
View File
@@ -13,12 +13,12 @@ export class WebSocketManager {
this.intervalId = null;
}
connectWebsocket(url) {
connectWebsocket(url, port) {
this.disconnectWebsocket();
this.socket = new WebSocket(url);
this.socket.onopen = () => {
chrome.runtime.sendMessage({action: ActionType.STATUS, connected: true});
chrome.runtime.sendMessage({action: ActionType.STATUS, connected: true, port: port});
this.startHeartbeat();
};
@@ -27,7 +27,7 @@ export class WebSocketManager {
};
this.socket.onclose = () => {
chrome.runtime.sendMessage({action: ActionType.STATUS, connected: false});
chrome.runtime.sendMessage({action: ActionType.STATUS, connected: false, port: port});
};
this.socket.onerror = (error) => {