Skip to content

Commit

Permalink
add room.connection.isOpen() getter
Browse files Browse the repository at this point in the history
  • Loading branch information
endel committed May 5, 2023
1 parent 3f8c32e commit bde0b32
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 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.2",
"version": "0.15.3",
"description": "Colyseus Multiplayer SDK for JavaScript/TypeScript",
"author": "Endel Dreyer",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class Connection implements ITransport {
this.transport.send(data);
}


connect(url: string): void {
this.transport.connect(url);
}
Expand All @@ -21,4 +22,8 @@ export class Connection implements ITransport {
this.transport.close(code, reason);
}

get isOpen() {
return this.transport.isOpen;
}

}
3 changes: 2 additions & 1 deletion src/transport/ITransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export interface ITransportConstructor {
}

export interface ITransport {
isOpen: boolean;
send(data: ArrayBuffer | Array<number>): void;
connect(url: string): void;
close(code?: number, reason?: string): void;
}
}
6 changes: 5 additions & 1 deletion src/transport/WebSocketTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export class WebSocketTransport implements ITransport {
this.ws.close(code, reason);
}

}
get isOpen() {
return this.ws.readyState === WebSocket.OPEN;
}

}

0 comments on commit bde0b32

Please sign in to comment.