Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a client-to-server-only call to list all the currently-connected users #57

Open
gridhead opened this issue Oct 17, 2020 · 9 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@gridhead
Copy link
Owner

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.

@gridhead gridhead added help wanted Extra attention is needed hacktoberfest Contribute to the notion of open-source this October! labels Oct 17, 2020
@gitarthasarma
Copy link
Contributor

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?

@gridhead
Copy link
Owner Author

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.

@gitarthasarma
Copy link
Contributor

gitarthasarma commented Oct 17, 2020

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

@thevivekmnair
Copy link
Contributor

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

@gitarthasarma
Copy link
Contributor

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.

@thevivekmnair
Copy link
Contributor

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.

@thevivekmnair
Copy link
Contributor

@t0xic0der can i work on this?

@gridhead
Copy link
Owner Author

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

I'm not sure if I understand what you are trying to say here @gitarthasarma. 😅 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.

@gitarthasarma
Copy link
Contributor

@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.

@gridhead gridhead removed the hacktoberfest Contribute to the notion of open-source this October! label Nov 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants