Skip to content

Commit

Permalink
refactor 'createMatchMakeRequest' for integration with @colyseus/play…
Browse files Browse the repository at this point in the history
…ground
  • Loading branch information
endel committed May 30, 2023
1 parent 5bb33ff commit 98b6d20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 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.15.8",
"version": "0.15.9",
"description": "Colyseus Multiplayer SDK for JavaScript/TypeScript",
"author": "Endel Dreyer",
"license": "MIT",
Expand Down
9 changes: 5 additions & 4 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class Client {
public async consumeSeatReservation<T>(
response: any,
rootSchema?: SchemaConstructor<T>,
previousRoom?: Room // used in devMode
reuseRoomInstance?: Room // used in devMode
): Promise<Room<T>> {
const room = this.createRoom<T>(response.room.name, rootSchema);
room.roomId = response.room.roomId;
Expand All @@ -118,7 +118,7 @@ export class Client {
options.reconnectionToken = response.reconnectionToken;
}

const targetRoom = previousRoom || room;
const targetRoom = reuseRoomInstance || room;
room.connect(this.buildEndpoint(response.room, options), response.devMode && (async () => {
console.info(`[Colyseus devMode]: ${String.fromCodePoint(0x1F504)} Re-establishing connection with room id '${room.roomId}'...`); // 🔄

Expand Down Expand Up @@ -161,7 +161,8 @@ export class Client {
method: string,
roomName: string,
options: JoinOptions = {},
rootSchema?: SchemaConstructor<T>
rootSchema?: SchemaConstructor<T>,
reuseRoomInstance?: Room,
) {
const response = (
await post(this.getHttpEndpoint(`${method}/${roomName}`), {
Expand All @@ -182,7 +183,7 @@ export class Client {
response.reconnectionToken = options.reconnectionToken;
}

return await this.consumeSeatReservation<T>(response, rootSchema);
return await this.consumeSeatReservation<T>(response, rootSchema, reuseRoomInstance);
}

protected createRoom<T>(roomName: string, rootSchema?: SchemaConstructor<T>) {
Expand Down

0 comments on commit 98b6d20

Please sign in to comment.