You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
525 B
20 lines
525 B
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;
|