cloudflare / cloudflare/partykit

Joining multiple rooms proxy?

Open
#282 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
TypeScript
Stars
1.3k
Forks
79
PR merge metrics
No merged PRs in 30d

Description

Any example how can I join multiple rooms? For example, an admin with 10 websites needs to join 10 rooms created to [embed the chat bot on his websites](https://github.com/ticketdesk-ai/ticketdesk-chat).

So, if I send a request to `/chatroom/all-rooms`, I need

```
const socket = usePartySocket({
host: "localhost:8787",
party: "chatroom",
room: "all-rooms",
});
```

```
app.use(
"*",
partyserverMiddleware({
options: {
onBeforeConnect: async (req) => {
const token = req.headers.get("authorization");
// Validate token
if (!token) return new Response("Unauthorized", { status: 401 });

// Get room names and join all
if(req.url.endsWith('all-rooms'))
const rooms : string[] = await getRooms(userId, token)

?? proxy to all chatroom/room1
// chatroom/room1
// chatroom/room2
}
}
})
);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.