|
@@ -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 {
|
|
@@ -9,29 +9,31 @@ export default class HcSocket {
|
|
static create(data, change) {
|
|
static create(data, change) {
|
|
const socket = new WebSocket(website.socket + data)
|
|
const socket = new WebSocket(website.socket + data)
|
|
socket.onopen = function () {
|
|
socket.onopen = function () {
|
|
- console.log('websocket 链接成功')
|
|
|
|
|
|
+ console.log('link success')
|
|
}
|
|
}
|
|
socket.onclose = function () {
|
|
socket.onclose = function () {
|
|
- console.log('websocket 链接已断开')
|
|
|
|
|
|
+ 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 {
|
|
change(JSON.parse(data))
|
|
change(JSON.parse(data))
|
|
}
|
|
}
|
|
|
|
+ //console.log("收到消息:", data)
|
|
}
|
|
}
|
|
- socket.onerror = function ({ data }) {
|
|
|
|
- console.log('websocket 发生错误:', data)
|
|
|
|
|
|
+ socket.onerror = function ({data}) {
|
|
|
|
+ console.log('link error:', data)
|
|
}
|
|
}
|
|
this.socket = socket
|
|
this.socket = socket
|
|
}
|
|
}
|
|
|
|
|
|
//发送消息
|
|
//发送消息
|
|
static async send(data) {
|
|
static async send(data) {
|
|
|
|
+ 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(data)
|
|
|
|
|
|
+ this.socket.send(dataStr)
|
|
}
|
|
}
|
|
|
|
|
|
//链接是否存在
|
|
//链接是否存在
|