sanctuary-zero
sanctuary-zero copied to clipboard
Add a client-to-server-only call to list all the currently-connected users
If I am a user and I wish to know the list of folks currently connected to the chatroom then I should have a convenient command called /list
to get the list of everyone connected at the moment.
Inside /cnew.py
, for every client we can maintain a dictionary with (key,value) as (serveraddr, [user1,user2,..])
. Next whenever any client runs the list
command, we will know from which server it is making the request, so we can return the value from that key. Will that work?
There are certain flaws to this approach here.
- Firstly, the list is to be maintained at the server end (namely
main.py
) so that the joining clients can convey their presence and querying clients can retrieve the list. - Also, keeping a list per server address is not very optimal as there would be only one server address. Instead, indexing with respect to the chatroom identity is advised.
Will this approach work?
Inside /cnew.py
under the producer_handler()
function, we need to handle for this /list
case and send a websocket request(don't know whether this is valid nomenclature) passing the current socket as data. Then inside main.py
we have the allus()
function which can return the list of all users connected provided we supply the chatroomid
Since there is already a map USERS
containing data about user and the chat-group they belong to, we can use that map to serve a list of users from server side when a /list
request with chatroomID comes in.
The request can be like - "/LIST"+sepr+chatroomID
Since there is already a map
USERS
containing data about user and the chat-group they belong to, we can use that map to serve a list of users from server side when a/list
request with chatroomID comes in. The request can be like -"/LIST"+sepr+chatroomID
But every user will already be associated with a chatroomID, so I feel we don't need any extra parameter with the request.
Since there is already a map
USERS
containing data about user and the chat-group they belong to, we can use that map to serve a list of users from server side when a/list
request with chatroomID comes in. The request can be like -"/LIST"+sepr+chatroomID
But every user will already be associated with a chatroomID, so I feel we don't need any extra parameter with the request.
Ya that should work.
@t0xic0der can i work on this?
Will this approach work? Inside
/cnew.py
under theproducer_handler()
function, we need to handle for this/list
case and send a websocket request(don't know whether this is valid nomenclature) passing the current socket as data. Then insidemain.py
we have theallus()
function which can return the list of all users connected provided we supply the chatroomid
I'm not sure if I understand what you are trying to say here @gitarthasarma. :sweat_smile: Could you please elaborate?
Since there is already a map
USERS
containing data about user and the chat-group they belong to, we can use that map to serve a list of users from server side when a/list
request with chatroomID comes in. The request can be like -"/LIST"+sepr+chatroomID
Wow yes. That approach would very likely work.
But every user will already be associated with a chatroomID, so I feel we don't need any extra parameter with the request.
That is true. We know from which chatroom, the /list
command is coming from so there's no need of an extra parameter.
Apologies for the delay in my responses. I am reaching out late beyond the office hours so it was some time before I could come to my desk for work.
@t0xic0der actually I was trying to figure out where the text msgs sent by the users inside chatrooms were handled inside 'cnew.py'. Inside there we can create a special case for user input '/list', there we will send a request to the server with the identity of the user attached(like the chatroomid). Inside the 'main.py' we can handle this request and we already have the 'getallus()' function which does all the hassle of finding out all users belonging to chatroomid. So using that we can return the list. But I am not so familiar with asyncio and websockets in python. So I don't know whether this is actually possible or not.