You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-25 05:23:13 +03:00
Merge pull request #1873 from SimonBrandner/feature/call-timer/18566
Give `MatrixCall` the capability to emit `LengthChanged` events
This commit is contained in:
@@ -127,6 +127,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 {
|
||||||
@@ -323,6 +325,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;
|
||||||
@@ -1479,6 +1484,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);
|
||||||
}
|
}
|
||||||
@@ -1729,6 +1738,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
|
||||||
|
|||||||
Reference in New Issue
Block a user