UNPKG

@azure/communication-react

Version:

React library for building modern communication user experiences utilizing Azure Communication Services

118 lines 6.02 kB
// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. /** * @private */ export class TeamsCaptionsSubscriber { constructor(callIdRef, context, captions) { this.subscribe = () => { this._captions.on('CaptionsActiveChanged', this.isCaptionsActiveChanged); this._captions.on('CaptionsReceived', this.onCaptionsReceived); this._captions.on('CaptionLanguageChanged', this.isCaptionLanguageChanged); this._captions.on('SpokenLanguageChanged', this.isSpokenLanguageChanged); }; this.unsubscribe = () => { this._captions.off('CaptionsActiveChanged', this.isCaptionsActiveChanged); this._captions.off('CaptionsReceived', this.onCaptionsReceived); this._captions.off('CaptionLanguageChanged', this.isCaptionLanguageChanged); this._captions.off('SpokenLanguageChanged', this.isSpokenLanguageChanged); }; this.onCaptionsReceived = (caption) => { this._context.addTeamsCaption(this._callIdRef.callId, caption); }; this.isCaptionsActiveChanged = () => { this._context.setIsCaptionActive(this._callIdRef.callId, this._captions.isCaptionsFeatureActive); }; this.isCaptionLanguageChanged = () => { this._context.setSelectedCaptionLanguage(this._callIdRef.callId, this._captions.activeCaptionLanguage); }; this.isSpokenLanguageChanged = () => { this._context.setSelectedSpokenLanguage(this._callIdRef.callId, this._captions.activeSpokenLanguage); }; this._callIdRef = callIdRef; this._context = context; this._captions = captions; if (this._captions.isCaptionsFeatureActive) { this._context.setIsCaptionActive(this._callIdRef.callId, this._captions.isCaptionsFeatureActive); } this._context.setAvailableSpokenLanguages(this._callIdRef.callId, this._captions.supportedSpokenLanguages); if ('supportedCaptionLanguages' in this._captions) { this._context.setAvailableCaptionLanguages(this._callIdRef.callId, this._captions.supportedCaptionLanguages); } this._context.setSelectedSpokenLanguage(this._callIdRef.callId, this._captions.activeSpokenLanguage); this._context.setSelectedCaptionLanguage(this._callIdRef.callId, this._captions.activeCaptionLanguage); this.subscribe(); } } /** * @private */ export class CaptionsSubscriber { constructor(callIdRef, context, captions) { this.subscribe = () => { this._captions.on('CaptionsActiveChanged', this.isCaptionsActiveChanged); this._captions.on('SpokenLanguageChanged', this.isSpokenLanguageChanged); this._captions.on('CaptionsReceived', this.onCaptionsReceived); }; this.unsubscribe = () => { this._captions.off('CaptionsActiveChanged', this.isCaptionsActiveChanged); this._captions.off('SpokenLanguageChanged', this.isSpokenLanguageChanged); this._captions.off('CaptionsReceived', this.onCaptionsReceived); }; this.onCaptionsReceived = (caption) => { this._context.addCaption(this._callIdRef.callId, caption); }; this.isCaptionsActiveChanged = () => { this._context.setIsCaptionActive(this._callIdRef.callId, this._captions.isCaptionsFeatureActive); }; this.isSpokenLanguageChanged = () => { this._context.setSelectedSpokenLanguage(this._callIdRef.callId, this._captions.activeSpokenLanguage); }; this._callIdRef = callIdRef; this._context = context; this._captions = captions; if (this._captions.isCaptionsFeatureActive) { this._context.setIsCaptionActive(this._callIdRef.callId, this._captions.isCaptionsFeatureActive); } this._context.setAvailableSpokenLanguages(this._callIdRef.callId, this._captions.supportedSpokenLanguages); this._context.setSelectedSpokenLanguage(this._callIdRef.callId, this._captions.activeSpokenLanguage); this.subscribe(); } } /** * @private */ export class CaptionsFeatureSubscriber { constructor(callIdRef, context, captions) { this.subscribe = () => { this._captions.on('CaptionsKindChanged', this.isCaptionsKindChanged); }; this.unsubscribe = () => { var _a, _b; this._captions.off('CaptionsKindChanged', this.isCaptionsKindChanged); (_a = this._TeamsCaptionsSubscriber) === null || _a === void 0 ? void 0 : _a.unsubscribe(); (_b = this._CaptionsSubscriber) === null || _b === void 0 ? void 0 : _b.unsubscribe(); }; this.isCaptionsKindChanged = () => { var _a; this._context.setCaptionsKind(this._callIdRef.callId, this._captions.captions.kind); // ACS call can turn into teams call but teams call will never turn into ACS call so we only need to handle the case when captions kind is TeamsCaptions if (this._captions.captions.kind === 'TeamsCaptions') { (_a = this._CaptionsSubscriber) === null || _a === void 0 ? void 0 : _a.unsubscribe(); this._TeamsCaptionsSubscriber = new TeamsCaptionsSubscriber(this._callIdRef, this._context, this._captions.captions); } }; this._callIdRef = callIdRef; this._context = context; this._captions = captions; this._context.setCaptionsKind(this._callIdRef.callId, this._captions.captions.kind); if (this._captions.captions.kind === 'TeamsCaptions') { this._TeamsCaptionsSubscriber = new TeamsCaptionsSubscriber(this._callIdRef, this._context, this._captions.captions); } else { this._CaptionsSubscriber = new CaptionsSubscriber(this._callIdRef, this._context, this._captions.captions); } this.subscribe(); } } //# sourceMappingURL=CaptionsSubscriber.js.map