From 10cd84a653966eb9da48b2af36b209de34aeadb8 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Wed, 15 Nov 2023 12:20:05 +0100 Subject: [PATCH] Add CallNotifyEvent to support matrixRTC ringing (#3878) * Add CallNotifyEvent to support matrix rtc ringing Signed-off-by: Timo K * test SessionId Signed-off-by: Timo K * docs + sessionId->callId Signed-off-by: Timo K --------- Signed-off-by: Timo K --- spec/unit/matrixrtc/MatrixRTCSession.spec.ts | 1 + src/@types/event.ts | 3 +++ src/matrixrtc/MatrixRTCSession.ts | 15 +++++++++++++++ src/matrixrtc/types.ts | 11 ++++++++++- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/spec/unit/matrixrtc/MatrixRTCSession.spec.ts b/spec/unit/matrixrtc/MatrixRTCSession.spec.ts index 545c3923b..6156ad15e 100644 --- a/spec/unit/matrixrtc/MatrixRTCSession.spec.ts +++ b/spec/unit/matrixrtc/MatrixRTCSession.spec.ts @@ -60,6 +60,7 @@ describe("MatrixRTCSession", () => { expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA"); expect(sess?.memberships[0].membershipID).toEqual("bloop"); expect(sess?.memberships[0].isExpired()).toEqual(false); + expect(sess?.callId).toEqual(""); }); it("ignores expired memberships events", () => { diff --git a/src/@types/event.ts b/src/@types/event.ts index 2111e3988..caa87f9f8 100644 --- a/src/@types/event.ts +++ b/src/@types/event.ts @@ -94,6 +94,9 @@ export enum EventType { // Group call events GroupCallPrefix = "org.matrix.msc3401.call", GroupCallMemberPrefix = "org.matrix.msc3401.call.member", + + // MatrixRTC events + CallNotify = "org.matrix.msc4075.call.notify", } export enum RelationType { diff --git a/src/matrixrtc/MatrixRTCSession.ts b/src/matrixrtc/MatrixRTCSession.ts index bba607043..86f53bc94 100644 --- a/src/matrixrtc/MatrixRTCSession.ts +++ b/src/matrixrtc/MatrixRTCSession.ts @@ -78,6 +78,9 @@ export type MatrixRTCSessionEventHandlerMap = { * This class doesn't deal with media at all, just membership & properties of a session. */ export class MatrixRTCSession extends TypedEventEmitter { + // The session Id of the call, this is the call_id of the call Member event. + private _callId: string | undefined; + // How many ms after we joined the call, that our membership should expire, or undefined // if we're not yet joined private relativeExpiry: number | undefined; @@ -106,6 +109,15 @@ export class MatrixRTCSession extends TypedEventEmitter>(); private lastEncryptionKeyUpdateRequest?: number; + /** + * The callId (sessionId) of the call. + * + * It can be undefined since the callId is only known once the first membership joins. + * The callId is the property that, per definition, groups memberships into one call. + */ + public get callId(): string | undefined { + return this._callId; + } /** * Returns all the call memberships for a room, oldest first */ @@ -178,6 +190,7 @@ export class MatrixRTCSession extends TypedEventEmitter !CallMembership.equal(m, this.memberships[i])); diff --git a/src/matrixrtc/types.ts b/src/matrixrtc/types.ts index 21a55f460..de4c7ac47 100644 --- a/src/matrixrtc/types.ts +++ b/src/matrixrtc/types.ts @@ -13,7 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ - +import { IMentions } from "../matrix"; export interface EncryptionKeyEntry { index: number; key: string; @@ -24,3 +24,12 @@ export interface EncryptionKeysEventContent { device_id: string; call_id: string; } + +export type CallNotifyType = "ring" | "notify"; + +export interface ICallNotifyContent { + "application": string; + "m.mentions": IMentions; + "notify_type": CallNotifyType; + "call_id": string; +}