Skip to content

Commit

Permalink
remove auto-reconnect in favor of manual 'rejoin()' method
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed Jul 7, 2018
1 parent 944a896 commit fcb86db
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "colyseus.js",
"version": "0.9.8",
"version": "0.9.9",
"description": "Multiplayer Game Client for the Browser",
"keywords": [
"multiplayer",
Expand Down
14 changes: 6 additions & 8 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<T>(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;
Expand Down
8 changes: 0 additions & 8 deletions src/Room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ export interface RoomAvailable {
metadata?: any;
}

export const RECONNECTION_KEY = 'reconnection';

export class Room<T= any> extends StateContainer<T & any> {
public id: string;
public sessionId: string;
Expand Down Expand Up @@ -47,7 +45,6 @@ export class Room<T= any> extends StateContainer<T & any> {
this.options = options;

this.onLeave.add(() => {
this.refreshAutoReconnection();
this.removeAllListeners();
});
}
Expand Down Expand Up @@ -91,7 +88,6 @@ export class Room<T= any> extends StateContainer<T & any> {

if (code === Protocol.JOIN_ROOM) {
this.sessionId = message[1];
this.refreshAutoReconnection();
this.onJoin.dispatch();

} else if (code === Protocol.JOIN_ERROR) {
Expand All @@ -116,10 +112,6 @@ export class Room<T= any> extends StateContainer<T & any> {
}
}

protected refreshAutoReconnection() {
setItem(RECONNECTION_KEY, this.sessionId);
}

protected setState( encodedState: Buffer, remoteCurrentTime?: number, remoteElapsedTime?: number ): void {
const state = msgpack.decode(encodedState);
this.set(state);
Expand Down

0 comments on commit fcb86db

Please sign in to comment.