Friends
Friends are players of phigros.tools who see each other online and what they play, watch each other's plays live and invite each other into rooms. They live on phigros.tools, so a player needs a profile there (phigros.tools). They're a built-in mod (mods/friends/): init.lua talks to the server and follows the plays, screen.lua draws the friends' screen.
That screen goes with the rooms': the tab with two people on the chapter screen opens the rooms, whose top bar reads Rooms and Friends, and tapping one shows it. Tapping the avatar at the top right of the song list opens the friends directly (without a profile the game slides the player's name out, as it always did). The two screens take turns: a room just entered closes the friends, and the friends opened from a room hide it until they're closed.
Add a friend, at the top right, takes a name and number (Name#0042): the bottom of the screen shows the player's own. The other player gets a request, and both are friends once it's accepted. In a room, tapping a player's row asks them the same way (Rooms).
Appear invisible, a checkbox at the bottom right, hides the player: their friends see them offline whatever they do, while they still see their friends.
Allow spectating, next to it, lets friends watch the player's plays, or not.
Under it are the requests to answer, then the friends: those playing first with their chart, those online, those offline, and the requests sent. Tapping a row accepts or declines a request, takes one back, removes a friend, or watches their play. Both checkboxes are settings of the Phigros++ tab too, with "Tell me when a friend comes online or leaves".
On phigros.tools
A browser signed in to the profile has a Friends tab on phigros.tools, next to Devices: the same list, with who is online and what they play, a field to add a friend by name and number, and the requests to accept, decline or take back. Another player's page offers to add them, or says what they already are. The browser signs these requests with its own key, as it does for Devices (POST, PUT and DELETE /api/friendships), under the same limits as the game, and the games of both players hear of each change at once. A browser is not a game: it never shows online, and watching a friend's play is in the game only.
Toasts
A friend coming online or leaving, a request, a request accepted and an invitation to a room each show a toast (toast, see Mod API) with the friend's avatar, name and number. The requests that came while the game was closed are told together at launch ("2 pending friend requests"), and that toast opens the friends' screen. Nothing is told during a song: no toast shows over one, and what friends did meanwhile is dropped. Tapping a request's toast opens the friends' screen, tapping an invitation's joins the room as its phigrospp://room/<id> link does.
Nobody fills someone else's screen. The game tells a player's request once, however often it's made again, a friend coming and going once a minute and their invitations every 30 seconds, and a toast saying what another already says isn't shown twice. The server holds what a player asks of others to a few times a minute (10 requests, 6 invitations, 30 removals and 30 plays followed: the game is told slow past them), and a player's friends hear how they are every 2 seconds at most, so flipping Appear invisible or starting a song over and over reaches them at that pace.
Watching a friend
A play is streamed like a room's: twice a second the game sends the frames recorded since the last time (phigrospp.replay.chunk). It only does when the player isn't invisible, allows spectating, isn't in a room (which streams its plays itself) and has a friend online when the song starts, so a play nobody could watch costs no data. A friend whose play can be watched shows in green, and Watch plays it in game a couple of seconds behind (phigrospp.replay.follow), from its start when it's followed late. Like a play of a room, it needs the chart unlocked in the game that watches. The cross leaves it.
The socket
The game keeps one WebSocket to wss://phigros.tools/api/friends while it runs and has a profile (phigrospp.channel), carrying JSON objects named by t. web/server/friends.ts is the other end and says what each means. It signs in like a room's socket, with phigros.tools friends v1\0 before the nonce. A connection that drops is made again after 5 seconds, then twice as long each time up to a minute, and the server keeps the player online for 30 seconds: their friends see nothing of a short cut. What a play streamed meanwhile goes once it's back. A second device of the same player takes the place of the first, which stays out until its friends' screen is opened.
| From the game | |
|---|---|
status | How the player shows: visible, and spectating (their plays may be watched) |
add | A player to ask or accept: an id, or a Name#0042 |
remove | Ends a friendship with a player id, declines their request or takes one back |
playing | The song (the game's id) and level being played, an empty song for none |
frames | The play's frames since the last ones (data, a replay in base64) |
follow | The friend (player) whose play to hear, from the part on, "" for none |
invite | Asks a friend (player) into the room this player sits in |
| From the server | |
|---|---|
hello, welcome | The nonce to sign, then the player the key is and whether their play is still known |
friends | The whole list at each change: each player, their state (friend, incoming, outgoing), and for a friend who shows whether they're online, what they're playing and whether it can be watched (watch) |
frames | A player id and their data, to those who follow them |
invite | The player inviting, the room's id and its name |
error | unknown, self or full for a friend refused, slow past a limit, elsewhere, no-profile or auth |
Who asked whom is kept in the server's database (friends: a row per request, two players are friends once both asked). Who is online, what they play and their streams live in its memory.