This commit adds a '/metrics' endpoint in the API that can be exploited by Prometheus.
This endpoint returns:
- the number of connected sockets
- the number of users per room
- common NodeJS and system metrics
WARNING: this endpoint is public right now and should be protected
Most of the time, sending a disconnect event to one of the players is enough (the player will close the connection
which will be shut for the other player).
However! In the rare case where the WebRTC connection is not yet established, if we close the connection on one of the player,
the other player will try connecting until a timeout happens (during this time, the circle with the name is displayed for nothing).
So now, we send disconnection event to every body (not only the people in the group, but also to the person leaving the group)
When a user connects or disconnects on the server, we log this (along the current server load).
This is only temporary, in order to assess the number of users a server can safely handle before crashing.
Now, when a user moves, only his/her position is sent back to the other users. The position of all users is not sent each time.
The messages sent to the browser are now:
- the list of all users as a return to the join_room event (you can send responses to events in socket.io)
- a "join_room" event sent when a new user joins the room
- a "user_moved" event when a user moved
- a "user_left" event when a user left the room
The GameScene tracks all these events and reacts accordingly.
Also, I made a number of refactoring in the classes and removed the GameSceneInterface that was useless (it was implemented by the LogincScene for no reason at all)
searchClientById was scanning through all open sockets to find the right one (which is inefficient if we have many).
Instead, I created a new Map that directly maps ids to sockets.
Furthermore, this solves a long-standing issue (when a socket is disconnected, we cannot find it anymore in the sockets list but it is still available in the disconnect callback from the map)
As a result, we should not have any remaining circles any more.
Socket.io can stringify JSON messages itself, so there is no need to pass a string to "emit". You can pass a serializable object!
This commit removes all the useless toJson() methods, JSON.serialize and JSON.parse!
Woot!
Previously, userid was generated by the "/login" route and passed along.
This commit completely removes the uuid "userid" (and disables the LoginController too and any Jwt check).
"userid" is replaced by the "socket id" of the connection.
So a user is now identified using a socket id, which is unique for a given connection.
So far, someone joining a map would not see the circles of groups already formed until someone moves in the group (because the "circle_moved_or_updated" event was not fired when someone arrives)
This commit fixes this behaviour. Someone entering a room will receive an event for each and every group currently formed.
The "frame" variable actually contains a string pointing to the character selected.
It has nothing to do with a frame which is usually a particular image in an animation.
I'm renaming the variable accross the application to avoid confusion.
This PR adds the display of a circle around groups. This is useful to view where you need to go to speak to someone but also to debug.
Note: implementation is suboptimal, relying on a "graphics" object that is known to be slow. In the future, we need to use a circle as a sprite instead.