Skip to content

Commit f2829f1

Browse files
committed
When state says you've left ongoing call, rejoin
When receiving a state change that says you are no longer a member of a RTC session that you are actually still participating in, send another state event to put yourself back in the session membership. This can happen when an administrator overwrites your call membership event (which is allowed even with MSC3757's restrictions on state), or if your delayed disconnection event (via MSC4140) timed out before your client could send a heartbeat to delay it further.
1 parent 13a967a commit f2829f1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,14 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
774774
if (changed) {
775775
logger.info(`Memberships for call in room ${this.room.roomId} have changed: emitting`);
776776
this.emit(MatrixRTCSessionEvent.MembershipsChanged, oldMemberships, this.memberships);
777+
778+
if (this.isJoined() && !this.memberships.some(this.isMyMembership)) {
779+
logger.warn("Missing own membership: force re-join");
780+
// TODO: Should this be awaited? And is there anything to tell the focus?
781+
this.triggerCallMembershipEventUpdate();
782+
// TODO: Is this needed?
783+
this.emit(MatrixRTCSessionEvent.JoinStateChanged, true);
784+
}
777785
}
778786

779787
if (this.manageMediaKeys && this.isJoined() && this.makeNewKeyTimeout === undefined) {
@@ -944,6 +952,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
944952
}
945953

946954
private triggerCallMembershipEventUpdate = async (): Promise<void> => {
955+
// TODO: Should this await on a shared promise?
947956
if (this.updateCallMembershipRunning) {
948957
this.needCallMembershipUpdate = true;
949958
return;
@@ -1032,7 +1041,6 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
10321041
const stateKey = this.makeMembershipStateKey(localUserId, localDeviceId);
10331042
const prepareDelayedDisconnection = async (): Promise<void> => {
10341043
try {
1035-
// TODO: If delayed event times out, re-join!
10361044
const res = await this.client._unstable_sendDelayedStateEvent(
10371045
this.room.roomId,
10381046
{

0 commit comments

Comments
 (0)