1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-12-01 04:43:29 +03:00

Give MatrixCall the capability to emit LengthChanged events

Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
Šimon Brandner
2021-08-27 15:06:55 +02:00
parent f83fcb1a18
commit f107d63fab

View File

@@ -120,6 +120,8 @@ export enum CallEvent {
FeedsChanged = 'feeds_changed', FeedsChanged = 'feeds_changed',
AssertedIdentityChanged = 'asserted_identity_changed', AssertedIdentityChanged = 'asserted_identity_changed',
LengthChanged = 'length_changed'
} }
export enum CallErrorCode { export enum CallErrorCode {
@@ -313,6 +315,9 @@ export class MatrixCall extends EventEmitter {
private remoteSDPStreamMetadata: SDPStreamMetadata; private remoteSDPStreamMetadata: SDPStreamMetadata;
private callLengthInterval: number;
private callLength = 0;
constructor(opts: CallOpts) { constructor(opts: CallOpts) {
super(); super();
this.roomId = opts.roomId; this.roomId = opts.roomId;
@@ -1485,6 +1490,10 @@ export class MatrixCall extends EventEmitter {
// chrome doesn't implement any of the 'onstarted' events yet // chrome doesn't implement any of the 'onstarted' events yet
if (this.peerConn.iceConnectionState == 'connected') { if (this.peerConn.iceConnectionState == 'connected') {
this.setState(CallState.Connected); this.setState(CallState.Connected);
this.callLengthInterval = setInterval(() => {
this.callLength++;
this.emit(CallEvent.LengthChanged, this.callLength);
}, 1000);
} else if (this.peerConn.iceConnectionState == 'failed') { } else if (this.peerConn.iceConnectionState == 'failed') {
this.hangup(CallErrorCode.IceFailed, false); this.hangup(CallErrorCode.IceFailed, false);
} }
@@ -1735,6 +1744,10 @@ export class MatrixCall extends EventEmitter {
clearTimeout(this.inviteTimeout); clearTimeout(this.inviteTimeout);
this.inviteTimeout = null; this.inviteTimeout = null;
} }
if (this.callLengthInterval) {
clearInterval(this.callLengthInterval);
this.callLengthInterval = null;
}
// Order is important here: first we stopAllMedia() and only then we can deleteAllFeeds() // Order is important here: first we stopAllMedia() and only then we can deleteAllFeeds()
// We don't stop media if the call was replaced as we want to re-use streams in the successor // We don't stop media if the call was replaced as we want to re-use streams in the successor