diff options
| author | Shulhan <ms@kilabit.info> | 2023-10-24 03:41:47 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-10-24 22:28:25 +0700 |
| commit | 85c3fc0431e7e75a41894d4669f6a46bbda5440b (patch) | |
| tree | 15b73a82e9eaaa9ac9f2558578c8d7610ad392cd /websocket_client.ts | |
| parent | 891a860299ac76739d59f46280cbed63ff07743e (diff) | |
| download | pakakeh.ts-85c3fc0431e7e75a41894d4669f6a46bbda5440b.tar.xz | |
all: fix all linter warnings from tsc and eslint
In this changes we introduce eslint as our linter for TypeScript and
update our tsconfig to be more strict.
The ".eslintrc.yaml" and "tsconfig.json" is taken from golang/website
repository [1].
[1]: https://cs.opensource.google/go/x/website
Diffstat (limited to 'websocket_client.ts')
| -rw-r--r-- | websocket_client.ts | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/websocket_client.ts b/websocket_client.ts index 7ffdbc0..7e02982 100644 --- a/websocket_client.ts +++ b/websocket_client.ts @@ -58,12 +58,12 @@ export class WuiWebSocketClient { // request-response. // async Send(req: WuiWebSocketRequest): Promise<WuiResponseInterface> { - return new Promise((resolve, reject) => { - let wuiRes: WuiResponseInterface = { + return new Promise((resolve) => { + const wuiRes: WuiResponseInterface = { code: 0, message: "", }; - let reqQueue: RequestQueue = { + const reqQueue: RequestQueue = { req: req, cbSuccess: (res: WuiWebSocketResponse) => { wuiRes.code = res.code; @@ -87,26 +87,26 @@ export class WuiWebSocketClient { connect() { this.conn = new WebSocket(this.address); - this.conn.onclose = (ev: CloseEvent) => { - this.onClose(ev); + this.conn.onclose = () => { + this.onClose(); }; - this.conn.onerror = (ev: Event) => { - this.onError(ev); + this.conn.onerror = () => { + this.onError(); }; this.conn.onmessage = (ev: MessageEvent) => { this.onMessage(ev); }; - this.conn.onopen = (ev: Event) => { - this.onOpen(ev); + this.conn.onopen = () => { + this.onOpen(); }; } // onClose handle connection closed by cleaning up the request // queue. - onClose(ev: CloseEvent) { - for (let x = 0; x < this.requestQueue.length; x++) { - this.requestQueue[x].cbFail("connection closed"); - } + onClose() { + this.requestQueue.forEach((reqq) => { + reqq.cbFail("connection closed"); + }); this.isOpen = false; this.error = "connection is closed by server"; @@ -121,30 +121,29 @@ export class WuiWebSocketClient { } } - onError(ev: Event) { + onError() { if (this.opts.onError) { this.opts.onError(); } } onMessage(ev: MessageEvent) { - let res: WuiWebSocketResponse = JSON.parse(ev.data); + const res: WuiWebSocketResponse = JSON.parse(ev.data); - for (let x = 0; x < this.requestQueue.length; x++) { - let reqq = this.requestQueue[x]; + this.requestQueue.forEach((reqq, x) => { if (reqq.req.id === res.id) { reqq.cbSuccess(res); this.requestQueue.splice(x, 1); return; } - } + }); if (this.opts.onBroadcast && res.id == 0) { this.opts.onBroadcast(res); } } - onOpen(ev: Event) { + onOpen() { this.isOpen = true; this.error = ""; |
