five-on-it / apps/api/src/social
apps/api/src/social
The social layer of the platform (GAME_DESIGN §13, TECHNICAL_SPECS §9.6): friends, their presence, parties, the party's channel and direct messages, mutes, and the feed that brings each player what concerns them.
The friend graph and the mutes live with the accounts' provider, behind a FriendBackend: in memory (and a JSON file) with the dev accounts (social-dev.ts), in Nakama's friends and storage with Nakama (social-nakama.ts). The rest is the SocialHub, in the API's process for either provider:
- Presence: a player's page says every so often where they are (a room, or none); one not heard from for PRESENCE_MS is offline. Friends see each other's.
- Parties of up to MAX_PARTY: a player creates one and leads it, invites friends, who join; a member leaves (the leader's place goes to the next member, the last one out ends it). When the leader opens or joins a room, every other member is sent a URL that joins it with them (the routes do that,
social-routes.ts); the join tokens carry the party, and the game server runs the party's missions together. - Messages: the party's channel and direct messages between friends, at most MESSAGE_BURST lines in
MESSAGE_WINDOW_MS. They are private conversations, so they are not moderated (GAME_DESIGN §10.4: only public rooms' chat is); the provider may keep them (Nakama's chat channels). - The feed: each account's events, numbered, the last
FEED_KEEPkept; a page asks for those after the last it saw and waits a while when there are none (a long poll), so it hears of a message, a friend request, an invitation, the party's room, its lobby changing and its lobby's run opening (lobbies.ts:lobby,run) or the end of one of its creations (creations.ts) within a moment.
The room's own channel is the game server's (apps/server/src/room-social.ts).