Skip to content
9 changes: 5 additions & 4 deletions spec/unit/matrixrtc/MatrixRTCSession.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
limitations under the License.
*/


import { type Mock } from "vitest";

import { type EventTimeline, EventType, KnownMembership, MatrixClient, type Room } from "../../../src";
Expand Down Expand Up @@ -687,15 +688,15 @@
event_id: ownMembershipId,
rel_type: "m.reference",
},
"lifetime": 30000,
"lifetime": 90000,
"sender_ts": expect.any(Number),
});

await didSendNotification;
// And ensure we emitted the DidSendCallNotification event with both payloads
expect(didSendEventFn).toHaveBeenCalledWith({
"event_id": "new-evt",
"lifetime": 30000,
"lifetime": 90000,
"m.mentions": { room: true, user_ids: [] },
"m.relates_to": {
event_id: expect.any(String),
Expand Down Expand Up @@ -744,15 +745,15 @@
event_id: ownMembershipEventId,
rel_type: "m.reference",
},
"lifetime": 30000,
"lifetime": 90000,
"sender_ts": expect.any(Number),
});

await didSendNotification;
// And ensure we emitted the DidSendCallNotification event with both payloads
expect(didSendEventFn).toHaveBeenCalledWith({
"event_id": "new-evt",
"lifetime": 30000,
"lifetime": 90000,
"m.mentions": { room: true, user_ids: [] },
"m.relates_to": {
event_id: expect.any(String),
Expand Down Expand Up @@ -889,7 +890,7 @@
it("returns the correct probablyLeft status", () => {
const mockRoom = makeMockRoom([sessionMembershipTemplate]);
sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession);
expect(sess!.probablyLeft).toBe(undefined);

Check warning on line 893 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer "expect(sess!.probablyLeft).toBeUndefined()" over this generic assertion; dedicated matchers read better and report clearer failures.

See more on https://sonarcloud.io/project/issues?id=matrix-js-sdk&issues=AZ-7SX78nB25CsgHUaWZ&open=AZ-7SX78nB25CsgHUaWZ&pullRequest=5398

sess!.joinRTCSession(owmMemberIdentity, [mockFocus], mockFocus, { manageMediaKeys: true });
expect(sess!.probablyLeft).toBe(false);
Expand All @@ -905,7 +906,7 @@
it("returns membershipStatus once joinRTCSession got called", () => {
const mockRoom = makeMockRoom([rtcMembershipTemplate]);
sess = MatrixRTCSession.sessionForSlot(client, mockRoom, callSession);
expect(sess!.membershipStatus).toBe(undefined);

Check warning on line 909 in spec/unit/matrixrtc/MatrixRTCSession.spec.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Prefer "expect(sess!.membershipStatus).toBeUndefined()" over this generic assertion; dedicated matchers read better and report clearer failures.

See more on https://sonarcloud.io/project/issues?id=matrix-js-sdk&issues=AZ-7SX78nB25CsgHUaWa&open=AZ-7SX78nB25CsgHUaWa&pullRequest=5398

sess!.joinRTCSession(owmMemberIdentity, [mockFocus], mockFocus, { manageMediaKeys: true });
expect(sess!.membershipStatus).toBe(Status.Connecting);
Expand Down
9 changes: 8 additions & 1 deletion src/matrixrtc/MatrixRTCSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ export interface SessionConfig {
* Determines the kind of call this will be.
*/
callIntent?: RTCCallIntent;

/**
* How long (in milliseconds) the callee's client should keep ringing/waiting for an
* answer before the sender gives up and the call notification is considered timed out.
*/
notificationLifetimeMs?: number;
}

// The names follow these principles:
Expand Down Expand Up @@ -675,6 +681,7 @@ export class MatrixRTCSession extends TypedEventEmitter<
notificationType: RTCNotificationType,
callIntent?: RTCCallIntent,
): void {
const lifetime = this.joinConfig?.notificationLifetimeMs ?? 60_000;
const sendNotificationEvent = async (): Promise<{
response: ISendEventResponse;
content: IRTCNotificationContent;
Expand All @@ -687,7 +694,7 @@ export class MatrixRTCSession extends TypedEventEmitter<
rel_type: RelationType.Reference,
},
"sender_ts": Date.now(),
"lifetime": 30_000, // 30 seconds
"lifetime": lifetime,
};
if (callIntent) {
content["m.call.intent"] = callIntent;
Expand Down