Repository navigation
Conversation
Every join, every leave and every reap of a voice channel's mirror runs
one Lua script as the last command of the MULTI that writes it: the
channel's occupancy version becomes Redis's clock in microseconds (TIME),
forced above the last value stored for the channel, and the MULTI answers
it. The key voice:channel:version:{id} is never deleted with the channel's
state; it expires a week after its last change. A space's deletion clears
its channels' mirrors without a version and sends no event.
voice:user_joined and voice:user_left carry that version as
occupancyVersion. A departure goes out once the leave's write answered, or
without a version OCCUPANCY_VERSION_WAIT_MS after the write was issued; a
join's events wait for theirs the same way. Only occupancy events wait:
state, speaking and screen-share events go out at once and can precede a
departure.
The joiner's list of those already there is built on the owner node after
the join's write answered: it holds at least every change up to the join
and carries the version just below the join's. Each row is read again once
the user rows are fetched, so an occupant who left meanwhile is left out
of it; such a row used to be sent with default flags and no session.
A snapshot (getVoiceStateForServers) reads every channel's occupants and
then every channel's version in its third MULTI, still three round trips,
and replayVoiceState sends each list with the version it was read at.
When the script's reply is the only error of a write's MULTI (the client
rejects exec() after Redis applied the other commands), the join, the
leave or the reap stands and its events go out without a version, with
one warning; any other failure is handled as before. The dead-node
reaper's tick and the boot cleanup then go on to the next channel. A
leave or a reap on a Redis over its memory limit is that case: its
deletes go through and the script's write is refused.
A join whose session ended during one of the reads that follow its write
(the occupants' user info, the annotation hydration) is sent nothing more
from that read on: not the occupants' list, not the scene, not its
transports, and it is not announced.
The field is optional on the wire: a client that does not know it ignores
it, and an event or a list without it applies as before.
Refs #195
…event The voice store judges every occupancy list and event by the server's occupancyVersion (stores/voiceOccupancy.ts). Per channel it keeps, outside anything that renders, the version of the last snapshot applied and, per user, the version of the latest event applied since. An event at or below what the list reflects for that user leaves the list as it is. A snapshot older than the last one applied changes no row. A newer snapshot replaces the list except for the users whose latest event is newer than it, who stay as the list shows them: a join or a leave that lands while a replay is on its way survives the snapshot. The sounds and the answer of removeUserFromChannel follow the events as before, and so do the departures the secure-voice keying is handed, whatever their version. What the keying is handed as present follows the list: - an arrival the list refused by its version is not handed over: it is no newer than what the list already reflects for that user, and the keying learns their current session from that later event or from the list of its own join; - for the names a list carries, the keying is handed the rows the store shows once the list is merged: nothing for a list refused as older than the one shown, nothing for a name whose newer event is a departure, and the current session of a name whose newer event is an arrival (a repeat the keying ignores when that arrival was handed to it); - an arrival or a list without a version is handed over as before. A departure already reflected leaves the screen-share reference, which follows the row, as it is. A list or an event without a version applies as before and leaves the bookkeeping alone, and the active channel's connect snapshot stays ignored. The bookkeeping is forgotten where the lists are cleared: the reconnect's synchronous clear, a deleted space's channels and the logout. The three handlers MainLayout registers live in services/voiceOccupancySocketHandlers.ts. Architecture.md describes the version and the merge. Closes #195
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
A client that connects or reconnects receives each visible voice channel's occupants as a snapshot (
voice:channel_users,source: 'connect'). The server reads it from Redis and sends it after a database read, and the socket is already in its channel rooms by then: avoice:user_joinedorvoice:user_leftsent in that window reached the client first and was then overwritten by the older snapshot. The sidebar showed someone who had left, or missed someone who had joined, until the next event about that person or the next reconnect. The same held for the replay after a space join and for the list a joiner receives.Two more things of the same family:
What the code does now
Server
TIME), forced above the value stored for the channel. The keyvoice:channel:version:{channelId}is not deleted with the channel's state and expires a week after the channel's last change, so a channel that empties and fills again, a node restart and an owner takeover never bring the version back down.voice:user_joined,voice:user_leftandvoice:channel_userscarry it as the optionaloccupancyVersion. A snapshot reads every channel's occupants and then every channel's version in one MULTI (still three Redis round trips whatever the number of spaces) and is sent with the version it was read at. The list a joiner receives is built on the channel's owner node after the join's write answered and carries the version just below the join's; an occupant who left while it was built is left out of it.Desktop
stores/voiceOccupancy.ts, at most 500 users a channel).removeUserFromChannelfollow the events as before, and so do the departures the secure-voice key exchange is handed. What it is handed as present follows the list:MainLayoutregistered inline live inservices/voiceOccupancySocketHandlers.ts.Compatibility. The field is optional in both directions: a 2.1.x client ignores it, and this client with a server that does not send it behaves as before.
Key files
apps/server/src/utils/voiceMirror.ts,apps/server/src/websocket/voiceHandler.tspackages/shared/src/types.ts,packages/shared/src/constants.tsapps/desktop/src/stores/voiceOccupancy.ts,apps/desktop/src/stores/voiceStore.ts(setChannelUsers,addUserToChannel,removeUserFromChannel),apps/desktop/src/services/voiceOccupancySocketHandlers.tsscripts/test-multi-node.ts,Architecture.md(the voice occupancy paragraph)Migrations
None. Redis gains one small key per voice channel that has had an occupant, which expires a week after the channel's last change.
Tests
scripts/test-multi-node.ts: versions grow across two nodes, across an emptied channel and across an owner takeover.To check by hand