-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
compatibility with latest @colyseus/core
- Loading branch information
Showing
9 changed files
with
3,233 additions
and
2,097 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,23 @@ | ||
import { Server } from '@colyseus/core'; | ||
import http from "http"; | ||
import { Server, Room, Client, ClientState } from '@colyseus/core'; | ||
|
||
const originalDefine = Server.prototype.define; | ||
export const allRoomNames: string[] = []; | ||
|
||
// @ts-ignore | ||
Server.prototype.define = function(name, handler, options) { | ||
allRoomNames.push(name); | ||
const original_onJoin = Room.prototype._onJoin; | ||
|
||
Room.prototype._onJoin = async function(client: Client, req?: http.IncomingMessage) { | ||
const result = await original_onJoin.apply(this, arguments); | ||
|
||
const definition = originalDefine.call(this, name, handler, options); | ||
if (client.state === ClientState.JOINING) { | ||
client.send("__playground_message_types", Object.keys(this['onMessageHandlers'])); | ||
} | ||
|
||
// notify client about all registered message handlers | ||
definition.on("join", (room, client) => { | ||
client.send("__playground_message_types", Object.keys(room['onMessageHandlers'])); | ||
}); | ||
return result; | ||
} | ||
|
||
return definition | ||
// @ts-ignore | ||
Server.prototype.define = function(name, handler, options) { | ||
allRoomNames.push(name); | ||
return originalDefine.call(this, name, handler, options); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters