@observertc/observer-js
Version:
Server Side NodeJS Library for processing ObserveRTC Samples
315 lines (314 loc) • 16.3 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ObservedCallEventMonitor = void 0;
class ObservedCallEventMonitor {
call;
context;
constructor(call, context) {
this.call = call;
this.context = context;
this._onPeerConnconnectionAdded = this._onPeerConnconnectionAdded.bind(this);
this._onPeerConnectionRemoved = this._onPeerConnectionRemoved.bind(this);
this._onCertificateAdded = this._onCertificateAdded.bind(this);
this._onCertificateRemoved = this._onCertificateRemoved.bind(this);
this._onInboundTrackAdded = this._onInboundTrackAdded.bind(this);
this._onInboundTrackRemoved = this._onInboundTrackRemoved.bind(this);
this._onOutboundTrackAdded = this._onOutboundTrackAdded.bind(this);
this._onOutboundTrackRemoved = this._onOutboundTrackRemoved.bind(this);
this._onInboundRtpAdded = this._onInboundRtpAdded.bind(this);
this._onInboundRtpRemoved = this._onInboundRtpRemoved.bind(this);
this._onOutboundRtpAdded = this._onOutboundRtpAdded.bind(this);
this._onOutboundRtpRemoved = this._onOutboundRtpRemoved.bind(this);
this._onDataChannelAdded = this._onDataChannelAdded.bind(this);
this._onDataChannelRemoved = this._onDataChannelRemoved.bind(this);
this._onAddedIceTransport = this._onAddedIceTransport.bind(this);
this._onRemovedIceTransport = this._onRemovedIceTransport.bind(this);
this._onIceCandidateAdded = this._onIceCandidateAdded.bind(this);
this._onIceCandidateRemoved = this._onIceCandidateRemoved.bind(this);
this._onAddedIceCandidatePair = this._onAddedIceCandidatePair.bind(this);
this._onRemovedIceCandidatePair = this._onRemovedIceCandidatePair.bind(this);
this._onAddedMediaCodec = this._onAddedMediaCodec.bind(this);
this._onRemovedMediaCodec = this._onRemovedMediaCodec.bind(this);
this._onAddedMediaPlayout = this._onAddedMediaPlayout.bind(this);
this._onRemovedMediaPlayout = this._onRemovedMediaPlayout.bind(this);
this._onMediaSourceAdded = this._onMediaSourceAdded.bind(this);
this._onMediaSourceRemoved = this._onMediaSourceRemoved.bind(this);
this._onClientIssue = this._onClientIssue.bind(this);
this._onClientMetadata = this._onClientMetadata.bind(this);
this._onClientJoined = this._onClientJoined.bind(this);
this._onClientLeft = this._onClientLeft.bind(this);
this._onUserMediaError = this._onUserMediaError.bind(this);
this._onUsingTurn = this._onUsingTurn.bind(this);
this._onClientAdded = this._onClientAdded.bind(this);
this._onCallAdded = this._onCallAdded.bind(this);
this._onClientRejoined = this._onClientRejoined.bind(this);
this._onClientExtensionStats = this._onClientExtensionStats.bind(this);
this._onCallAdded(call);
}
// Public event handlers
onCallClosed;
onCallEmpty;
onCallNotEmpty;
onCallUpdated;
onClientAdded;
onClientClosed;
onClientRejoined;
onClientIssue;
onClientMetadata;
onClientExtensionStats;
onClientJoined;
onClientLeft;
onClientUserMediaError;
onClientUsingTurn;
onClientUpdated;
onClientEvent;
onPeerConnectionAdded;
onPeerConnectionRemoved;
onSelectedCandidatePairChanged;
onIceGatheringStateChange;
onIceConnectionStateChange;
onConnectionStateChange;
onCertificateAdded;
onCertificateRemoved;
onInboundTrackAdded;
onInboundTrackRemoved;
onOutboundTrackAdded;
onOutboundTrackRemoved;
onInboundRtpAdded;
onInboundRtpRemoved;
onOutboundRtpAdded;
onOutboundRtpRemoved;
onDataChannelAdded;
onDataChannelRemoved;
onAddedIceTransport;
onRemovedIceTransport;
onIceCandidateAdded;
onIceCandidateRemoved;
onAddedIceCandidatePair;
onRemovedIceCandidatePair;
onAddedMediaCodec;
onRemovedMediaCodec;
onAddedMediaPlayout;
onRemovedMediaPlayout;
onMediaSourceAdded;
onMediaSourceRemoved;
_onCallAdded(call) {
const onCallEmpty = () => this.onCallEmpty?.(call, this.context);
const onCallNotEmpty = () => this.onCallNotEmpty?.(call, this.context);
const onCallUpdated = () => this.onCallUpdated?.(call, this.context);
call.once('close', () => {
call.off('newclient', this._onClientAdded);
call.off('empty', onCallEmpty);
call.off('not-empty', onCallNotEmpty);
call.off('update', onCallUpdated);
this.onCallClosed?.(call, this.context);
});
call.on('newclient', this._onClientAdded);
call.on('empty', onCallEmpty);
call.on('not-empty', onCallNotEmpty);
call.on('update', onCallUpdated);
}
_onClientAdded(observedClient) {
const onClientIssue = (issue) => this._onClientIssue(observedClient, issue);
const onClientMetadata = (metaData) => this._onClientMetadata(observedClient, metaData);
const onClientJoined = () => this._onClientJoined(observedClient);
const onClientLeft = () => this._onClientLeft(observedClient);
const onClientRejoined = () => this._onClientRejoined(observedClient);
const onClientExtensionStats = (extensionStats) => this._onClientExtensionStats(observedClient, extensionStats);
const onUsingTurn = (usingTurn) => this._onUsingTurn(observedClient, usingTurn);
const onUserMediaError = (error) => this._onUserMediaError(observedClient, error);
const onClientUpdated = (...args) => this.onClientUpdated?.(observedClient, args[0], this.context);
const onClientEvent = (event) => this.onClientEvent?.(observedClient, event, this.context);
observedClient.once('close', () => {
observedClient.off('newpeerconnection', this._onPeerConnconnectionAdded);
observedClient.off('issue', onClientIssue);
observedClient.off('metaData', onClientMetadata);
observedClient.off('joined', onClientJoined);
observedClient.off('left', onClientLeft);
observedClient.off('rejoined', onClientJoined);
observedClient.off('usermediaerror', onUserMediaError);
observedClient.off('usingturn', onUsingTurn);
observedClient.off('update', onClientUpdated);
observedClient.off('clientEvent', onClientEvent);
this.onClientClosed?.(observedClient, this.context);
});
observedClient.on('newpeerconnection', this._onPeerConnconnectionAdded);
observedClient.on('issue', onClientIssue);
observedClient.on('metaData', onClientMetadata);
observedClient.on('joined', onClientJoined);
observedClient.on('left', onClientLeft);
observedClient.on('rejoined', onClientRejoined);
observedClient.on('usermediaerror', onUserMediaError);
observedClient.on('usingturn', onUsingTurn);
observedClient.on('extensionStats', onClientExtensionStats);
observedClient.on('update', onClientUpdated);
observedClient.on('clientEvent', onClientEvent);
this.onClientAdded?.(observedClient, this.context);
}
_onClientRejoined(observedClient) {
this.onClientRejoined?.(observedClient, this.context);
}
_onPeerConnconnectionAdded(peerConnection) {
const onSelectedCandidatePairChanged = () => this.onSelectedCandidatePairChanged?.(peerConnection, this.context);
const onIceGatheringStateChange = () => this.onIceGatheringStateChange?.(peerConnection, this.context);
const onIceConnectionStateChange = () => this.onIceConnectionStateChange?.(peerConnection, this.context);
const onConnectionStateChange = () => this.onConnectionStateChange?.(peerConnection, this.context);
peerConnection.once('close', () => {
peerConnection.off('added-certificate', this._onCertificateAdded);
peerConnection.off('removed-certificate', this._onCertificateRemoved);
peerConnection.off('added-inbound-track', this._onInboundTrackAdded);
peerConnection.off('removed-inbound-track', this._onInboundTrackRemoved);
peerConnection.off('added-outbound-track', this._onOutboundTrackAdded);
peerConnection.off('removed-outbound-track', this._onOutboundTrackRemoved);
peerConnection.off('added-inbound-rtp', this._onInboundRtpAdded);
peerConnection.off('removed-inbound-rtp', this._onInboundRtpRemoved);
peerConnection.off('added-outbound-rtp', this._onOutboundRtpAdded);
peerConnection.off('removed-outbound-rtp', this._onOutboundRtpRemoved);
peerConnection.off('added-data-channel', this._onDataChannelAdded);
peerConnection.off('removed-data-channel', this._onDataChannelRemoved);
peerConnection.off('added-ice-transport', this._onAddedIceTransport);
peerConnection.off('removed-ice-transport', this._onRemovedIceTransport);
peerConnection.off('added-ice-candidate', this._onIceCandidateAdded);
peerConnection.off('removed-ice-candidate', this._onIceCandidateRemoved);
peerConnection.off('added-ice-candidate-pair', this._onAddedIceCandidatePair);
peerConnection.off('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
peerConnection.off('added-codec', this._onAddedMediaCodec);
peerConnection.off('removed-codec', this._onRemovedMediaCodec);
peerConnection.off('added-media-playout', this._onAddedMediaPlayout);
peerConnection.off('removed-media-playout', this._onRemovedMediaPlayout);
peerConnection.off('added-media-source', this._onMediaSourceAdded);
peerConnection.off('removed-media-source', this._onMediaSourceRemoved);
peerConnection.off('selectedcandidatepair', onSelectedCandidatePairChanged);
peerConnection.off('icegatheringstatechange', onIceGatheringStateChange);
peerConnection.off('iceconnectionstatechange', onIceConnectionStateChange);
peerConnection.off('connectionstatechange', onConnectionStateChange);
this.onPeerConnectionRemoved?.(peerConnection, this.context);
});
peerConnection.on('added-certificate', this._onCertificateAdded);
peerConnection.on('removed-certificate', this._onCertificateRemoved);
peerConnection.on('added-inbound-track', this._onInboundTrackAdded);
peerConnection.on('removed-inbound-track', this._onInboundTrackRemoved);
peerConnection.on('added-outbound-track', this._onOutboundTrackAdded);
peerConnection.on('removed-outbound-track', this._onOutboundTrackRemoved);
peerConnection.on('added-inbound-rtp', this._onInboundRtpAdded);
peerConnection.on('removed-inbound-rtp', this._onInboundRtpRemoved);
peerConnection.on('added-outbound-rtp', this._onOutboundRtpAdded);
peerConnection.on('removed-outbound-rtp', this._onOutboundRtpRemoved);
peerConnection.on('added-data-channel', this._onDataChannelAdded);
peerConnection.on('removed-data-channel', this._onDataChannelRemoved);
peerConnection.on('added-ice-transport', this._onAddedIceTransport);
peerConnection.on('removed-ice-transport', this._onRemovedIceTransport);
peerConnection.on('added-ice-candidate', this._onIceCandidateAdded);
peerConnection.on('removed-ice-candidate', this._onIceCandidateRemoved);
peerConnection.on('added-ice-candidate-pair', this._onAddedIceCandidatePair);
peerConnection.on('removed-ice-candidate-pair', this._onRemovedIceCandidatePair);
peerConnection.on('added-codec', this._onAddedMediaCodec);
peerConnection.on('removed-codec', this._onRemovedMediaCodec);
peerConnection.on('added-media-playout', this._onAddedMediaPlayout);
peerConnection.on('removed-media-playout', this._onRemovedMediaPlayout);
peerConnection.on('added-media-source', this._onMediaSourceAdded);
peerConnection.on('removed-media-source', this._onMediaSourceRemoved);
peerConnection.on('selectedcandidatepair', onSelectedCandidatePairChanged);
peerConnection.on('icegatheringstatechange', onIceGatheringStateChange);
peerConnection.on('iceconnectionstatechange', onIceConnectionStateChange);
peerConnection.on('connectionstatechange', onConnectionStateChange);
this.onPeerConnectionAdded?.(peerConnection, this.context);
}
_onPeerConnectionRemoved(peerConnection) {
this.onPeerConnectionRemoved?.(peerConnection, this.context);
}
_onCertificateAdded(certificate) {
this.onCertificateAdded?.(certificate, this.context);
}
_onCertificateRemoved(certificate) {
this.onCertificateRemoved?.(certificate, this.context);
}
_onInboundTrackAdded(inboundTrack) {
this.onInboundTrackAdded?.(inboundTrack, this.context);
}
_onInboundTrackRemoved(inboundTrack) {
this.onInboundTrackRemoved?.(inboundTrack, this.context);
}
_onOutboundTrackAdded(outboundTrack) {
this.onOutboundTrackAdded?.(outboundTrack, this.context);
}
_onOutboundTrackRemoved(outboundTrack) {
this.onOutboundTrackRemoved?.(outboundTrack, this.context);
}
_onInboundRtpAdded(inboundRtp) {
this.onInboundRtpAdded?.(inboundRtp, this.context);
}
_onInboundRtpRemoved(inboundRtp) {
this.onInboundRtpRemoved?.(inboundRtp, this.context);
}
_onOutboundRtpAdded(outboundRtp) {
this.onOutboundRtpAdded?.(outboundRtp, this.context);
}
_onOutboundRtpRemoved(outboundRtp) {
this.onOutboundRtpRemoved?.(outboundRtp, this.context);
}
_onDataChannelAdded(dataChannel) {
this.onDataChannelAdded?.(dataChannel, this.context);
}
_onDataChannelRemoved(dataChannel) {
this.onDataChannelRemoved?.(dataChannel, this.context);
}
_onAddedIceTransport(iceTransport) {
this.onAddedIceTransport?.(iceTransport, this.context);
}
_onRemovedIceTransport(iceTransport) {
this.onRemovedIceTransport?.(iceTransport, this.context);
}
_onIceCandidateAdded(iceCandidate) {
this.onIceCandidateAdded?.(iceCandidate, this.context);
}
_onIceCandidateRemoved(iceCandidate) {
this.onIceCandidateRemoved?.(iceCandidate, this.context);
}
_onAddedIceCandidatePair(candidatePair) {
this.onAddedIceCandidatePair?.(candidatePair, this.context);
}
_onRemovedIceCandidatePair(candidatePair) {
this.onRemovedIceCandidatePair?.(candidatePair, this.context);
}
_onAddedMediaCodec(codec) {
this.onAddedMediaCodec?.(codec, this.context);
}
_onRemovedMediaCodec(codec) {
this.onRemovedMediaCodec?.(codec, this.context);
}
_onAddedMediaPlayout(mediaPlayout) {
this.onAddedMediaPlayout?.(mediaPlayout, this.context);
}
_onRemovedMediaPlayout(mediaPlayout) {
this.onRemovedMediaPlayout?.(mediaPlayout, this.context);
}
_onMediaSourceAdded(mediaSource) {
this.onMediaSourceAdded?.(mediaSource, this.context);
}
_onMediaSourceRemoved(mediaSource) {
this.onMediaSourceRemoved?.(mediaSource, this.context);
}
_onClientIssue(observedClent, issue) {
this.onClientIssue?.(observedClent, issue, this.context);
}
_onClientMetadata(observedClient, metadata) {
this.onClientMetadata?.(observedClient, metadata, this.context);
}
_onClientExtensionStats(observedClient, extensionStats) {
this.onClientExtensionStats?.(observedClient, extensionStats, this.context);
}
_onClientJoined(observedClient) {
this.onClientJoined?.(observedClient, this.context);
}
_onClientLeft(observedClient) {
this.onClientLeft?.(observedClient, this.context);
}
_onUserMediaError(observedClient, error) {
this.onClientUserMediaError?.(observedClient, error, this.context);
}
_onUsingTurn(observedClient, usingTurn) {
this.onClientUsingTurn?.(observedClient, usingTurn, this.context);
}
}
exports.ObservedCallEventMonitor = ObservedCallEventMonitor;