@interval/sdk
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -52,3 +52,2 @@ import type { WebSocket as NodeWebSocket, MessageEvent as NodeWSMessageEvent } from 'ws'; | ||
private timeouts; | ||
private isClosed; | ||
onMessage: Evt<string>; | ||
@@ -71,2 +70,3 @@ onOpen: Evt<void>; | ||
confirmAuthentication(): Promise<void>; | ||
get isOpen(): boolean; | ||
/** Both **/ | ||
@@ -73,0 +73,0 @@ /** |
@@ -71,9 +71,13 @@ "use strict"; | ||
set onopen(cb) { | ||
const handleOpen = () => { | ||
__classPrivateFieldSet(this, _DataChannelSocket_readyState, 'open', "f"); | ||
cb(); | ||
}; | ||
if ('onOpen' in this.dc) { | ||
// node | ||
this.dc.onOpen(cb); | ||
this.dc.onOpen(handleOpen); | ||
} | ||
else { | ||
// web | ||
this.dc.onopen = cb; | ||
this.dc.onopen = handleOpen; | ||
} | ||
@@ -157,3 +161,2 @@ } | ||
var _a, _b, _c; | ||
this.isClosed = false; | ||
this.pendingMessages = new Map(); | ||
@@ -173,3 +176,2 @@ this.onMessage = new evt_1.Evt(); | ||
this.onClose.attach(() => { | ||
this.isClosed = true; | ||
for (const timeout of this.timeouts) { | ||
@@ -181,3 +183,2 @@ clearTimeout(timeout); | ||
this.ws.onopen = () => { | ||
this.isClosed = false; | ||
this.onOpen.post(); | ||
@@ -198,3 +199,3 @@ }; | ||
} | ||
if (this.isClosed) | ||
if (!this.isOpen) | ||
return; | ||
@@ -248,3 +249,3 @@ const data = JSON.parse(evt.data.toString()); | ||
return new Promise((resolve, reject) => { | ||
if (this.ws.readyState === this.ws.OPEN && this.isAuthenticated) { | ||
if (this.isOpen && this.isAuthenticated) { | ||
return resolve(); | ||
@@ -265,2 +266,5 @@ } | ||
} | ||
get isOpen() { | ||
return this.ws.readyState === this.ws.OPEN; | ||
} | ||
/** Both **/ | ||
@@ -272,3 +276,3 @@ /** | ||
async send(data, options = {}) { | ||
if (this.isClosed) | ||
if (!this.isOpen) | ||
throw new NotConnectedError(); | ||
@@ -299,3 +303,2 @@ return new Promise((resolve, reject) => { | ||
close(code, reason) { | ||
this.isClosed = true; | ||
this.onMessage.detach(); | ||
@@ -316,3 +319,3 @@ return this.ws.close(code, reason); | ||
async ping() { | ||
if (this.isClosed) | ||
if (!this.isOpen) | ||
throw new NotConnectedError(); | ||
@@ -319,0 +322,0 @@ const ws = this.ws; |
{ | ||
"name": "@interval/sdk", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"description": "The frontendless framework for high growth companies. Interval automatically generates apps by inlining the UI in your backend code. It's a faster and more maintainable way to build internal tools, rapid prototypes, and more.", | ||
@@ -5,0 +5,0 @@ "homepage": "https://interval.com", |
Sorry, the diff of this file is too big to display
24618
1206741