Skip to content

Commit

Permalink
fix requestId to rotate after 255 calls. colyseus/colyseus#242
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed May 18, 2019
1 parent f1fd74d commit 1938dc1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/colyseus.js

Large diffs are not rendered by default.

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.10.5",
"version": "0.10.6",
"description": "Multiplayer Game Client for the Browser",
"keywords": [
"colyseus",
Expand Down
8 changes: 6 additions & 2 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class Client {

public getAvailableRooms(roomName: string, callback: (rooms: RoomAvailable[], err?: string) => void) {
// reject this promise after 15 seconds.
const requestId = ++this.requestId;
const requestId = this.getNextRequestId();
const removeRequest = () => delete this.roomsAvailableRequests[requestId];
const rejectionTimeout = setTimeout(() => {
removeRequest();
Expand Down Expand Up @@ -76,7 +76,7 @@ export class Client {
reuseRoomInstance?: Room<T>,
retryCount?: number,
) {
options.requestId = ++this.requestId;
options.requestId = this.getNextRequestId();

const room = reuseRoomInstance || this.createRoom<T>(roomName, options);

Expand Down Expand Up @@ -201,4 +201,8 @@ export class Client {

}

protected getNextRequestId() {
return (++this.requestId % 255);
}

}

0 comments on commit 1938dc1

Please sign in to comment.