From deab5bce91f0715e091a83ce6b1917d25787ac64 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 14 May 2021 23:49:09 +0900 Subject: [PATCH] refactor --- src/streaming.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/streaming.ts b/src/streaming.ts index be228ac38..a30ef5497 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -20,7 +20,7 @@ export default class Stream extends EventEmitter { private sharedConnections: SharedConnection[] = []; private nonSharedConnections: NonSharedConnection[] = []; - constructor(wsUrl: string, user: { token: string; } | null, options?: { + constructor(origin: string, user: { token: string; } | null, options?: { }) { super(); @@ -29,7 +29,9 @@ export default class Stream extends EventEmitter { _t: Date.now(), }); - this.stream = new ReconnectingWebsocket(`${wsUrl}?${query}`, '', { minReconnectionDelay: 1 }); // https://github.com/pladaria/reconnecting-websocket/issues/91 + this.stream = new ReconnectingWebsocket(`${origin.replace('http://', 'ws://').replace('https://', 'wss://')}/streaming?${query}`, '', { + minReconnectionDelay: 1 // https://github.com/pladaria/reconnecting-websocket/issues/91 + }); this.stream.addEventListener('open', this.onOpen); this.stream.addEventListener('close', this.onClose); this.stream.addEventListener('message', this.onMessage);