|
@@ -1,5 +1,5 @@
|
|
import website from '~src/config/index'
|
|
import website from '~src/config/index'
|
|
-import {isNullES} from 'js-fast-way'
|
|
|
|
|
|
+import { isNullES } from 'js-fast-way'
|
|
|
|
|
|
// 长链接推送插件
|
|
// 长链接推送插件
|
|
export default class HcSocket {
|
|
export default class HcSocket {
|
|
@@ -14,7 +14,7 @@ export default class HcSocket {
|
|
socket.onclose = function () {
|
|
socket.onclose = function () {
|
|
console.log('link break')
|
|
console.log('link break')
|
|
}
|
|
}
|
|
- socket.onmessage = function ({data}) {
|
|
|
|
|
|
+ socket.onmessage = function ({ data }) {
|
|
if (typeof change !== 'function') {
|
|
if (typeof change !== 'function') {
|
|
return false
|
|
return false
|
|
} else {
|
|
} else {
|
|
@@ -22,7 +22,7 @@ export default class HcSocket {
|
|
}
|
|
}
|
|
//console.log("收到消息:", data)
|
|
//console.log("收到消息:", data)
|
|
}
|
|
}
|
|
- socket.onerror = function ({data}) {
|
|
|
|
|
|
+ socket.onerror = function ({ data }) {
|
|
console.log('link error:', data)
|
|
console.log('link error:', data)
|
|
}
|
|
}
|
|
this.socket = socket
|
|
this.socket = socket
|
|
@@ -30,10 +30,14 @@ export default class HcSocket {
|
|
|
|
|
|
//发送消息
|
|
//发送消息
|
|
static async send(data) {
|
|
static async send(data) {
|
|
- const dataStr = data + ",business";
|
|
|
|
|
|
+ const dataStr = data + ',business'
|
|
const is_socket = await this.isSocket()
|
|
const is_socket = await this.isSocket()
|
|
if (!is_socket) return false
|
|
if (!is_socket) return false
|
|
- this.socket.send(dataStr)
|
|
|
|
|
|
+ try {
|
|
|
|
+ this.socket?.send(dataStr)
|
|
|
|
+ } catch (e) {
|
|
|
|
+ console.error('WebSocket', e.message)
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//链接是否存在
|
|
//链接是否存在
|