anhtran
anhtran

Reputation: 2044

Python - Broadcasting with WebSocket using AutobahnPython

I have read this example from AutobahnPython: https://github.com/tavendo/AutobahnPython/tree/master/examples/websocket/broadcast

It looks pretty easy to understand and practice. But I want to add a little more. Members who submit the correct secret string can send the messages, anyone else can only view the information transmitted. Any idea?

Thanks!

Upvotes: 1

Views: 1341

Answers (2)

johny
johny

Reputation: 11

Well it is purely your logic in the code. When you receive the message you are simply broadcasting it, what you have to do is to pass this onto a custom function, and there, do a check:

Create a temporary array that contains list of active authenticated users. when user logs on, it should send this special string, match it, if OK, add this user to this active user list array, if not don't add it. Later, call the bradcast function but rather then taking all online users, use this custom array instead.

That is all that you have to do.
Make sure when someone logs out, remove him from this array.

Upvotes: 1

oberstet
oberstet

Reputation: 22051

Actually, there is a ready to run example that includes both strong client authentication and fine-grained, flexible authorization for PubSub (publish and/or subscribe rights?) - also for RPC btw.

Disclaimer: I created Autobahn and work for Tavendo.

Upvotes: 3

Related Questions