W
Wasp-langβ€’14mo ago
pr0age

Socket.io namespaces support

Hello guys. I'd like to ask something related to the wasp websockets support. AFAIK it's based on socket.io. My question it's related to socket.io namespaces. It seems wasp socket.io wrapping doesn't expose this namespaces functionality (useSocket() hook doesn't seem to allow parameters). Am I right or is it able to use socket.io namespaces with wasp? Thanks in advance
10 Replies
MEE6
MEE6β€’14mo ago
Wohooo @pr0age, you just became a Waspeteer level 1!
martinsos
martinsosβ€’14mo ago
Ha, so that is a good question! Sockets are relatively new feature in Wasp and I haven't yet used them much, but @miho was on of the main devs behind implementing it, so let's hear first what he says. I do remember we discussed internally exactly this, the namespaces, since without those sockets don't make much sense (everything is just one big room, we need isolation), and I remember the conclusion was that those can be used with how Wasp is currently working, by defining them on the server side and that is it. But I would have to confirm that or have somebody confirm. I might be mixing namespaces with rooms though hm. @shayne might also have a good idea about this? (batsign / shaynesign lights in the sky :D)
shayne
shayneβ€’14mo ago
good question! super foggy on it now lol i think namespaces would work on the server side, since we gave access to io, but I don't think it would work on the client out of the box since you have to parameterize the initialization, but we don't give that override fn yet. but @miho may have a better idea since he cleaned up the client side for TS type sharing before merging.
miho
mihoβ€’14mo ago
Hey, sorry for jumping in late, we were traveling yesterday πŸ™‚
AFAIK it's based on socket.io.
Yep!
My question it's related to socket.io namespaces. It seems wasp socket.io wrapping doesn't expose this namespaces functionality (useSocket() hook doesn't seem to allow parameters). Am I right or is it able to use socket.io namespaces with wasp?
So yeah, on the client it seems we are not exposing the io to you and we are connect via the default namespace always. So our convenience methods won't help you with namespaces. We should upgrade our support for that! But in the meantime, what you can do, is write your own piece of code. Give me a few minutes to write it all down and I'll share a gist here πŸ™ƒ
pr0age
pr0ageβ€’14mo ago
Thank you all guys for your time! I think it would be very good for you to expose the namespaces/rooms socket.io features in your framework, since as you say, it's a good resource if you want some kind of isolation. It'd be great @miho if you can share this workaround, thank you by the way, very "curious" your full username @miho haha
miho
mihoβ€’14mo ago
So my full name is Mihovil (Croatian for Michael) thus my nickname is Miho πŸ˜„ buuuut there is also a pun in Mihodeputa πŸ˜„ I'll be sharing the workaround shortly, Socket.io is giving me some trouble
pr0age
pr0ageβ€’14mo ago
buuuut there is also a pun in Mihodeputa
yeah, I noticed the pun because I'm spanish, haha
miho
mihoβ€’14mo ago
Oooh which part of Spain? πŸ™‚ It was weird introducing myself in Spain I have to admit πŸ˜„ Here's the gist with the workaround: https://gist.github.com/infomiho/14cf8b5b6efb07ba4f7a3e1ec76f4381 1. Disable auto connect for the default socket 2. Introduce a /messages namespace on the server 3. Use a custom hook with io connecting to the namespace 4. Use the new hooks in MainPage It's nothing super advanced, but I wanted to wrap the namespace in a separate hook so it's more elegant to use πŸ™‚
Gist
Using Namespaces with Wasp WebSocket
Using Namespaces with Wasp WebSocket. GitHub Gist: instantly share code, notes, and snippets.
pr0age
pr0ageβ€’14mo ago
Oooh which part of Spain? πŸ™‚ It was weird introducing myself in Spain I have to admit πŸ˜„
hahaha. I'm from Granada, Andalucia (southern part of Spain), but been living in Madrid por 13 years already Thank you very much for the gist!!! Gonna take a look with my team. Thank you again! Thank you @miho , What you propose in the gist fits our current needs, so we're going to use this approach until you integrate the namespaces usage in the native useSocket hook. Thank you again!
martinsos
martinsosβ€’14mo ago
Nice @miho -> I made a GH issues based on what you did here, so we don't forget it and add it to Wasp! https://github.com/wasp-lang/wasp/issues/1474
GitHub
Add support for socket.io namespaces to Wasp's socket support Β· Iss...
In our client code, the useSocket hook, we don't allow specifying the socket.io namespace -> we will want to allow that! Here is a discord convo about this: https://discord.com/channels/6868...
Want results from more Discord servers?
Add your server