UNPKG

@observertc/observer-js

Version:

Server Side NodeJS Library for processing ObserveRTC Samples

434 lines (433 loc) 22.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ObserverEventMonitor = void 0; class ObserverEventMonitor { observer; context; constructor(observer, context) { this.observer = observer; 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._onOutboundTrackMuted = this._onOutboundTrackMuted.bind(this); this._onOutboundTrackUnmuted = this._onOutboundTrackUnmuted.bind(this); this._onInboundRtpAdded = this._onInboundRtpAdded.bind(this); this._onInboundRtpRemoved = this._onInboundRtpRemoved.bind(this); this._onInboundRtpUpdated = this._onInboundRtpUpdated.bind(this); this._onOutboundTrackUpdated = this._onOutboundTrackUpdated.bind(this); this._onInboundTrackUpdated = this._onInboundTrackUpdated.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._onCertificateUpdated = this._onCertificateUpdated.bind(this); this._onInboundRtpUpdated = this._onInboundRtpUpdated.bind(this); this._onOutboundRtpUpdated = this._onOutboundRtpUpdated.bind(this); this._onInboundTrackUpdated = this._onInboundTrackUpdated.bind(this); this._onOutboundTrackUpdated = this._onOutboundTrackUpdated.bind(this); this._onDataChannelUpdated = this._onDataChannelUpdated.bind(this); this._onIceTransportUpdated = this._onIceTransportUpdated.bind(this); this._onIceCandidatePairUpdated = this._onIceCandidatePairUpdated.bind(this); this._onMediaCodecUpdated = this._onMediaCodecUpdated.bind(this); this._onMediaPlayoutUpdated = this._onMediaPlayoutUpdated.bind(this); this._onMediaSourceUpdated = this._onMediaSourceUpdated.bind(this); this._onIceCandidateUpdated = this._onIceCandidateUpdated.bind(this); this.observer.once('close', () => { this.observer.off('newcall', this._onCallAdded); }); this.observer.on('newcall', this._onCallAdded); } // Public event handlers onCallAdded; onCallRemoved; onCallEmpty; onCallNotEmpty; onCallUpdated; onClientAdded; onClientClosed; onClientRejoined; onClientIssue; onClientMetadata; onClientExtensionStats; onClientJoined; onClientLeft; onClientUserMediaError; onClientUsingTurn; onClientUpdated; onClientEvent; onPeerConnectionAdded; onPeerConnectionRemoved; onSelectedCandidatePairChanged; onIceGatheringStateChange; onIceConnectionStateChange; onConnectionStateChange; onCertificateAdded; onCertificateRemoved; onCertificateUpdated; onInboundTrackAdded; onInboundTrackRemoved; onInboundTrackUpdated; onInboundTrackMuted; onInboundTrackUnmuted; onOutboundTrackAdded; onOutboundTrackRemoved; onOutboundTrackUpdated; onOutboundTrackMuted; onOutboundTrackUnmuted; onInboundRtpAdded; onInboundRtpRemoved; onInboundRtpUpdated; onOutboundRtpAdded; onOutboundRtpRemoved; onOutboundRtpUpdated; onDataChannelAdded; onDataChannelRemoved; onDataChannelUpdated; onAddedIceTransport; onRemovedIceTransport; onIceTransportUpdated; onIceCandidateAdded; onIceCandidateRemoved; onIceCandidateUpdated; onAddedIceCandidatePair; onRemovedIceCandidatePair; onIceCandidatePairUpdated; onAddedMediaCodec; onRemovedMediaCodec; onMediaCodecUpdated; onAddedMediaPlayout; onRemovedMediaPlayout; onMediaPlayoutUpdated; onMediaSourceAdded; onMediaSourceRemoved; onMediaSourceUpdated; _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.onCallRemoved?.(call, this.context); }); call.on('newclient', this._onClientAdded); call.on('empty', onCallEmpty); call.on('not-empty', onCallNotEmpty); call.on('update', onCallUpdated); this.onCallAdded?.(call, this.context); } _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('extensionStats', onClientExtensionStats); 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('updated-certificate', this._onCertificateUpdated); peerConnection.off('added-inbound-track', this._onInboundTrackAdded); peerConnection.off('removed-inbound-track', this._onInboundTrackRemoved); peerConnection.off('updated-inbound-track', this._onInboundTrackUpdated); peerConnection.off('muted-inbound-track', this._onInboundTrackMuted); peerConnection.off('unmuted-inbound-track', this._onInboundTrackUnmuted); peerConnection.off('added-outbound-track', this._onOutboundTrackAdded); peerConnection.off('removed-outbound-track', this._onOutboundTrackRemoved); peerConnection.off('updated-outbound-track', this._onOutboundTrackUpdated); peerConnection.off('muted-outbound-track', this._onOutboundTrackMuted); peerConnection.off('unmuted-outbound-track', this._onOutboundTrackUnmuted); peerConnection.off('added-inbound-rtp', this._onInboundRtpAdded); peerConnection.off('removed-inbound-rtp', this._onInboundRtpRemoved); peerConnection.off('updated-inbound-rtp', this._onInboundRtpUpdated); peerConnection.off('added-outbound-rtp', this._onOutboundRtpAdded); peerConnection.off('removed-outbound-rtp', this._onOutboundRtpRemoved); peerConnection.off('updated-outbound-rtp', this._onOutboundRtpUpdated); peerConnection.off('added-data-channel', this._onDataChannelAdded); peerConnection.off('removed-data-channel', this._onDataChannelRemoved); peerConnection.off('updated-data-channel', this._onDataChannelUpdated); peerConnection.off('added-ice-transport', this._onAddedIceTransport); peerConnection.off('removed-ice-transport', this._onRemovedIceTransport); peerConnection.off('updated-ice-transport', this._onIceTransportUpdated); peerConnection.off('added-ice-candidate', this._onIceCandidateAdded); peerConnection.off('removed-ice-candidate', this._onIceCandidateRemoved); peerConnection.off('updated-ice-candidate', this._onIceCandidateUpdated); peerConnection.off('added-ice-candidate-pair', this._onAddedIceCandidatePair); peerConnection.off('removed-ice-candidate-pair', this._onRemovedIceCandidatePair); peerConnection.off('updated-ice-candidate-pair', this._onIceCandidatePairUpdated); peerConnection.off('added-codec', this._onAddedMediaCodec); peerConnection.off('removed-codec', this._onRemovedMediaCodec); peerConnection.off('updated-codec', this._onMediaCodecUpdated); peerConnection.off('added-media-playout', this._onAddedMediaPlayout); peerConnection.off('removed-media-playout', this._onRemovedMediaPlayout); peerConnection.off('updated-media-playout', this._onMediaPlayoutUpdated); peerConnection.off('added-media-source', this._onMediaSourceAdded); peerConnection.off('removed-media-source', this._onMediaSourceRemoved); peerConnection.off('updated-media-source', this._onMediaSourceUpdated); 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('updated-certificate', this._onCertificateUpdated); peerConnection.on('added-inbound-track', this._onInboundTrackAdded); peerConnection.on('removed-inbound-track', this._onInboundTrackRemoved); peerConnection.on('updated-inbound-track', this._onInboundTrackUpdated); peerConnection.on('muted-inbound-track', this._onInboundTrackMuted); peerConnection.on('unmuted-inbound-track', this._onInboundTrackUnmuted); peerConnection.on('added-outbound-track', this._onOutboundTrackAdded); peerConnection.on('removed-outbound-track', this._onOutboundTrackRemoved); peerConnection.on('updated-outbound-track', this._onOutboundTrackUpdated); peerConnection.on('muted-outbound-track', this._onOutboundTrackMuted); peerConnection.on('unmuted-outbound-track', this._onOutboundTrackUnmuted); peerConnection.on('added-inbound-rtp', this._onInboundRtpAdded); peerConnection.on('removed-inbound-rtp', this._onInboundRtpRemoved); peerConnection.on('updated-inbound-rtp', this._onInboundRtpUpdated); peerConnection.on('added-outbound-rtp', this._onOutboundRtpAdded); peerConnection.on('removed-outbound-rtp', this._onOutboundRtpRemoved); peerConnection.on('updated-outbound-rtp', this._onOutboundRtpUpdated); peerConnection.on('added-data-channel', this._onDataChannelAdded); peerConnection.on('removed-data-channel', this._onDataChannelRemoved); peerConnection.on('updated-data-channel', this._onDataChannelUpdated); peerConnection.on('added-ice-transport', this._onAddedIceTransport); peerConnection.on('removed-ice-transport', this._onRemovedIceTransport); peerConnection.on('updated-ice-transport', this._onIceTransportUpdated); peerConnection.on('added-ice-candidate', this._onIceCandidateAdded); peerConnection.on('removed-ice-candidate', this._onIceCandidateRemoved); peerConnection.on('updated-ice-candidate', this._onIceCandidateUpdated); peerConnection.on('added-ice-candidate-pair', this._onAddedIceCandidatePair); peerConnection.on('removed-ice-candidate-pair', this._onRemovedIceCandidatePair); peerConnection.on('updated-ice-candidate-pair', this._onIceCandidatePairUpdated); peerConnection.on('added-codec', this._onAddedMediaCodec); peerConnection.on('removed-codec', this._onRemovedMediaCodec); peerConnection.on('updated-codec', this._onMediaCodecUpdated); peerConnection.on('added-media-playout', this._onAddedMediaPlayout); peerConnection.on('removed-media-playout', this._onRemovedMediaPlayout); peerConnection.on('updated-media-playout', this._onMediaPlayoutUpdated); peerConnection.on('added-media-source', this._onMediaSourceAdded); peerConnection.on('removed-media-source', this._onMediaSourceRemoved); peerConnection.on('updated-media-source', this._onMediaSourceUpdated); 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); } _onCertificateUpdated(certificate) { this.onCertificateUpdated?.(certificate, this.context); } _onInboundTrackAdded(inboundTrack) { this.onInboundTrackAdded?.(inboundTrack, this.context); } _onInboundTrackRemoved(inboundTrack) { this.onInboundTrackRemoved?.(inboundTrack, this.context); } _onInboundTrackUpdated(inboundTrack) { this.onInboundTrackUpdated?.(inboundTrack, this.context); } _onOutboundTrackMuted(outboundTrack) { this.onOutboundTrackMuted?.(outboundTrack, this.context); } _onOutboundTrackUnmuted(outboundTrack) { this.onOutboundTrackUnmuted?.(outboundTrack, this.context); } _onOutboundTrackAdded(outboundTrack) { this.onOutboundTrackAdded?.(outboundTrack, this.context); } _onOutboundTrackRemoved(outboundTrack) { this.onOutboundTrackRemoved?.(outboundTrack, this.context); } _onOutboundTrackUpdated(outboundTrack) { this.onOutboundTrackUpdated?.(outboundTrack, this.context); } _onInboundTrackMuted(inboundTrack) { this.onInboundTrackMuted?.(inboundTrack, this.context); } _onInboundTrackUnmuted(inboundTrack) { this.onInboundTrackUnmuted?.(inboundTrack, this.context); } _onInboundRtpAdded(inboundRtp) { this.onInboundRtpAdded?.(inboundRtp, this.context); } _onInboundRtpRemoved(inboundRtp) { this.onInboundRtpRemoved?.(inboundRtp, this.context); } _onInboundRtpUpdated(inboundRtp) { this.onInboundRtpUpdated?.(inboundRtp, this.context); } _onOutboundRtpAdded(outboundRtp) { this.onOutboundRtpAdded?.(outboundRtp, this.context); } _onOutboundRtpRemoved(outboundRtp) { this.onOutboundRtpRemoved?.(outboundRtp, this.context); } _onOutboundRtpUpdated(outboundRtp) { this.onOutboundRtpUpdated?.(outboundRtp, this.context); } _onDataChannelAdded(dataChannel) { this.onDataChannelAdded?.(dataChannel, this.context); } _onDataChannelRemoved(dataChannel) { this.onDataChannelRemoved?.(dataChannel, this.context); } _onDataChannelUpdated(dataChannel) { this.onDataChannelUpdated?.(dataChannel, this.context); } _onAddedIceTransport(iceTransport) { this.onAddedIceTransport?.(iceTransport, this.context); } _onRemovedIceTransport(iceTransport) { this.onRemovedIceTransport?.(iceTransport, this.context); } _onIceTransportUpdated(iceTransport) { this.onIceTransportUpdated?.(iceTransport, this.context); } _onIceCandidateAdded(iceCandidate) { this.onIceCandidateAdded?.(iceCandidate, this.context); } _onIceCandidateRemoved(iceCandidate) { this.onIceCandidateRemoved?.(iceCandidate, this.context); } _onIceCandidateUpdated(iceCandidate) { this.onIceCandidateUpdated?.(iceCandidate, this.context); } _onAddedIceCandidatePair(candidatePair) { this.onAddedIceCandidatePair?.(candidatePair, this.context); } _onRemovedIceCandidatePair(candidatePair) { this.onRemovedIceCandidatePair?.(candidatePair, this.context); } _onIceCandidatePairUpdated(candidatePair) { this.onIceCandidatePairUpdated?.(candidatePair, this.context); } _onAddedMediaCodec(codec) { this.onAddedMediaCodec?.(codec, this.context); } _onRemovedMediaCodec(codec) { this.onRemovedMediaCodec?.(codec, this.context); } _onMediaCodecUpdated(codec) { this.onMediaCodecUpdated?.(codec, this.context); } _onAddedMediaPlayout(mediaPlayout) { this.onAddedMediaPlayout?.(mediaPlayout, this.context); } _onRemovedMediaPlayout(mediaPlayout) { this.onRemovedMediaPlayout?.(mediaPlayout, this.context); } _onMediaPlayoutUpdated(mediaPlayout) { this.onMediaPlayoutUpdated?.(mediaPlayout, this.context); } _onMediaSourceAdded(mediaSource) { this.onMediaSourceAdded?.(mediaSource, this.context); } _onMediaSourceRemoved(mediaSource) { this.onMediaSourceRemoved?.(mediaSource, this.context); } _onMediaSourceUpdated(mediaSource) { this.onMediaSourceUpdated?.(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.ObserverEventMonitor = ObserverEventMonitor;