Skip to content

Commit 46d38a9

Browse files
committed
replace joining concept with ownMembership
1 parent 370689f commit 46d38a9

File tree

3 files changed

+24
-18
lines changed

3 files changed

+24
-18
lines changed

src/matrixrtc/IMembershipManager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ export interface IMembershipManager {
5555
* Get the actual connection status of the manager.
5656
*/
5757
get status(): Status;
58+
5859
/**
59-
* The current status while the manager is activated
60+
* The Current own state event if the manger is connected.
61+
* `undefined` if not connected.
6062
*/
63+
get ownMembership(): CallMembership | undefined;
64+
6165
/**
6266
* Start sending all necessary events to make this user participate in the RTC session.
6367
* @param fociPreferred the list of preferred foci to use in the joined RTC membership event.

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,6 @@ export class MatrixRTCSession extends TypedEventEmitter<
194194
private joinConfig?: SessionConfig;
195195
private logger: Logger;
196196

197-
/**
198-
* Whether we're trying to join the session but still waiting for room state
199-
* to reflect our own membership.
200-
*/
201-
private joining = false;
202-
203197
/**
204198
* This timeout is responsible to track any expiration. We need to know when we have to start
205199
* to ignore other call members. There is no callback for this. This timeout will always be configured to
@@ -465,9 +459,6 @@ export class MatrixRTCSession extends TypedEventEmitter<
465459
}
466460

467461
this.joinConfig = joinConfig;
468-
const userId = this.client.getUserId()!;
469-
const deviceId = this.client.getDeviceId()!;
470-
this.joining = !this.memberships.some((m) => isMyMembership(m, userId, deviceId));
471462

472463
// Join!
473464
this.membershipManager!.join(fociPreferred, fociActive, (e) => {
@@ -498,7 +489,6 @@ export class MatrixRTCSession extends TypedEventEmitter<
498489

499490
this.logger.info(`Leaving call session in room ${this.roomSubset.roomId}`);
500491

501-
this.joining = false;
502492
this.encryptionManager!.leave();
503493
const leavePromise = this.membershipManager!.leave(timeout);
504494

@@ -625,14 +615,15 @@ export class MatrixRTCSession extends TypedEventEmitter<
625615
});
626616

627617
void this.membershipManager?.onRTCSessionMemberUpdate(this.memberships);
628-
629-
const userId = this.client.getUserId()!;
630-
const deviceId = this.client.getDeviceId()!;
631-
if (this.joining && this.memberships.some((m) => isMyMembership(m, userId, deviceId))) {
632-
this.joining = false;
618+
const ownMembership = this.membershipManager?.ownMembership;
619+
if (ownMembership && oldMemberships.length === 0) {
633620
// If we're the first member in the call, we're responsible for
634621
// sending the notification event
635-
if (oldMemberships.length === 0) this.sendCallNotify();
622+
if (ownMembership.eventId) {
623+
this.sendCallNotify(ownMembership.eventId);
624+
} else {
625+
this.logger.warn("Own membership eventId is undefined, cannot send call notification");
626+
}
636627
}
637628
}
638629
// This also needs to be done if `changed` = false

src/matrixrtc/MembershipManager.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,13 @@ export class MembershipManager
221221
public async onRTCSessionMemberUpdate(memberships: CallMembership[]): Promise<void> {
222222
const userId = this.client.getUserId();
223223
const deviceId = this.client.getDeviceId();
224-
if (userId && deviceId && this.isJoined() && !memberships.some((m) => isMyMembership(m, userId, deviceId))) {
224+
if (!userId || !deviceId) {
225+
this.logger.error("MembershipManager.onRTCSessionMemberUpdate called without user or device id");
226+
return Promise.resolve();
227+
}
228+
this._ownMembership = memberships.find((m) => isMyMembership(m, userId, deviceId));
229+
230+
if (this.isActivated() && !this._ownMembership) {
225231
// If one of these actions are scheduled or are getting inserted in the next iteration, we should already
226232
// take care of our missing membership.
227233
const sendingMembershipActions = [
@@ -310,6 +316,11 @@ export class MembershipManager
310316
}, this.logger);
311317
}
312318

319+
private _ownMembership?: CallMembership;
320+
public get ownMembership(): CallMembership | undefined {
321+
return this._ownMembership;
322+
}
323+
313324
// scheduler
314325
private oldStatus?: Status;
315326
private scheduler: ActionScheduler;

0 commit comments

Comments
 (0)