mirror of
https://github.com/yaklang/yaklang-chrome-extension.git
synced 2026-09-26 21:21:53 +08:00
fix: 修复重连问题
This commit is contained in:
@@ -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
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user