@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
257 lines • 8.32 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { toFlatCommunicationIdentifier } from "../../acs-ui-common/src";
import { _isTeamsIncomingCall } from './TypeGuards';
import { _isACSCall } from './TypeGuards';
import { _isTeamsCall } from './TypeGuards';
import { Features } from '@azure/communication-calling';
/**
* @private
*/
export function convertSdkLocalStreamToDeclarativeLocalStream(stream) {
const localVideoStreamEffectsAPI = stream.feature(Features.VideoEffects);
return {
source: stream.source,
mediaStreamType: stream.mediaStreamType,
view: undefined,
videoEffects: convertFromSDKToDeclarativeVideoStreamVideoEffects(localVideoStreamEffectsAPI.activeEffects)
};
}
/**
* @private
*/
export function convertSdkRemoteStreamToDeclarativeRemoteStream(stream) {
return {
id: stream.id,
mediaStreamType: stream.mediaStreamType,
isAvailable: stream.isAvailable,
isReceiving: stream.isReceiving,
view: undefined,
streamSize: stream.size
};
}
/**
* @private
*/
export function convertSdkCallFeatureStreamToDeclarativeCallFeatureStream(stream, featureName) {
return {
feature: featureName,
id: stream.id,
mediaStreamType: stream.mediaStreamType,
isAvailable: stream.isAvailable,
isReceiving: stream.isReceiving,
view: undefined,
streamSize: stream.size
};
}
/**
* @private
*/
export function convertSdkParticipantToDeclarativeParticipant(participant) {
const declarativeVideoStreams = {};
for (const videoStream of participant.videoStreams) {
declarativeVideoStreams[videoStream.id] = convertSdkRemoteStreamToDeclarativeRemoteStream(videoStream);
}
return {
identifier: participant.identifier,
displayName: participant.displayName,
state: participant.state,
callEndReason: participant.callEndReason,
videoStreams: declarativeVideoStreams,
isMuted: participant.isMuted,
isSpeaking: participant.isSpeaking,
raisedHand: undefined,
role: participant.role,
spotlight: undefined,
mediaAccess: undefined
};
}
/**
* @private
*
* Note at the time of writing only one LocalVideoStream is supported by the SDK.
*/
export function convertSdkCallToDeclarativeCall(call) {
const declarativeRemoteParticipants = {};
call.remoteParticipants.forEach((participant) => {
declarativeRemoteParticipants[toFlatCommunicationIdentifier(participant.identifier)] = convertSdkParticipantToDeclarativeParticipant(participant);
});
let hideAttendeeNames = false;
if (call.feature(Features.Capabilities).capabilities && call.feature(Features.Capabilities).capabilities.viewAttendeeNames) {
const viewAttendeeNames = call.feature(Features.Capabilities).capabilities.viewAttendeeNames;
if (!viewAttendeeNames.isPresent && viewAttendeeNames.reason === 'MeetingRestricted') {
hideAttendeeNames = true;
}
}
let callInfo;
if ('info' in call) {
callInfo = call.info;
}
return {
id: call.id,
kind: _isACSCall(call) ? 'Call' : 'TeamsCall',
callerInfo: call.callerInfo,
state: call.state,
callEndReason: call.callEndReason,
diagnostics: {
network: {
latest: {}
},
media: {
latest: {}
}
},
direction: call.direction,
isMuted: call.isMuted,
isScreenSharingOn: call.isScreenSharingOn,
localVideoStreams: call.localVideoStreams.map(convertSdkLocalStreamToDeclarativeLocalStream),
remoteParticipants: declarativeRemoteParticipants,
remoteParticipantsEnded: {},
recording: {
isRecordingActive: false
},
pptLive: {
isActive: false
},
raiseHand: {
raisedHands: []
},
togetherMode: {
isActive: false,
streams: {},
seatingPositions: {}
},
localParticipantReaction: undefined,
transcription: {
isTranscriptionActive: false
},
screenShareRemoteParticipant: undefined,
startTime: new Date(),
endTime: undefined,
role: call.role,
captionsFeature: {
captions: [],
supportedSpokenLanguages: [],
supportedCaptionLanguages: [],
currentCaptionLanguage: '',
currentSpokenLanguage: '',
isCaptionsFeatureActive: false,
startCaptionsInProgress: false,
captionsKind: _isTeamsCall(call) ? 'TeamsCaptions' : 'Captions'
},
realTimeTextFeature: {
realTimeTexts: {},
isRealTimeTextFeatureActive: false
},
transfer: {
acceptedTransfers: {}
},
optimalVideoCount: {
maxRemoteVideoStreams: call.feature(Features.OptimalVideoCount).optimalVideoCount
},
hideAttendeeNames,
info: callInfo,
meetingConference: {
conferencePhones: []
}
};
}
/**
* @private
*/
export function convertSdkIncomingCallToDeclarativeIncomingCall(call) {
if (_isTeamsIncomingCall(call)) {
const newInfo = Object.assign(Object.assign({}, call.info), { kind: call.kind });
return {
id: call.id,
info: newInfo,
callerInfo: call.callerInfo,
startTime: new Date(),
endTime: undefined
};
}
else {
const newInfo = Object.assign(Object.assign({}, call.info), { kind: call.kind });
return {
id: call.id,
info: newInfo,
callerInfo: call.callerInfo,
startTime: new Date(),
endTime: undefined
};
}
const newInfo = Object.assign(Object.assign({}, call.info), { kind: call.kind });
return {
id: call.id,
info: newInfo,
callerInfo: call.callerInfo,
startTime: new Date(),
endTime: undefined
};
}
/**
* @private
*/
export function convertFromSDKToDeclarativeVideoStreamRendererView(view) {
return {
scalingMode: view.scalingMode,
isMirrored: view.isMirrored,
target: view.target
};
}
/**
* @private
*/
export function convertFromTeamsSDKToCaptionInfoState(caption) {
return Object.assign({}, caption);
}
/**
* @private
*/
export function convertFromSDKToCaptionInfoState(caption) {
return Object.assign({ captionText: caption.spokenText }, caption);
}
/**
* @private
*/
export function convertFromSDKRealTimeTextToRealTimeTextInfoState(realTimeText) {
return Object.assign({ message: realTimeText.text, isMe: realTimeText.isLocal }, realTimeText);
}
/** @private */
export function convertFromSDKToDeclarativeVideoStreamVideoEffects(videoEffects) {
return {
activeEffects: videoEffects
};
}
/**
* @private
*/
export function convertFromSDKToRaisedHandState(raisedHand) {
return {
raisedHandOrderPosition: raisedHand.order
};
}
/** @private */
export function convertConferencePhoneInfo(meetingConferencePhoneInfo) {
if (!meetingConferencePhoneInfo) {
return [];
}
return meetingConferencePhoneInfo.phoneNumbers.flatMap(phoneNumber => {
var _a, _b, _c, _d;
const common = {
conferenceId: meetingConferencePhoneInfo.phoneConferenceId,
country: phoneNumber.countryName,
city: phoneNumber.cityName,
phoneNumber: '',
isTollFree: false
};
const toll = Object.assign({}, common);
toll.phoneNumber = (_b = (_a = phoneNumber.tollPhoneNumber) === null || _a === void 0 ? void 0 : _a.phoneNumber) !== null && _b !== void 0 ? _b : '';
toll.isTollFree = false;
const tollFree = Object.assign({}, common);
tollFree.phoneNumber = (_d = (_c = phoneNumber.tollFreePhoneNumber) === null || _c === void 0 ? void 0 : _c.phoneNumber) !== null && _d !== void 0 ? _d : '';
tollFree.isTollFree = true;
return [toll, tollFree].filter(phoneInfo => phoneInfo.phoneNumber);
});
}
//# sourceMappingURL=Converter.js.map