miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
272 stars 24 forks source link

Join/Leave Rooms #76

Closed nbyloff closed 5 months ago

nbyloff commented 5 months ago

I've got a web service that will only connect to the wss:// protocol so I can't use flask-socketio. This package works perfect, except the one thing I need to do is emit messages to specific users sometimes. Sure enough you did a demo with a great solution for my issue.

This package doesn't use namespaces, but looking at the basic_enter_room function, could the same functions for joining/leaving rooms, emitting messages to specific rooms, be added to this class?

If @miguelgrinberg sees this, is it a heavy lift to add something like this? I don't know how much more there is to managing these connections and rooms, but your rooms solution is perfect for me I just need need the wss:// protocol.

If preferred, I'd be happy to do a pull request if it's as simple as I make it sound. :)

miguelgrinberg commented 5 months ago

I guess it is possible, but this package isn't the right place for such a hight level feature. You can create a separate package that implements rooms on top of it, though.

nbyloff commented 5 months ago

Fair enough. This was just the only stable package I could find that supported the wss protocol. I'll roll my own. Thanks!

JarriqTheTechie commented 5 months ago

Fair enough. This was just the only stable package I could find that supported the wss protocol. I'll roll my own. Thanks!

When you complete it maybe link in the comments here. I've seen this come up several times.

nbyloff commented 5 months ago

When you complete it maybe link in the comments here. I've seen this come up several times.

Will do. I still think it's worthwhile adding it to this package, especially if others asked for it too. flask-sock is a great compliment to flask-socketio for users who can't use http. I may just add some code to control the messaging in my code instead of an additional package on top of this. Whichever route I go, I'll share.

miguelgrinberg commented 5 months ago

@nbyloff you seem to have a misunderstanding of what Flask-SocketIO can or cannot do. You can configure it to work with WebSocket only, with HTTP only, or with both HTTP and WebSocket together.

This package is a simple WebSocket integration. Since the WebSocket protocol does not have a concept of rooms, such a high-level feature does not belong here, regardless of being a useful feature, which I agree that it is.

nbyloff commented 5 months ago

@nbyloff you seem to have a misunderstanding of what Flask-SocketIO can or cannot do. You can configure it to work with WebSocket only, with HTTP only, or with both HTTP and WebSocket together.

This package is a simple WebSocket integration. Since the WebSocket protocol does not have a concept of rooms, such a high-level feature does not belong here, regardless of being a useful feature, which I agree that it is.

I did misunderstand, thanks for clarifying. I mentioned it specifically several times because I tried to demo a remote service that uses websockets and use socketio. I was told they can't/won't support socketio because the connection wasn't working and I should use this package instead. When I asked them why, I was told it's because the vendor only supports wss:// connections.

It looks more like a difference in handshake between packages. Thanks for the clarification!

miguelgrinberg commented 5 months ago

The problem is that you continue to mix up things that work at different levels. When you say wss:// all you are saying is that a WebSocket connection is used, but you are not saying what format the data that is exchanged is, which is something that the client and the server must agree on.

If the server is a Socket.IO server, then you need to use a Socket.IO client to connect. If the server is not a Socket.IO server, then you need to figure out what protocol the server speaks, and use a client that is compatible with that.

nbyloff commented 5 months ago

That's what I meant about the difference in "handshake". I started with the assumption the clients & servers were interchangeable like browsers and web servers. I know better now. Sorry for the confusion.