@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
290 lines • 15.4 kB
JavaScript
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import { isPhoneNumberIdentifier } from '@azure/communication-common';
import { _toCommunicationIdentifier } from "../../../../../acs-ui-common/src";
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
/**
* Facade around the CallWithChatAdapter to satisfy the call adapter interface.
*
* @private
*/
export class CallWithChatBackedCallAdapter {
constructor(callWithChatAdapter) {
// For onStateChange we must convert CallWithChat state to chat state. This involves creating a new handler to be passed into the onStateChange.
// In order to unsubscribe the handler when offStateChange is called we must have a mapping of the original handler to the newly created handler.
this.eventStore = new Map();
this.on = (event, listener) => {
switch (event) {
case 'error':
return this.callWithChatAdapter.on('callError', listener);
case 'participantsJoined':
return this.callWithChatAdapter.on('callParticipantsJoined', listener);
case 'participantsLeft':
return this.callWithChatAdapter.on('callParticipantsLeft', listener);
default:
return this.callWithChatAdapter.on(event, listener);
}
};
this.off = (event, listener) => {
switch (event) {
case 'error':
return this.callWithChatAdapter.off('callError', listener);
case 'participantsJoined':
return this.callWithChatAdapter.off('callParticipantsJoined', listener);
case 'participantsLeft':
return this.callWithChatAdapter.off('callParticipantsLeft', listener);
default:
return this.callWithChatAdapter.off(event, listener);
}
};
this.onStateChange = (handler) => {
const convertedHandler = (state) => {
handler(callAdapterStateFromCallWithChatAdapterState(state));
};
this.callWithChatAdapter.onStateChange(convertedHandler);
this.eventStore.set(handler, convertedHandler);
};
this.offStateChange = (handler) => {
const convertedHandler = this.eventStore.get(handler);
if (convertedHandler) {
this.callWithChatAdapter.offStateChange(convertedHandler);
}
};
this.getState = () => callAdapterStateFromCallWithChatAdapterState(this.callWithChatAdapter.getState());
this.dispose = () => this.callWithChatAdapter.dispose();
this.joinCall = (options) => {
if (typeof options === 'boolean') {
return this.callWithChatAdapter.joinCall(options);
}
else {
return this.callWithChatAdapter.joinCall(options);
}
};
this.leaveCall = (forEveryone) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.leaveCall(forEveryone); });
this.startCall = (participants, options) => {
if (participants.every((participant) => typeof participant === 'string')) {
return this.callWithChatAdapter.startCall(participants, options);
}
else {
return this.callWithChatAdapter.startCall(participants, options);
}
};
this.setCamera = (sourceId, options) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.setCamera(sourceId, options); });
this.setMicrophone = (sourceId) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.setMicrophone(sourceId); });
this.setSpeaker = (sourceId) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.setSpeaker(sourceId); });
this.askDevicePermission = (constraints) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.askDevicePermission(constraints); });
this.queryCameras = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.queryCameras(); });
this.queryMicrophones = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.queryMicrophones(); });
this.querySpeakers = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.querySpeakers(); });
this.startCamera = (options) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.startCamera(options); });
this.stopCamera = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.stopCamera(); });
this.mute = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.mute(); });
this.unmute = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.unmute(); });
this.startScreenShare = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.startScreenShare(); });
this.stopScreenShare = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.stopScreenShare(); });
this.raiseHand = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.raiseHand(); });
this.lowerHand = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.lowerHand(); });
this.onReactionClick = (reaction) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.onReactionClick(reaction); });
this.removeParticipant = (userId) => __awaiter(this, void 0, void 0, function* () {
let participant = userId;
participant = _toCommunicationIdentifier(userId);
yield this.callWithChatAdapter.removeParticipant(participant);
});
this.createStreamView = (remoteUserId, options) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.createStreamView(remoteUserId, options); });
this.createTogetherModeStreamView = (options) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.createTogetherModeStreamView(options); });
this.startTogetherMode = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.startTogetherMode(); });
this.setTogetherModeSceneSize = (width, height) => this.callWithChatAdapter.setTogetherModeSceneSize(width, height);
this.disposeStreamView = (remoteUserId, options) => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.disposeStreamView(remoteUserId, options); });
this.disposeTogetherModeStreamView = () => __awaiter(this, void 0, void 0, function* () { return yield this.callWithChatAdapter.disposeTogetherModeStreamView(); });
this.holdCall = () => __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.holdCall();
});
this.resumeCall = () => __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.resumeCall();
});
this.sendDtmfTone = (dtmfTone) => __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.sendDtmfTone(dtmfTone);
});
this.callWithChatAdapter = callWithChatAdapter;
}
disposeScreenShareStreamView(remoteUserId) {
return this.callWithChatAdapter.disposeScreenShareStreamView(remoteUserId);
}
disposeRemoteVideoStreamView(remoteUserId) {
return this.callWithChatAdapter.disposeRemoteVideoStreamView(remoteUserId);
}
disposeLocalVideoStreamView() {
return this.callWithChatAdapter.disposeLocalVideoStreamView();
}
addParticipant(participant, options) {
return __awaiter(this, void 0, void 0, function* () {
if (isPhoneNumberIdentifier(participant) && options) {
return this.callWithChatAdapter.addParticipant(participant, options);
}
else {
return this.callWithChatAdapter.addParticipant(participant);
}
});
}
startCaptions(options) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.startCaptions(options);
});
}
stopCaptions(options) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.stopCaptions(options);
});
}
setCaptionLanguage(language) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.setCaptionLanguage(language);
});
}
setSpokenLanguage(language) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.setSpokenLanguage(language);
});
}
sendRealTimeText(text, isFinalized) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.sendRealTimeText(text, isFinalized);
});
}
startVideoBackgroundEffect(videoBackgroundEffect) {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.startVideoBackgroundEffect(videoBackgroundEffect);
});
}
stopVideoBackgroundEffects() {
return __awaiter(this, void 0, void 0, function* () {
yield this.callWithChatAdapter.stopVideoBackgroundEffects();
});
}
updateBackgroundPickerImages(backgroundImages) {
return this.callWithChatAdapter.updateBackgroundPickerImages(backgroundImages);
}
updateSelectedVideoBackgroundEffect(selectedVideoBackground) {
return this.callWithChatAdapter.updateSelectedVideoBackgroundEffect(selectedVideoBackground);
}
startNoiseSuppressionEffect() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.startNoiseSuppressionEffect();
});
}
stopNoiseSuppressionEffect() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.stopNoiseSuppressionEffect();
});
}
submitSurvey(survey) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.submitSurvey(survey);
});
}
startSpotlight(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.startSpotlight(userIds);
});
}
stopSpotlight(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.stopSpotlight(userIds);
});
}
stopAllSpotlight() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.stopAllSpotlight();
});
}
muteParticipant(userId) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.muteParticipant(userId);
});
}
muteAllRemoteParticipants() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.muteAllRemoteParticipants();
});
}
returnFromBreakoutRoom() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.returnFromBreakoutRoom();
});
}
forbidAudio(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.forbidAudio(userIds);
});
}
permitAudio(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.permitAudio(userIds);
});
}
forbidOthersAudio() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.forbidOthersAudio();
});
}
permitOthersAudio() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.permitOthersAudio();
});
}
forbidVideo(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.forbidAudio(userIds);
});
}
permitVideo(userIds) {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.permitAudio(userIds);
});
}
forbidOthersVideo() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.forbidOthersAudio();
});
}
permitOthersVideo() {
return __awaiter(this, void 0, void 0, function* () {
return this.callWithChatAdapter.permitOthersAudio();
});
}
}
function callAdapterStateFromCallWithChatAdapterState(callWithChatAdapterState) {
return {
isLocalPreviewMicrophoneEnabled: callWithChatAdapterState.isLocalPreviewMicrophoneEnabled,
page: callWithChatAdapterState.page,
userId: callWithChatAdapterState.userId,
displayName: callWithChatAdapterState.displayName,
call: callWithChatAdapterState.call,
devices: callWithChatAdapterState.devices,
isTeamsCall: callWithChatAdapterState.isTeamsCall,
isTeamsMeeting: callWithChatAdapterState.isTeamsMeeting,
isRoomsCall: false,
latestErrors: callWithChatAdapterState.latestCallErrors,
latestNotifications: callWithChatAdapterState.latestCallNotifications,
alternateCallerId: callWithChatAdapterState.alternateCallerId,
environmentInfo: callWithChatAdapterState.environmentInfo,
videoBackgroundImages: callWithChatAdapterState.videoBackgroundImages,
onResolveVideoEffectDependency: callWithChatAdapterState.onResolveVideoEffectDependency,
onResolveDeepNoiseSuppressionDependency: callWithChatAdapterState.onResolveDeepNoiseSuppressionDependency,
deepNoiseSuppressionOnByDefault: callWithChatAdapterState.deepNoiseSuppressionOnByDefault,
hideDeepNoiseSuppressionButton: callWithChatAdapterState.hideDeepNoiseSuppressionButton,
selectedVideoBackgroundEffect: callWithChatAdapterState.selectedVideoBackgroundEffect,
reactions: callWithChatAdapterState.reactions
};
}
//# sourceMappingURL=CallWithChatBackedCallAdapter.js.map