diff --git a/src/routes/ably-auth/+server.ts b/src/routes/ably-auth/+server.ts index d1869cf..2b08703 100644 --- a/src/routes/ably-auth/+server.ts +++ b/src/routes/ably-auth/+server.ts @@ -14,13 +14,15 @@ export const GET = async ({ locals }) => { 500, "An unexpected error occurred while trying to retrieve your user data", ); + const channels = ["player:*:" + locals.user.id]; + for (const player of userData.players) { + channels.push("game:" + player.gameId + ":*"); + } return json( await ablyServer.auth.createTokenRequest({ - capability: userData.players.reduce( - (acc, player) => { - acc["game:" + player.gameId] = ["subscribe"]; - acc["game:" + player.gameId + ":announcements"] = ["subscribe"]; - acc["game:" + player.gameId + ":" + locals.user.id] = ["subscribe"]; + capability: channels.reduce( + (acc, channel) => { + acc[channel] = ["subscribe"]; return acc; }, {} as { [key: string]: ["subscribe"] }, diff --git a/src/routes/game/[gameId=id]/+page.svelte b/src/routes/game/[gameId=id]/+page.svelte index b2d2293..8c68ec8 100644 --- a/src/routes/game/[gameId=id]/+page.svelte +++ b/src/routes/game/[gameId=id]/+page.svelte @@ -12,7 +12,7 @@ ablyClientStore.subscribe(async (ablyClient) => { if (!ablyClient) return; await ablyClient.channels - .get("game:" + $page.params.gameId) + .get("game:" + $page.params.gameId + ":positions") .subscribe((message) => { switch (message.name) { case "move": @@ -21,7 +21,7 @@ } }); await ablyClient.channels - .get("game:" + $page.params.gameId + ":" + data.userId) + .get("player:" + $page.params.gameId + ":" + data.userId) .subscribe((message) => { switch (message.name) { case "points": diff --git a/src/routes/game/[gameId=id]/answer/+server.ts b/src/routes/game/[gameId=id]/answer/+server.ts index 5cda815..eea77c8 100644 --- a/src/routes/game/[gameId=id]/answer/+server.ts +++ b/src/routes/game/[gameId=id]/answer/+server.ts @@ -36,10 +36,12 @@ export const POST = async ({ request, params, locals }) => { currMoveId: null, }, }); - await ablyServer.channels.get("game:" + params.gameId).publish("move", { - userId: locals.user.id, - svgRef: player.currMove.svgRef, - }); + await ablyServer.channels + .get("game:" + params.gameId + ":positions") + .publish("move", { + userId: locals.user.id, + svgRef: player.currMove.svgRef, + }); } return json({ correct }); }; diff --git a/src/routes/game/[gameId=id]/shop/+page.svelte b/src/routes/game/[gameId=id]/shop/+page.svelte index 18a4f63..3cc990a 100644 --- a/src/routes/game/[gameId=id]/shop/+page.svelte +++ b/src/routes/game/[gameId=id]/shop/+page.svelte @@ -16,7 +16,7 @@ ablyClientStore.subscribe(async (ablyClient) => { if (!ablyClient) return; await ablyClient.channels - .get("game:" + $page.params.gameId + ":" + data.userId) + .get("player:" + $page.params.gameId + ":" + data.userId) .subscribe((message) => { switch (message.name) { case "points": diff --git a/src/routes/game/[gameId=id]/shop/[itemId=id]/buy/+server.ts b/src/routes/game/[gameId=id]/shop/[itemId=id]/buy/+server.ts index 88d5146..5f8b604 100644 --- a/src/routes/game/[gameId=id]/shop/[itemId=id]/buy/+server.ts +++ b/src/routes/game/[gameId=id]/shop/[itemId=id]/buy/+server.ts @@ -24,10 +24,12 @@ async function moveRoom( where: { id: playerId }, data: { currRoomId: roomId }, }); - await ablyServer.channels.get("game:" + gameId).publish("move", { - userId: userId, - svgRef: svgRef, - }); + await ablyServer.channels + .get("game:" + gameId + ":positions") + .publish("move", { + userId: userId, + svgRef: svgRef, + }); } const ACTIONS: { [key: string]: (details: ActionDetails) => Promise } = { @@ -129,7 +131,7 @@ const ACTIONS: { [key: string]: (details: ActionDetails) => Promise } = { data: { points: newPoints }, }); await ablyServer.channels - .get("game:" + gameId + ":" + randPlayer.userId) + .get("player:" + gameId + ":" + randPlayer.userId) .publish("points", { points: newPoints, });