jhzh
2025-04-03 db12897dc68c68d40c557aa59ad78022e2b30ac2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
let createWS = (url, callbackObj) =>{
    var ws = new WebSocket(url)
    WebSocket.prototype.sendJson = function (obj) {
        this.send(JSON.stringify(obj))
    }
    ws.onopen = function () {
        callbackObj.open && callbackObj.open(ws)
        setInterval(function () {
            ws.send(JSON.stringify({
                type: "heartbeat"
            }))
        }, 10000);
    }
    ws.onclose = function () {
        callbackObj.onclose && callbackObj.onclose(ws)
    }
    return ws
}
 
export default createWS;