diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 2d29a6c8d..35a7cb970 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -127,6 +127,8 @@ export enum CallEvent { FeedsChanged = 'feeds_changed', AssertedIdentityChanged = 'asserted_identity_changed', + + LengthChanged = 'length_changed' } export enum CallErrorCode { @@ -323,6 +325,9 @@ export class MatrixCall extends EventEmitter { private remoteSDPStreamMetadata: SDPStreamMetadata; + private callLengthInterval: number; + private callLength = 0; + constructor(opts: CallOpts) { super(); this.roomId = opts.roomId; @@ -1479,6 +1484,10 @@ export class MatrixCall extends EventEmitter { // chrome doesn't implement any of the 'onstarted' events yet if (this.peerConn.iceConnectionState == 'connected') { this.setState(CallState.Connected); + this.callLengthInterval = setInterval(() => { + this.callLength++; + this.emit(CallEvent.LengthChanged, this.callLength); + }, 1000); } else if (this.peerConn.iceConnectionState == 'failed') { this.hangup(CallErrorCode.IceFailed, false); } @@ -1729,6 +1738,10 @@ export class MatrixCall extends EventEmitter { clearTimeout(this.inviteTimeout); 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() // We don't stop media if the call was replaced as we want to re-use streams in the successor