@colyseus/core
Version:
Multiplayer Framework for Node.js.
8 lines (7 loc) • 2.24 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/matchmaker/Lobby.ts"],
"sourcesContent": ["import * as matchMaker from '../MatchMaker.js';\n\nimport type { Room } from '../Room.js';\nimport { IRoomCache } from './driver/api.js';\n\nconst LOBBY_CHANNEL = '$lobby';\n\n/*\n * TODO: refactor this on v0.16\n *\n * Some users might be relying on \"1\" = \"removed\" from the lobby due to this workaround: https://github.com/colyseus/colyseus/issues/617\n * Though, for consistency, we should invert as \"0\" = \"invisible\" and \"1\" = \"visible\".\n *\n * - rename \"removed\" to \"isVisible\" and swap the logic\n * - emit \"visibility-change\" with inverted value (isVisible)\n * - update \"subscribeLobby\" to check \"1\" as \"isVisible\" instead of \"removed\"\n */\n\nexport function updateLobby(room: Room, removed: boolean = false) {\n const listing = room.listing;\n\n if (listing.unlisted) return;\n\n if (removed) {\n matchMaker.presence.publish(LOBBY_CHANNEL, `${listing.roomId},1`);\n } else if (!listing.private) {\n matchMaker.presence.publish(LOBBY_CHANNEL, `${listing.roomId},0`);\n }\n}\n\nexport async function subscribeLobby(callback: (roomId: string, roomListing: IRoomCache) => void) {\n const cb = async (message) => {\n const [roomId, isRemove] = message.split(',');\n\n if (isRemove === '1') {\n callback(roomId, null);\n\n } else {\n const room = (await matchMaker.query({ roomId }))[0];\n callback(roomId, room);\n }\n };\n\n await matchMaker.presence.subscribe(LOBBY_CHANNEL, cb);\n\n return () => matchMaker.presence.unsubscribe(LOBBY_CHANNEL, cb);\n}\n"],
"mappings": ";AAAA,YAAY,gBAAgB;AAK5B,IAAM,gBAAgB;AAaf,SAAS,YAAY,MAAY,UAAmB,OAAO;AAChE,QAAM,UAAU,KAAK;AAErB,MAAI,QAAQ,SAAU;AAEtB,MAAI,SAAS;AACX,IAAW,oBAAS,QAAQ,eAAe,GAAG,QAAQ,MAAM,IAAI;AAAA,EAClE,WAAW,CAAC,QAAQ,SAAS;AAC3B,IAAW,oBAAS,QAAQ,eAAe,GAAG,QAAQ,MAAM,IAAI;AAAA,EAClE;AACF;AAEA,eAAsB,eAAe,UAA6D;AAChG,QAAM,KAAK,OAAO,YAAY;AAC5B,UAAM,CAAC,QAAQ,QAAQ,IAAI,QAAQ,MAAM,GAAG;AAE5C,QAAI,aAAa,KAAK;AACpB,eAAS,QAAQ,IAAI;AAAA,IAEvB,OAAO;AACL,YAAM,QAAQ,MAAiB,iBAAM,EAAE,OAAO,CAAC,GAAG,CAAC;AACnD,eAAS,QAAQ,IAAI;AAAA,IACvB;AAAA,EACF;AAEA,QAAiB,oBAAS,UAAU,eAAe,EAAE;AAErD,SAAO,MAAiB,oBAAS,YAAY,eAAe,EAAE;AAChE;",
"names": []
}