forked from FoundKeyGang/FoundKey
Use ReconnectingWebSocket
This commit is contained in:
parent
aeed7952e7
commit
a1e5420b8f
1 changed files with 11 additions and 4 deletions
|
@ -7,7 +7,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as childProcess from 'child_process';
|
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 * as request from 'request-promise-native';
|
||||||
import conf from '../../../conf';
|
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', () => {
|
homeStream.on('open', () => {
|
||||||
console.log('home stream opened');
|
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', () => {
|
othelloStream.on('open', () => {
|
||||||
console.log('othello stream opened');
|
console.log('othello stream opened');
|
||||||
|
@ -127,7 +132,9 @@ othelloStream.on('message', message => {
|
||||||
*/
|
*/
|
||||||
function gameStart(game) {
|
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', () => {
|
gw.on('open', () => {
|
||||||
console.log('othello game stream opened');
|
console.log('othello game stream opened');
|
||||||
|
|
Loading…
Reference in a new issue