base-websocket
Advanced tools
Comparing version 1.0.7 to 1.0.8
{ | ||
"name": "base-websocket", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"description": "webSocket basic module", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
let a = () => { | ||
}, i = () => { | ||
}, s = !1; | ||
function f({ url: n, onOpen: t, onResponse: l, onError: c, onClose: r }) { | ||
if (s) | ||
}, r = () => { | ||
}, n = !1; | ||
function S({ | ||
url: t, | ||
onOpen: c = function() { | ||
}, | ||
onResponse: l = function() { | ||
}, | ||
onError: i = function() { | ||
}, | ||
onClose: f = function() { | ||
} | ||
}) { | ||
if (n) | ||
return; | ||
s = !0; | ||
const e = new WebSocket(n); | ||
n = !0; | ||
const e = new WebSocket(t); | ||
a = (o) => { | ||
e.send(JSON.stringify(o)); | ||
}, i = () => { | ||
console.log("WS CLOSE"), r(), e.close(), s = !1; | ||
}, r = () => { | ||
console.log("WS CLOSE"), f(), e.close(), n = !1; | ||
}, e.onopen = () => { | ||
t(); | ||
c(); | ||
}, e.onmessage = async (o) => { | ||
JSON.parse(await new Response(o.data).text()) && l(); | ||
console.log(o); | ||
const s = JSON.parse(await new Response(o.data).text()); | ||
s && l(s); | ||
}, e.onerror = (o) => { | ||
console.log("ERROR: ", o), s = !1, e.close(), c(); | ||
console.log("ERROR: ", o), n = !1, e.close(), i(); | ||
}, e.onclose = () => { | ||
@@ -24,5 +36,5 @@ console.log("CLOSE"); | ||
export { | ||
i as closeWS, | ||
f as initWebSocket, | ||
r as closeWS, | ||
S as initWebSocket, | ||
a as send | ||
}; |
1768
54