UNPKG

communication-react-19

Version:

React library for building modern communication user experiences utilizing Azure Communication Services (React 19 compatible fork)

105 lines 4.14 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /** * @private */ export class UserFacingDiagnosticsSubscriber { constructor(callIdRef, context, diagnostics) { this.unsubscribe = () => { this._diagnostics.network.off('diagnosticChanged', this.networkDiagnosticsChanged.bind(this)); this._diagnostics.media.off('diagnosticChanged', this.mediaDiagnosticsChanged.bind(this)); }; this._callIdRef = callIdRef; this._context = context; this._diagnostics = diagnostics; this.setInitialDiagnostics(); this.subscribe(); } setInitialDiagnostics() { const network = this._diagnostics.network.getLatest(); const media = this._diagnostics.media.getLatest(); if (Object.entries(network).length === 0 && Object.entries(media).length === 0) { return; } this._context.modifyState((state) => { const call = state.calls[this._callIdRef.callId]; if (call === undefined) { return; } call.diagnostics = { network: { latest: network }, media: { latest: media } }; }); } subscribe() { this._diagnostics.network.on('diagnosticChanged', this.networkDiagnosticsChanged.bind(this)); this._diagnostics.media.on('diagnosticChanged', this.mediaDiagnosticsChanged.bind(this)); /* @conditional-compile-remove(remote-ufd) */ this._diagnostics.remote.on('diagnosticChanged', this.remoteDiagnosticsChanged.bind(this)); } /* @conditional-compile-remove(remote-ufd) */ remoteDiagnosticsChanged(args) { this._context.modifyState((state) => { var _a; const call = state.calls[this._callIdRef.callId]; if (call === undefined) { return; } for (const diagnostic of args.diagnostics) { const { remoteParticipant: _, rawId } = diagnostic, participantDiagnostic = __rest(diagnostic, ["remoteParticipant", "rawId"]); const participant = call.remoteParticipants[rawId]; if (participant) { participant.diagnostics = (_a = participant.diagnostics) !== null && _a !== void 0 ? _a : {}; participant.diagnostics[participantDiagnostic.diagnostic] = participantDiagnostic; } } }); } networkDiagnosticsChanged(args) { this._context.modifyState((state) => { var _a; const call = state.calls[this._callIdRef.callId]; if (call === undefined) { return; } const network = (_a = call.diagnostics) === null || _a === void 0 ? void 0 : _a.network.latest; if (network) { network[args.diagnostic] = latestFromEvent(args); } }); } mediaDiagnosticsChanged(args) { this._context.modifyState((state) => { var _a; const call = state.calls[this._callIdRef.callId]; if (call === undefined) { return; } const media = (_a = call.diagnostics) === null || _a === void 0 ? void 0 : _a.media.latest; if (media) { media[args.diagnostic] = latestFromEvent(args); } }); } } const latestFromEvent = (args) => ({ value: args.value, valueType: args.valueType }); //# sourceMappingURL=UserFacingDiagnosticsSubscriber.js.map