-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clear peers on disconnect #168
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,13 +370,13 @@ export class HiFiMixerSession { | |
}); | ||
|
||
let mixerPeerKeys = Object.keys(this._mixerPeerKeyToStateCacheDict); | ||
for (const mixerPeerKey of mixerPeerKeys) { | ||
if (this._mixerPeerKeyToStateCacheDict[mixerPeerKey].hashedVisitID === hashedVisitID) { | ||
if (this._mixerPeerKeyToStateCacheDict[mixerPeerKey].providedUserID) { | ||
deletedUserData.providedUserID = this._mixerPeerKeyToStateCacheDict[mixerPeerKey].providedUserID; | ||
for (const key of mixerPeerKeys) { | ||
let peerData = this._mixerPeerKeyToStateCacheDict[key]; | ||
if (peerData.hashedVisitID === hashedVisitID) { | ||
if (peerData.providedUserID) { | ||
deletedUserData.providedUserID = peerData.providedUserID; | ||
} | ||
// TODO: remove the entry from the peer state cache -- is this OK? | ||
//delete this._mixerPeerKeyToStateCacheDict[mixerPeerKey]; | ||
delete this._mixerPeerKeyToStateCacheDict[key]; | ||
break; | ||
} | ||
} | ||
|
@@ -699,6 +699,7 @@ export class HiFiMixerSession { | |
await close(this._raviSignalingConnection, "Signaling Connection", RaviSignalingStates.CLOSED); | ||
await close(this._raviSession, "Session", RaviSessionStates.CLOSED); | ||
|
||
this._clearPeerData(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the real fix for HIFI-847: clear the peer cache on disconnect. |
||
this._resetMixerInfo(); | ||
|
||
await this._setMutedByAdmin(false, MuteReason.INTERNAL); | ||
|
@@ -1231,6 +1232,25 @@ export class HiFiMixerSession { | |
this.mixerInfo = { | ||
"connected": false, | ||
}; | ||
} | ||
|
||
/** | ||
* Clears all cached peer data and submits all hashedVisitIDs as "deleted" | ||
*/ | ||
private _clearPeerData(): void { | ||
if (this.onUsersDisconnected && this._mixerPeerKeyToStateCacheDict.length > 0) { | ||
let allDeletedUserData: Array<ReceivedHiFiAudioAPIData> = []; | ||
for (const peerData of this._mixerPeerKeyToStateCacheDict) { | ||
let deletedUserData = new ReceivedHiFiAudioAPIData({ | ||
hashedVisitID: peerData.hashedVisitID, | ||
}); | ||
if (peerData.providedUserID) { | ||
deletedUserData.providedUserID = peerData.providedUserID; | ||
} | ||
allDeletedUserData.push(deletedUserData); | ||
} | ||
this.onUsersDisconnected(allDeletedUserData); | ||
} | ||
this._mixerPeerKeyToStateCacheDict = {}; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: we aren't just clearing the peer cache here. If onUserDisconnect callback exists we also assemble allDeletedUserData and feed it to onUserDisconnect. This tells the Application to remove any stale peer data it happens to be using. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While looking over the code I noticed this for loop was performing double map lookups in _mixerPeerKeyToStateCacheDict in the common case and triple lookups in the uncommon. This offends my sensibilities for high performance code and so I was compelled to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, also notice that I did uncomment the code for the old TODO. Yes, it is a good idea to actually purge old peer data from the cache when it gets deleted.