@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
68 lines • 4.15 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { getDisplayName, getIdentifier, getRemoteParticipants, getStartCaptionsInProgress, getSupportedCaptionLanguages } from './baseSelectors';
import { getCaptions, getCaptionsStatus, getCurrentCaptionLanguage, getCurrentSpokenLanguage, getSupportedSpokenLanguages } from './baseSelectors';
import * as reselect from 'reselect';
import { toFlatCommunicationIdentifier } from "../../acs-ui-common/src";
/**
* Selector for {@link StartCaptionsButton} component.
*
* @public
*/
export const startCaptionsButtonSelector = reselect.createSelector([getCaptionsStatus, getCurrentCaptionLanguage, getCurrentSpokenLanguage], (isCaptionsFeatureActive, currentCaptionLanguage, currentSpokenLanguage) => {
return {
checked: isCaptionsFeatureActive !== null && isCaptionsFeatureActive !== void 0 ? isCaptionsFeatureActive : false,
currentCaptionLanguage: currentCaptionLanguage !== null && currentCaptionLanguage !== void 0 ? currentCaptionLanguage : '',
currentSpokenLanguage: currentSpokenLanguage !== null && currentSpokenLanguage !== void 0 ? currentSpokenLanguage : 'en-us'
};
});
/**
* Selector for Changing caption language and spoken language
*
* @public
*/
export const captionSettingsSelector = reselect.createSelector([getSupportedCaptionLanguages, getCurrentCaptionLanguage, getSupportedSpokenLanguages, getCurrentSpokenLanguage, getCaptionsStatus], (supportedCaptionLanguages, currentCaptionLanguage, supportedSpokenLanguages, currentSpokenLanguage, isCaptionsFeatureActive) => {
return {
supportedCaptionLanguages: supportedCaptionLanguages !== null && supportedCaptionLanguages !== void 0 ? supportedCaptionLanguages : [],
currentCaptionLanguage: currentCaptionLanguage !== null && currentCaptionLanguage !== void 0 ? currentCaptionLanguage : 'en',
supportedSpokenLanguages: supportedSpokenLanguages !== null && supportedSpokenLanguages !== void 0 ? supportedSpokenLanguages : ['en-us'],
currentSpokenLanguage: currentSpokenLanguage !== null && currentSpokenLanguage !== void 0 ? currentSpokenLanguage : 'en-us',
isCaptionsFeatureActive: isCaptionsFeatureActive !== null && isCaptionsFeatureActive !== void 0 ? isCaptionsFeatureActive : false
};
});
/**
* Selector for {@link CaptionsBanner} component.
*
* @public
*/
export const captionsBannerSelector = reselect.createSelector([getCaptions, getCaptionsStatus, getStartCaptionsInProgress, getRemoteParticipants, getDisplayName, getIdentifier], (captions, isCaptionsFeatureActive, startCaptionsInProgress, remoteParticipants, displayName, identifier) => {
const captionsInfo = captions === null || captions === void 0 ? void 0 : captions.map((c, index) => {
const userId = getCaptionsSpeakerIdentifier(c);
let finalDisplayName;
if (userId === identifier) {
finalDisplayName = displayName;
}
else if (remoteParticipants) {
const participant = remoteParticipants[userId];
if (participant) {
finalDisplayName = participant.displayName;
}
}
return {
id: (finalDisplayName !== null && finalDisplayName !== void 0 ? finalDisplayName : 'Unnamed Participant') + index,
displayName: finalDisplayName !== null && finalDisplayName !== void 0 ? finalDisplayName : 'Unnamed Participant',
captionText: c.captionText,
userId,
createdTimeStamp: c.timestamp
};
});
return {
captions: captionsInfo !== null && captionsInfo !== void 0 ? captionsInfo : [],
isCaptionsOn: isCaptionsFeatureActive !== null && isCaptionsFeatureActive !== void 0 ? isCaptionsFeatureActive : false,
startCaptionsInProgress: startCaptionsInProgress !== null && startCaptionsInProgress !== void 0 ? startCaptionsInProgress : false
};
});
const getCaptionsSpeakerIdentifier = (captions) => {
return captions.speaker.identifier ? toFlatCommunicationIdentifier(captions.speaker.identifier) : '';
};
//# sourceMappingURL=captionsSelector.js.map