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.3w ago
JSON.stringy them then console.log ing them
Hello, I’m Allie!
Yeah, I don't think they are stringifiable
gekkepop.
gekkepop.3w ago
O
Hello, I’m Allie!
They are there
gekkepop.
gekkepop.3w ago
How can I see their properties etc? Because I am not that familiar
gekkepop.
gekkepop.3w 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.3w 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.3w 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.3w 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.3w 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.3w 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.3w 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.3w ago
Thanks a lot for the help, really helped me out here!