this.ctx.getWebSockets() return array of empty objects

When I run this.ctx.getWebSockets() from my durableObject it returns me an array of empty objects, but I expected to actually receive the websockets, what am I missing?
20 Replies
Hello, I’m Allie!
Are you just console.loging them?
gekkepop.
gekkepop.OP6mo ago
JSON.stringy them then console.log ing them
Hello, I’m Allie!
Yeah, I don't think they are stringifiable
gekkepop.
gekkepop.OP6mo ago
O
Hello, I’m Allie!
They are there
gekkepop.
gekkepop.OP6mo ago
How can I see their properties etc? Because I am not that familiar
gekkepop.
gekkepop.OP6mo ago
You were correct! If I just assume it contains a websocket, it actually has one Do you happen to know if the websockets have an id or a name I can use to reference them and make disctions between the websockets themselves? I don't see anything in the api Or do I just use the websocket itself as a id? So I can do ws === ws?
Hello, I’m Allie!
Give each a unique tag
gekkepop.
gekkepop.OP6mo ago
Yeah, but the problem is how do I relate a WebSocket to this unique tag I only have the websocket itself I want to do something like this: async fetch(request) { const webSocketPair = new WebSocketPair(); const [client, server] = Object.values(webSocketPair); this.sessions.set(client, crypto.randomUUID()); }
gekkepop.
gekkepop.OP6mo ago
GitHub
workers-chat-demo/src/chat.mjs at master · cloudflare/workers-chat-...
Contribute to cloudflare/workers-chat-demo development by creating an account on GitHub.
gekkepop.
gekkepop.OP6mo ago
(well similar), but for me it doesn't work
Hello, I’m Allie!
I wouldn't store the actual client anywhere, since that would defeat the purpose of the hibernation API
gekkepop.
gekkepop.OP6mo ago
But how would I send a message to a specific websocket? So let's say my durable object has a connection with a,b,c, and I want to send a message from a -> c, how can I do that? I need some way to get the correct websocket for C based on the input of A, so I need some kind of pointer
Hello, I’m Allie!
this.ctx.getWebSockets("c")
gekkepop.
gekkepop.OP6mo ago
But how do I give them a tag? How do I know incoming messager from a websocket is for example "A" or "B" or "C" InacceptWebSocket?
Hello, I’m Allie!
this.ctx.acceptWebSocket(server, ["c"])
gekkepop.
gekkepop.OP6mo ago
O, and then I can use getTags to see which websocket is currently sending I think I finally get it
Hello, I’m Allie!
Yeah
gekkepop.
gekkepop.OP6mo ago
Thanks a lot for the help, really helped me out here!
Want results from more Discord servers?
Add your server