From dd134b4bdb1a9b04c72a84c7d74066817f9aca13 Mon Sep 17 00:00:00 2001 From: FruitRiin Date: Tue, 28 Feb 2023 00:56:01 +0900 Subject: [PATCH] =?UTF-8?q?streaming=20=E3=81=AE=E3=82=A8=E3=83=A9?= =?UTF-8?q?=E3=83=BC=E3=83=8F=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E3=82=92=E3=82=82=E3=81=86=E3=81=A1=E3=82=87=E3=81=A3=E3=81=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/streaming.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/streaming.ts b/src/streaming.ts index 92b8319..6e30115 100644 --- a/src/streaming.ts +++ b/src/streaming.ts @@ -54,6 +54,7 @@ export default class Stream extends EventEmitter { this.stream.addEventListener('open', this.onOpen); this.stream.addEventListener('close', this.onClose); this.stream.addEventListener('message', this.onMessage); + this.stream.addEventListener('error', console.error); } @autobind @@ -134,6 +135,17 @@ export default class Stream extends EventEmitter { } } + /** + * Callback of when error connection + */ + @autobind + private onError(): void { + if (this.state === 'connected') { + this.state = 'reconnecting'; + this.emit('_disconnected_'); + } + } + /** * Callback of when received a message from connection */ @@ -182,7 +194,10 @@ export default class Stream extends EventEmitter { */ @autobind public close(): void { - this.stream.close(); + // this.stream.readyState が CONNECTING とかのときにCLOSEすると死ぬ + if (this.stream.readyState === WebSocket.OPEN ) { + this.stream.close(); + } } }