A MatrixRTCSession manages the membership & properties of a MatrixRTC session. This class doesn't deal with media at all, just membership & properties of a session.

Hierarchy (view full)

Properties

memberships: CallMembership[]
room: Room
statistics: {
    counters: {
        roomEventEncryptionKeysReceived: number;
        roomEventEncryptionKeysSent: number;
        toDeviceEncryptionKeysReceived: number;
        toDeviceEncryptionKeysSent: number;
    };
    totals: {
        roomEventEncryptionKeysReceivedTotalAge: number;
        toDeviceEncryptionKeysReceivedTotalAge: number;
    };
} = ...

The statistics for this session.

Type declaration

  • counters: {
        roomEventEncryptionKeysReceived: number;
        roomEventEncryptionKeysSent: number;
        toDeviceEncryptionKeysReceived: number;
        toDeviceEncryptionKeysSent: number;
    }
    • roomEventEncryptionKeysReceived: number

      The number of times we have received a room event containing encryption keys.

    • roomEventEncryptionKeysSent: number

      The number of times we have sent a room event containing encryption keys.

    • toDeviceEncryptionKeysReceived: number

      The number of times we have received a to-device event containing encryption keys.

    • toDeviceEncryptionKeysSent: number

      The number of times we have sent a to-device event containing encryption keys.

  • totals: {
        roomEventEncryptionKeysReceivedTotalAge: number;
        toDeviceEncryptionKeysReceivedTotalAge: number;
    }
    • roomEventEncryptionKeysReceivedTotalAge: number

      The total age (in milliseconds) of all room events containing encryption keys that we have received. We track the total age so that we can later calculate the average age of all keys received.

    • toDeviceEncryptionKeysReceivedTotalAge: number

      The total age (in milliseconds) of all to-device events containing encryption keys that we have received. We track the total age so that we can later calculate the average age of all keys received.

Accessors

  • get callId(): undefined | string
  • 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.

    Returns undefined | string

Methods

  • Synchronously calls each of the listeners registered for the event named event, in the order they were registered, passing the supplied arguments to each.

    Type Parameters

    Parameters

    Returns boolean

    true if the event had listeners, false otherwise.

  • Synchronously calls each of the listeners registered for the event namedeventName, in the order they were registered, passing the supplied arguments to each.

    Returns true if the event had listeners, false otherwise.

    import EventEmitter from 'node:events';
    const myEmitter = new EventEmitter();

    // First listener
    myEmitter.on('event', function firstListener() {
    console.log('Helloooo! first listener');
    });
    // Second listener
    myEmitter.on('event', function secondListener(arg1, arg2) {
    console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
    });
    // Third listener
    myEmitter.on('event', function thirdListener(...args) {
    const parameters = args.join(', ');
    console.log(`event with parameters ${parameters} in third listener`);
    });

    console.log(myEmitter.listeners('event'));

    myEmitter.emit('event', 1, 2, 3, 4, 5);

    // Prints:
    // [
    // [Function: firstListener],
    // [Function: secondListener],
    // [Function: thirdListener]
    // ]
    // Helloooo! first listener
    // event with parameters 1, 2 in second listener
    // event with parameters 1, 2, 3, 4, 5 in third listener

    Type Parameters

    Parameters

    Returns boolean

    v0.1.26

  • A map of keys used to encrypt and decrypt (we are using a symmetric cipher) given participant's media. This also includes our own key

    Returns IterableIterator<[string, Uint8Array[]], any, any>

    This will be made private in a future release.

  • Get the known encryption keys for a given participant device.

    Parameters

    • userId: string

      the user ID of the participant

    • deviceId: string

      the device ID of the participant

    Returns undefined | Uint8Array[]

    The encryption keys for the given participant, or undefined if they are not known.

    This will be made private in a future release.

  • Announces this user and device as joined to the MatrixRTC session, and continues to update the membership event to keep it valid until leaveRoomSession() is called This will not subscribe to updates: remember to call subscribe() separately if desired. This method will return immediately and the session will be joined in the background.

    Parameters

    • fociPreferred: Focus[]

      The list of preferred foci this member proposes to use/knows/has access to. For the livekit case this is a list of foci generated from the homeserver well-known, the current rtc session, or optionally other room members homeserver well known.

    • OptionalfociActive: Focus

      The object representing the active focus. (This depends on the focus type.)

    • OptionaljoinConfig: JoinSessionConfig

      Additional configuration for the joined session.

    Returns void

  • Announces this user and device as having left the MatrixRTC session and stops scheduled updates. This will not unsubscribe from updates: remember to call unsubscribe() separately if desired. The membership update required to leave the session will retry if it fails. Without network connection the promise will never resolve. A timeout can be provided so that there is a guarantee for the promise to resolve.

    Parameters

    • timeout: undefined | number = undefined

    Returns Promise<boolean>

    Whether the membership update was attempted and did not time out.

  • Adds the listener function to the end of the listeners array for the event named event.

    No checks are made to see if the listener has already been added. Multiple calls passing the same combination of event and listener will result in the listener being added, and called, multiple times.

    By default, event listeners are invoked in the order they are added. The prependListener method can be used as an alternative to add the event listener to the beginning of the listeners array.

    Type Parameters

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.

  • Process m.call.encryption_keys events to track the encryption keys for call participants. This should be called each time the relevant event is received from a room timeline. If the event is malformed then it will be logged and ignored.

    Parameters

    Returns void

  • Examines the latest call memberships and handles any encryption key sending or rotation that is needed.

    This function should be called when the room members or call memberships might have changed.

    Returns void

  • Re-emit an EncryptionKeyChanged event for each tracked encryption key. This can be used to export the keys.

    Returns void

  • Removes all listeners, or those of the specified event.

    It is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).

    Parameters

    Returns this

    a reference to the EventEmitter, so that calls can be chained.