@azure/communication-react
Version:
React library for building modern communication user experiences utilizing Azure Communication Services
60 lines • 3.81 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 { isCommunicationUserIdentifier, isMicrosoftTeamsUserIdentifier, isPhoneNumberIdentifier } from '@azure/communication-common';
import { _toCommunicationIdentifier } from "../../../acs-ui-common/src";
import memoizeOne from 'memoize-one';
import { createLocalVideoStream } from '../utils/callUtils';
import { createDefaultCommonCallingHandlers } from './createCommonHandlers';
/**
* Create the default implementation of {@link CallingHandlers} for teams call.
*
* Useful when implementing a custom component that utilizes the providers
* exported from this library.
*
* @public
*/
export const createDefaultCallingHandlers = memoizeOne((...args) => {
const [callClient, callAgent, deviceManager, call, options] = args;
const commonCallingHandlers = createDefaultCommonCallingHandlers(callClient, deviceManager, call, options);
return Object.assign(Object.assign({}, commonCallingHandlers), {
// FIXME: onStartCall API should use string, not the underlying SDK types.
onStartCall: (participants, options) => {
return callAgent === null || callAgent === void 0 ? void 0 : callAgent.startCall(participants, options);
}, onAddParticipant: (userId, options) => __awaiter(void 0, void 0, void 0, function* () {
const participant = _toCommunicationIdentifier(userId);
if (isPhoneNumberIdentifier(participant)) {
call === null || call === void 0 ? void 0 : call.addParticipant(participant, options);
}
else if (isCommunicationUserIdentifier(participant) || isMicrosoftTeamsUserIdentifier(participant)) {
call === null || call === void 0 ? void 0 : call.addParticipant(participant);
}
}), onRemoveParticipant: (userId) => __awaiter(void 0, void 0, void 0, function* () {
const participant = _toCommunicationIdentifier(userId);
yield (call === null || call === void 0 ? void 0 : call.removeParticipant(participant));
}), onAcceptCall: (incomingCallId, useVideo) => __awaiter(void 0, void 0, void 0, function* () {
const localVideoStream = useVideo ? yield createLocalVideoStream(callClient) : undefined;
const incomingCall = callAgent === null || callAgent === void 0 ? void 0 : callAgent.incomingCalls.find((incomingCall) => incomingCall.id === incomingCallId);
if (incomingCall) {
yield incomingCall.accept(localVideoStream ? {
videoOptions: {
localVideoStreams: [localVideoStream]
}
} : undefined);
}
}), onRejectCall: (incomingCallId) => __awaiter(void 0, void 0, void 0, function* () {
const incomingCall = callAgent === null || callAgent === void 0 ? void 0 : callAgent.incomingCalls.find((incomingCall) => incomingCall.id === incomingCallId);
if (incomingCall) {
yield incomingCall.reject();
}
}) });
});
//# sourceMappingURL=createHandlers.js.map