From a1e5420b8ffbb13097d65dfa5ea677f0a7e034f0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Wed, 14 Mar 2018 06:58:40 +0900 Subject: [PATCH] Use ReconnectingWebSocket --- src/common/othello/ai/front.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/common/othello/ai/front.ts b/src/common/othello/ai/front.ts index 99cf1a712..838e5a143 100644 --- a/src/common/othello/ai/front.ts +++ b/src/common/othello/ai/front.ts @@ -7,7 +7,8 @@ */ import * as childProcess from 'child_process'; -import * as WebSocket from 'ws'; +const WebSocket = require('ws'); +import * as ReconnectingWebSocket from 'reconnecting-websocket'; import * as request from 'request-promise-native'; import conf from '../../../conf'; @@ -28,7 +29,9 @@ const id = conf.othello_ai.id; /** * ホームストリーム */ -const homeStream = new WebSocket(`wss://api.misskey.xyz/?i=${i}`); +const homeStream = new ReconnectingWebSocket(`wss://api.misskey.xyz/?i=${i}`, undefined, { + constructor: WebSocket +}); homeStream.on('open', () => { console.log('home stream opened'); @@ -97,7 +100,9 @@ function invite(userId) { /** * オセロストリーム */ -const othelloStream = new WebSocket(`wss://api.misskey.xyz/othello?i=${i}`); +const othelloStream = new ReconnectingWebSocket(`wss://api.misskey.xyz/othello?i=${i}`, undefined, { + constructor: WebSocket +}); othelloStream.on('open', () => { console.log('othello stream opened'); @@ -127,7 +132,9 @@ othelloStream.on('message', message => { */ function gameStart(game) { // ゲームストリームに接続 - const gw = new WebSocket(`wss://api.misskey.xyz/othello-game?i=${i}&game=${game.id}`); + const gw = new ReconnectingWebSocket(`wss://api.misskey.xyz/othello-game?i=${i}&game=${game.id}`, undefined, { + constructor: WebSocket + }); gw.on('open', () => { console.log('othello game stream opened');