Skip to content

Commit 3a33c65

Browse files
authored
Expose the StatusChanged event through the RTCSession (#4974)
* Expose the StatusChanged event through the RTCSession Signed-off-by: Timo K <[email protected]> * add membershipManagerStatus public get field Signed-off-by: Timo K <[email protected]> * add probably left as a getter Signed-off-by: Timo K <[email protected]> * add tests for coverage Signed-off-by: Timo K <[email protected]> --------- Signed-off-by: Timo K <[email protected]>
1 parent 81e42b9 commit 3a33c65

File tree

4 files changed

+52
-7
lines changed

4 files changed

+52
-7
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ limitations under the License.
1717
import { encodeBase64, EventType, MatrixClient, type MatrixError, type MatrixEvent, type Room } from "../../../src";
1818
import { KnownMembership } from "../../../src/@types/membership";
1919
import { MatrixRTCSession, MatrixRTCSessionEvent } from "../../../src/matrixrtc/MatrixRTCSession";
20-
import { type EncryptionKeysEventContent } from "../../../src/matrixrtc/types";
20+
import { Status, type EncryptionKeysEventContent } from "../../../src/matrixrtc/types";
2121
import { secureRandomString } from "../../../src/randomstring";
2222
import { makeMockEvent, makeMockRoom, membershipTemplate, makeKey, type MembershipData, mockRoomState } from "./mocks";
2323
import { RTCEncryptionManager } from "../../../src/matrixrtc/RTCEncryptionManager.ts";
@@ -1226,5 +1226,31 @@ describe("MatrixRTCSession", () => {
12261226
}
12271227
});
12281228
});
1229+
describe("read status", () => {
1230+
it("returns the correct probablyLeft status", () => {
1231+
const mockRoom = makeMockRoom([membershipTemplate]);
1232+
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession);
1233+
expect(sess!.probablyLeft).toBe(undefined);
1234+
1235+
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
1236+
expect(sess!.probablyLeft).toBe(false);
1237+
1238+
// Simulate the membership manager believing the user has left
1239+
const accessPrivateFieldsSession = sess as unknown as {
1240+
membershipManager: { state: { probablyLeft: boolean } };
1241+
};
1242+
accessPrivateFieldsSession.membershipManager.state.probablyLeft = true;
1243+
expect(sess!.probablyLeft).toBe(true);
1244+
});
1245+
1246+
it("returns membershipStatus once joinRoomSession got called", () => {
1247+
const mockRoom = makeMockRoom([membershipTemplate]);
1248+
sess = MatrixRTCSession.sessionForRoom(client, mockRoom, callSession);
1249+
expect(sess!.membershipStatus).toBe(undefined);
1250+
1251+
sess!.joinRoomSession([mockFocus], mockFocus, { manageMediaKeys: true });
1252+
expect(sess!.membershipStatus).toBe(Status.Connecting);
1253+
});
1254+
});
12291255
});
12301256
});

src/matrixrtc/IMembershipManager.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export interface IMembershipManager
7171
*/
7272
get ownMembership(): CallMembership | undefined;
7373

74+
/**
75+
* If the membership manager has reason to believe that the hs sent a leave event
76+
* and as a consequence the current user is perceived as left for other session participants.
77+
*/
78+
get probablyLeft(): boolean;
79+
7480
/**
7581
* Start sending all necessary events to make this user participate in the RTC session.
7682
* @param fociPreferred the list of preferred foci to use in the joined RTC membership event.

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import { KnownMembership } from "../@types/membership.ts";
2727
import { MembershipManager } from "./MembershipManager.ts";
2828
import { EncryptionManager, type IEncryptionManager } from "./EncryptionManager.ts";
2929
import { deepCompare, logDurationSync } from "../utils.ts";
30-
import { type Statistics, type RTCNotificationType } from "./types.ts";
30+
import { type Statistics, type RTCNotificationType, type Status } from "./types.ts";
3131
import { RoomKeyTransport } from "./RoomKeyTransport.ts";
3232
import {
3333
MembershipManagerEvent,
@@ -224,10 +224,8 @@ export type JoinSessionConfig = SessionConfig & MembershipConfig & EncryptionCon
224224
* This class doesn't deal with media at all, just membership & properties of a session.
225225
*/
226226
export class MatrixRTCSession extends TypedEventEmitter<
227-
MatrixRTCSessionEvent | RoomAndToDeviceEvents | MembershipManagerEvent.ProbablyLeft,
228-
MatrixRTCSessionEventHandlerMap &
229-
RoomAndToDeviceEventsHandlerMap &
230-
Pick<MembershipManagerEventHandlerMap, MembershipManagerEvent.ProbablyLeft>
227+
MatrixRTCSessionEvent | RoomAndToDeviceEvents | MembershipManagerEvent,
228+
MatrixRTCSessionEventHandlerMap & RoomAndToDeviceEventsHandlerMap & MembershipManagerEventHandlerMap
231229
> {
232230
private membershipManager?: IMembershipManager;
233231
private encryptionManager?: IEncryptionManager;
@@ -257,6 +255,14 @@ export class MatrixRTCSession extends TypedEventEmitter<
257255
},
258256
};
259257

258+
public get membershipStatus(): Status | undefined {
259+
return this.membershipManager?.status;
260+
}
261+
262+
public get probablyLeft(): boolean | undefined {
263+
return this.membershipManager?.probablyLeft;
264+
}
265+
260266
/**
261267
* The callId (sessionId) of the call.
262268
*
@@ -496,7 +502,10 @@ export class MatrixRTCSession extends TypedEventEmitter<
496502
this.logger,
497503
);
498504

499-
this.reEmitter.reEmit(this.membershipManager!, [MembershipManagerEvent.ProbablyLeft]);
505+
this.reEmitter.reEmit(this.membershipManager!, [
506+
MembershipManagerEvent.ProbablyLeft,
507+
MembershipManagerEvent.StatusChanged,
508+
]);
500509
// Create Encryption manager
501510
let transport;
502511
if (joinConfig?.useExperimentalToDeviceTransport) {

src/matrixrtc/MembershipManager.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -984,6 +984,10 @@ export class MembershipManager
984984
this.logger.error("MembershipManager has an unknown state. Actions: ", actions);
985985
return Status.Unknown;
986986
}
987+
988+
public get probablyLeft(): boolean {
989+
return this.state.probablyLeft;
990+
}
987991
}
988992

989993
function createInsertActionUpdate(type: MembershipActionType, offset?: number): ActionUpdate {

0 commit comments

Comments
 (0)