From a12d5b07d9a676f8fee6d80e3e46ddf273107dd3 Mon Sep 17 00:00:00 2001 From: mei23 Date: Tue, 25 Sep 2018 04:04:23 +0900 Subject: [PATCH] =?UTF-8?q?WebScoket=E5=86=8D=E6=8E=A5=E7=B6=9A=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=86=8D=E5=BA=A6?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/ai.ts | 6 ++++-- src/modules/reversi/index.ts | 6 ++++-- src/modules/server/index.ts | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index bb41f26..2aacf5f 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "mecab-async": "0.1.2", "misskey-reversi": "0.0.5", "promise-retry": "1.1.1", - "reconnecting-websocket": "3.2.2", + "reconnecting-websocket": "4.0.0-rc5", "request": "2.87.0", "request-promise-native": "1.0.5", "seedrandom": "2.4.3", diff --git a/src/ai.ts b/src/ai.ts index 58e0b20..9bb7152 100644 --- a/src/ai.ts +++ b/src/ai.ts @@ -70,7 +70,7 @@ export default class 藍 { //#region Home stream this.connection = new ReconnectingWebSocket(`${config.wsUrl}/?i=${config.i}`, [], { - constructor: WebSocket + WebSocket: WebSocket }); this.connection.addEventListener('open', () => { @@ -79,6 +79,7 @@ export default class 藍 { this.connection.addEventListener('close', () => { console.log('home stream closed'); + this.connection._shouldReconnect && this.connection._connect() }); this.connection.addEventListener('message', message => { @@ -90,7 +91,7 @@ export default class 藍 { //#region Local timeline stream this.localTimelineConnection = new ReconnectingWebSocket(`${config.wsUrl}/local-timeline?i=${config.i}`, [], { - constructor: WebSocket + WebSocket: WebSocket }); this.localTimelineConnection.addEventListener('open', () => { @@ -99,6 +100,7 @@ export default class 藍 { this.localTimelineConnection.addEventListener('close', () => { console.log('local-timeline stream closed'); + this.localTimelineConnection._shouldReconnect && this.localTimelineConnection._connect() }); this.localTimelineConnection.addEventListener('message', message => { diff --git a/src/modules/reversi/index.ts b/src/modules/reversi/index.ts index a48898b..364e51a 100644 --- a/src/modules/reversi/index.ts +++ b/src/modules/reversi/index.ts @@ -23,7 +23,7 @@ export default class ReversiModule implements IModule { this.ai = ai; this.reversiConnection = new ReconnectingWebSocket(`${config.wsUrl}/games/reversi?i=${config.i}`, [], { - constructor: WebSocket + WebSocket: WebSocket }); this.reversiConnection.addEventListener('open', () => { @@ -32,6 +32,7 @@ export default class ReversiModule implements IModule { this.reversiConnection.addEventListener('close', () => { console.log('reversi stream closed'); + this.reversiConnection._shouldReconnect && this.reversiConnection._connect() }); this.reversiConnection.addEventListener('message', message => { @@ -97,7 +98,7 @@ export default class ReversiModule implements IModule { private onReversiGameStart = (game: any) => { // ゲームストリームに接続 const gw = new ReconnectingWebSocket(`${config.wsUrl}/games/reversi-game?i=${config.i}&game=${game.id}`, [], { - constructor: WebSocket + WebSocket: WebSocket }); function send(msg) { @@ -189,6 +190,7 @@ export default class ReversiModule implements IModule { gw.addEventListener('close', () => { console.log('reversi game stream closed'); + gw._shouldReconnect && gw._connect() }); } diff --git a/src/modules/server/index.ts b/src/modules/server/index.ts index 9d3586e..ca00db9 100644 --- a/src/modules/server/index.ts +++ b/src/modules/server/index.ts @@ -23,7 +23,7 @@ export default class ServerModule implements IModule { this.ai = ai; this.connection = new ReconnectingWebSocket(`${config.wsUrl}/server-stats`, [], { - constructor: WebSocket + WebSocket: WebSocket }); this.connection.addEventListener('open', () => { @@ -32,6 +32,7 @@ export default class ServerModule implements IModule { this.connection.addEventListener('close', () => { console.log('server-stats stream closed'); + this.connection._shouldReconnect && this.connection._connect() }); this.connection.addEventListener('message', message => {