From fcb86dbf37fea4255a137e0cea39a9493383fee9 Mon Sep 17 00:00:00 2001 From: Endel Dreyer Date: Sat, 7 Jul 2018 01:11:47 -0300 Subject: [PATCH] remove auto-reconnect in favor of manual 'rejoin()' method --- package.json | 2 +- src/Client.ts | 14 ++++++-------- src/Room.ts | 8 -------- 3 files changed, 7 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 33f068d..132b82d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "colyseus.js", - "version": "0.9.8", + "version": "0.9.9", "description": "Multiplayer Game Client for the Browser", "keywords": [ "multiplayer", diff --git a/src/Client.ts b/src/Client.ts index 8c7c9c3..fe7fe2e 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -3,7 +3,7 @@ import * as msgpack from './msgpack'; import { Connection } from './Connection'; import { Protocol } from './Protocol'; -import { RECONNECTION_KEY, Room, RoomAvailable } from './Room'; +import { Room, RoomAvailable } from './Room'; import { getItem, setItem } from './Storage'; export class Client { @@ -42,17 +42,15 @@ export class Client { this.connectingRooms[ options.requestId ] = room; - getItem(RECONNECTION_KEY, (reconnectingSessionId) => { - if (reconnectingSessionId) { - options.sessionId = reconnectingSessionId; - } - - this.connection.send([Protocol.JOIN_ROOM, roomName, options]); - }); + this.connection.send([Protocol.JOIN_ROOM, roomName, options]); return room; } + public rejoin(roomName: string, sessionId: string) { + return this.join(roomName, { sessionId }); + } + public getAvailableRooms(roomName: string, callback: (rooms: RoomAvailable[], err?: string) => void) { // reject this promise after 10 seconds. const requestId = ++this.requestId; diff --git a/src/Room.ts b/src/Room.ts index 7ec412b..4f284f8 100644 --- a/src/Room.ts +++ b/src/Room.ts @@ -17,8 +17,6 @@ export interface RoomAvailable { metadata?: any; } -export const RECONNECTION_KEY = 'reconnection'; - export class Room extends StateContainer { public id: string; public sessionId: string; @@ -47,7 +45,6 @@ export class Room extends StateContainer { this.options = options; this.onLeave.add(() => { - this.refreshAutoReconnection(); this.removeAllListeners(); }); } @@ -91,7 +88,6 @@ export class Room extends StateContainer { if (code === Protocol.JOIN_ROOM) { this.sessionId = message[1]; - this.refreshAutoReconnection(); this.onJoin.dispatch(); } else if (code === Protocol.JOIN_ERROR) { @@ -116,10 +112,6 @@ export class Room extends StateContainer { } } - protected refreshAutoReconnection() { - setItem(RECONNECTION_KEY, this.sessionId); - } - protected setState( encodedState: Buffer, remoteCurrentTime?: number, remoteElapsedTime?: number ): void { const state = msgpack.decode(encodedState); this.set(state);