1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-07 23:02:56 +03:00

Add CallNotifyEvent to support matrixRTC ringing (#3878)

* Add CallNotifyEvent to support matrix rtc ringing

Signed-off-by: Timo K <toger5@hotmail.de>

* test SessionId

Signed-off-by: Timo K <toger5@hotmail.de>

* docs + sessionId->callId

Signed-off-by: Timo K <toger5@hotmail.de>

---------

Signed-off-by: Timo K <toger5@hotmail.de>
This commit is contained in:
Timo
2023-11-15 12:20:05 +01:00
committed by GitHub
parent c36166d156
commit 10cd84a653
4 changed files with 29 additions and 1 deletions

View File

@@ -60,6 +60,7 @@ describe("MatrixRTCSession", () => {
expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA"); expect(sess?.memberships[0].deviceId).toEqual("AAAAAAA");
expect(sess?.memberships[0].membershipID).toEqual("bloop"); expect(sess?.memberships[0].membershipID).toEqual("bloop");
expect(sess?.memberships[0].isExpired()).toEqual(false); expect(sess?.memberships[0].isExpired()).toEqual(false);
expect(sess?.callId).toEqual("");
}); });
it("ignores expired memberships events", () => { it("ignores expired memberships events", () => {

View File

@@ -94,6 +94,9 @@ export enum EventType {
// Group call events // Group call events
GroupCallPrefix = "org.matrix.msc3401.call", GroupCallPrefix = "org.matrix.msc3401.call",
GroupCallMemberPrefix = "org.matrix.msc3401.call.member", GroupCallMemberPrefix = "org.matrix.msc3401.call.member",
// MatrixRTC events
CallNotify = "org.matrix.msc4075.call.notify",
} }
export enum RelationType { export enum RelationType {

View File

@@ -78,6 +78,9 @@ export type MatrixRTCSessionEventHandlerMap = {
* This class doesn't deal with media at all, just membership & properties of a session. * This class doesn't deal with media at all, just membership & properties of a session.
*/ */
export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, MatrixRTCSessionEventHandlerMap> { export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, MatrixRTCSessionEventHandlerMap> {
// 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 // How many ms after we joined the call, that our membership should expire, or undefined
// if we're not yet joined // if we're not yet joined
private relativeExpiry: number | undefined; private relativeExpiry: number | undefined;
@@ -106,6 +109,15 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
private encryptionKeys = new Map<string, Array<Uint8Array>>(); private encryptionKeys = new Map<string, Array<Uint8Array>>();
private lastEncryptionKeyUpdateRequest?: number; 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 * Returns all the call memberships for a room, oldest first
*/ */
@@ -178,6 +190,7 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
public memberships: CallMembership[], public memberships: CallMembership[],
) { ) {
super(); super();
this._callId = memberships[0]?.callId;
this.setExpiryTimer(); this.setExpiryTimer();
} }
@@ -551,6 +564,8 @@ export class MatrixRTCSession extends TypedEventEmitter<MatrixRTCSessionEvent, M
const oldMemberships = this.memberships; const oldMemberships = this.memberships;
this.memberships = MatrixRTCSession.callMembershipsForRoom(this.room); this.memberships = MatrixRTCSession.callMembershipsForRoom(this.room);
this._callId = this._callId ?? this.memberships[0]?.callId;
const changed = const changed =
oldMemberships.length != this.memberships.length || oldMemberships.length != this.memberships.length ||
oldMemberships.some((m, i) => !CallMembership.equal(m, this.memberships[i])); oldMemberships.some((m, i) => !CallMembership.equal(m, this.memberships[i]));

View File

@@ -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 See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { IMentions } from "../matrix";
export interface EncryptionKeyEntry { export interface EncryptionKeyEntry {
index: number; index: number;
key: string; key: string;
@@ -24,3 +24,12 @@ export interface EncryptionKeysEventContent {
device_id: string; device_id: string;
call_id: string; call_id: string;
} }
export type CallNotifyType = "ring" | "notify";
export interface ICallNotifyContent {
"application": string;
"m.mentions": IMentions;
"notify_type": CallNotifyType;
"call_id": string;
}