-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 3.7.0 * add `setUserId` * typofix for stats * add `VideoFreezesDetector` * add `layers` property to outbound track stats * add `usermediaerror` event * add `usingTURN` property to peer conections * add `using-turn` event to monitor * add `sendingFractionLost` to monitor * add `receivingFractionLost` to monitor
- Loading branch information
1 parent
4b87725
commit 2637b38
Showing
12 changed files
with
321 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
import EventEmitter from "events"; | ||
import { InboundRtpEntry } from "../entries/StatsEntryInterfaces"; | ||
|
||
export type VideoFreezesDetectorConfig = { | ||
// empty | ||
} | ||
|
||
export type FreezedVideoStartedEvent = { | ||
peerConnectionId: string | undefined, | ||
trackId: string, | ||
ssrc: number, | ||
} | ||
|
||
export type FreezedVideoEndedEvent = { | ||
peerConnectionId: string, | ||
trackId: string, | ||
durationInS: number, | ||
} | ||
|
||
export type VideoFreezesDetectorEvents = { | ||
freezedVideoStarted: [FreezedVideoStartedEvent], | ||
freezedVideoEnded: [FreezedVideoEndedEvent], | ||
close: [], | ||
} | ||
|
||
type InboundRtpStatsTrace = { | ||
ssrc: number, | ||
lastFreezeCount: number, | ||
freezedStartedDuration?: number, | ||
freezed: boolean, | ||
visited: boolean, | ||
} | ||
|
||
export declare interface VideoFreezesDetector { | ||
on<K extends keyof VideoFreezesDetectorEvents>(event: K, listener: (...events: VideoFreezesDetectorEvents[K]) => void): this; | ||
off<K extends keyof VideoFreezesDetectorEvents>(event: K, listener: (...events: VideoFreezesDetectorEvents[K]) => void): this; | ||
once<K extends keyof VideoFreezesDetectorEvents>(event: K, listener: (...events: VideoFreezesDetectorEvents[K]) => void): this; | ||
emit<K extends keyof VideoFreezesDetectorEvents>(event: K, ...events: VideoFreezesDetectorEvents[K]): boolean; | ||
} | ||
|
||
export class VideoFreezesDetector extends EventEmitter { | ||
private _closed = false; | ||
private readonly _traces = new Map<number, InboundRtpStatsTrace>(); | ||
|
||
public constructor( | ||
public readonly config: VideoFreezesDetectorConfig, | ||
) { | ||
super(); | ||
this.setMaxListeners(Infinity); | ||
|
||
} | ||
|
||
public close() { | ||
if (this._closed) return; | ||
this._closed = true; | ||
|
||
this._traces.clear(); | ||
this.emit('close'); | ||
} | ||
|
||
public update(inboundRtps: IterableIterator<InboundRtpEntry>) { | ||
for (const inboundRtp of inboundRtps) { | ||
const stats = inboundRtp.stats; | ||
const trackId = inboundRtp.getTrackId(); | ||
const ssrc = stats.ssrc; | ||
if (stats.kind !== 'video' || trackId === undefined) { | ||
continue; | ||
} | ||
|
||
let trace = this._traces.get(ssrc); | ||
if (!trace) { | ||
trace = { | ||
ssrc, | ||
lastFreezeCount: 0, | ||
freezed: false, | ||
freezedStartedDuration: 0, | ||
visited: false, | ||
}; | ||
this._traces.set(ssrc, trace); | ||
} | ||
|
||
const wasFreezed = trace.freezed; | ||
|
||
trace.visited = true; | ||
trace.freezed = 0 < Math.max(0, (stats.freezeCount ?? 0) - trace.lastFreezeCount); | ||
trace.lastFreezeCount = stats.freezeCount ?? 0; | ||
|
||
if (!wasFreezed && trace.freezed) { | ||
trace.freezedStartedDuration = stats.totalFreezesDuration ?? 0; | ||
this.emit('freezedVideoStarted', { | ||
peerConnectionId: inboundRtp.getPeerConnection()?.peerConnectionId, | ||
trackId, | ||
ssrc, | ||
}) | ||
} else if (wasFreezed && !trace.freezed) { | ||
const durationInS = Math.max(0, (stats.totalFreezesDuration ?? 0) - (trace.freezedStartedDuration ?? 0)); | ||
|
||
trace.freezedStartedDuration = undefined; | ||
|
||
0 < durationInS && this.emit('freezedVideoEnded', { | ||
peerConnectionId: inboundRtp.getPeerConnection()?.peerConnectionId, | ||
trackId, | ||
durationInS, | ||
}) | ||
} | ||
} | ||
|
||
for (const trace of this._traces.values()) { | ||
if (trace.visited) { | ||
trace.visited = false; | ||
|
||
continue; | ||
} | ||
|
||
this._traces.delete(trace.ssrc); | ||
} | ||
} | ||
} |
Oops, something went wrong.