|
|
@@ -27,15 +27,7 @@ class SocketUtil {
|
|
|
this.reconnectHandler = null;
|
|
|
this.lockReconnect = false;
|
|
|
|
|
|
- this.socket.onOpen(this.openSocket);
|
|
|
- // 监听消息
|
|
|
-
|
|
|
- this.socket.onMessage(this.onMessageSocket);
|
|
|
-
|
|
|
- // 监听Socket的关闭
|
|
|
- this.socket.onClose(this.closeSocket);
|
|
|
-
|
|
|
- this.socket.onError(this.errorSocket);
|
|
|
+ this.bindHandlerEvent();
|
|
|
|
|
|
// uni.onSocketOpen(function(res) {
|
|
|
// console.log("WebSocket连接已打开!");
|
|
|
@@ -47,6 +39,17 @@ class SocketUtil {
|
|
|
// uni.closeSocket();
|
|
|
// });
|
|
|
}
|
|
|
+ bindHandlerEvent() {
|
|
|
+ this.socket.onOpen(this.openSocket);
|
|
|
+ // 监听消息
|
|
|
+
|
|
|
+ this.socket.onMessage(this.onMessageSocket);
|
|
|
+
|
|
|
+ // 监听Socket的关闭
|
|
|
+ this.socket.onClose(this.closeSocket);
|
|
|
+
|
|
|
+ this.socket.onError(this.errorSocket);
|
|
|
+ }
|
|
|
connectSocket(url) {
|
|
|
let path = `ws://${url}`;
|
|
|
// #ifdef MP-WEIXIN
|
|
|
@@ -104,6 +107,7 @@ class SocketUtil {
|
|
|
if (this.retryTime < SocketConfig.retry) {
|
|
|
this.reconnectHandler = setTimeout(() => {
|
|
|
this.socket = this.connectSocket(this.url);
|
|
|
+ this.bindHandlerEvent();
|
|
|
this.lockReconnect = false;
|
|
|
}, 5000);
|
|
|
this.retryTime++;
|