From 76d0a9cc5d8c4e8d1ce211cf129557bbba77d65e Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 2 Jul 2021 22:48:07 +0900 Subject: [PATCH] refactor --- src/streaming.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/streaming.ts b/src/streaming.ts index d8feb700b..8507f28a8 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -10,6 +10,8 @@ function urlQuery(obj: {}): string { .reduce((a, [k, v]) => (a[k] = v, a), {} as Record)); } +type AnyOf> = T[keyof T]; + type StreamEvents = { _connected_: void; _disconnected_: void; @@ -39,7 +41,9 @@ export default class Stream extends EventEmitter { _t: Date.now(), }); - this.stream = new ReconnectingWebsocket(`${origin.replace('http://', 'ws://').replace('https://', 'wss://')}/streaming?${query}`, '', { + const wsOrigin = origin.replace('http://', 'ws://').replace('https://', 'wss://'); + + this.stream = new ReconnectingWebsocket(`${wsOrigin}/streaming?${query}`, '', { minReconnectionDelay: 1, // https://github.com/pladaria/reconnecting-websocket/issues/91 WebSocket: options.WebSocket }); @@ -250,7 +254,7 @@ class Pool { } } -abstract class Connection extends EventEmitter { +abstract class Connection = any> extends EventEmitter { public channel: string; protected stream: Stream; public abstract id: string; @@ -281,7 +285,7 @@ abstract class Connection extend public abstract dispose(): void; } -class SharedConnection extends Connection { +class SharedConnection = any> extends Connection { private pool: Pool; public get id(): string { @@ -303,7 +307,7 @@ class SharedConnection extends C } } -class NonSharedConnection extends Connection { +class NonSharedConnection = any> extends Connection { public id: string; protected params: Channel['params'];