mdl29 / scratchy

Scratchy, application de tchat projet LPH
GNU General Public License v3.0
2 stars 8 forks source link

252 [Back] Add flask socketio #269

Open Draeggon opened 2 years ago

Draeggon commented 2 years ago

i have implemented socketio on the method to get room, @yannis-mlgrn or @viandoxdev could you test if it work on the js side (normally by creating a socket and sending the message "get" you should get the room)

viandoxdev commented 2 years ago

I'll test. Nvm I can't get docker-compose to work. Also, the only thing we really need to do with sockets (for now) is updates, so the simplest way would be to just broadcast (from the server) an update_msg message with no data to every client, to inform them that a new message has been sent. A much less naive way would be to only update clients that are in the correct room (see socketio rooms maybe).

yannis-mlgrn commented 2 years ago

We should just implented websocket for messages updating in the current room ( or maybe every room where the user is added) But also for update these messages more easily and avoid to DDOS the server because every second all users connected send a HTTP request. This improvement will we allow to add also the "is writing" state

yannis-mlgrn commented 2 years ago

Add websocket for :

And we needed to add this fonctionnality in the service.ts and use it in the application

viandoxdev commented 2 years ago

So, summary of what needs to be done with websockets:

The server should handle rooms like so: When a user "goes" into a room (channel), it should send a join event, the server then places the user in the right socketio room. Then when a user sends a message, the server should react by sending a message event to everyone in the room (except for the sending user, with skip_sid).

The server should also send events informing that a user has joined/left (The user clicked in/off or logged off) the current room.

The server should also now keep track of which user is writing, probably not in the Database, but maybe in a big Map<RoomId, UserId[]> at runtime, as that data isn't really important anyways. The server should also now provide two events for that: start_writing and stop_writing, as well as writing_state, that it would send to users of a room along a list of currently writing userId whenever that state changes.

Events

From server to client(s)

From client to server

Questions

test

Also see middlewares for auth, even if we won't run any actual check on the backend, we need to be able to associate a websocket connection and a scratchy user.