UNPKG

@observertc/observer-js

Version:

Server Side NodeJS Library for processing ObserveRTC Samples

37 lines (36 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OnAnyClientCallUpdater = void 0; class OnAnyClientCallUpdater { _observedCall; name = 'OnAnyClientCallUpdater'; description = 'Call the update() method of the ObservedCall when any of the client has been updated'; closed = false; constructor(_observedCall) { this._observedCall = _observedCall; this._onNewObservedClient = this._onNewObservedClient.bind(this); this._observedCall.once('close', () => { this._observedCall.off('newclient', this._onNewObservedClient); }); this._observedCall.on('newclient', this._onNewObservedClient); } close() { if (this.closed) return; this.closed = true; } _onNewObservedClient(observedClient) { if (this.closed) return; const onUpdate = () => { if (this.closed) return; this._observedCall.update(); }; observedClient.once('close', () => { observedClient.off('update', onUpdate); }); observedClient.on('update', onUpdate); } } exports.OnAnyClientCallUpdater = OnAnyClientCallUpdater;