@azure/communication-call-automation
Version:
Azure client library for Azure Communication Call Automation services
346 lines (345 loc) • 13.2 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var callConnection_exports = {};
__export(callConnection_exports, {
CallConnection: () => CallConnection
});
module.exports = __toCommonJS(callConnection_exports);
var import_communication_common = require("@azure/communication-common");
var import_callMedia = require("./callMedia.js");
var import_src = require("./generated/src/index.js");
var import_operations = require("./generated/src/operations/index.js");
var import_converters = require("./utli/converters.js");
var import_core_util = require("@azure/core-util");
class CallConnection {
callConnectionId;
callConnection;
callAutomationApiClient;
endpoint;
credential;
callAutomationApiClientOptions;
constructor(callConnectionId, endpoint, credential, options) {
this.callAutomationApiClient = new import_src.CallAutomationApiClient(endpoint, options);
const authPolicy = (0, import_communication_common.createCommunicationAuthPolicy)(credential);
this.callAutomationApiClient.pipeline.addPolicy(authPolicy);
this.callConnectionId = callConnectionId;
this.callConnection = new import_operations.CallConnectionImpl(this.callAutomationApiClient);
this.endpoint = endpoint;
this.credential = credential;
this.callAutomationApiClientOptions = options;
}
/**
* Initializes a new instance of CallMedia.
*/
getCallMedia() {
return new import_callMedia.CallMedia(
this.callConnectionId,
this.endpoint,
this.credential,
this.callAutomationApiClientOptions
);
}
/**
* Get call connection properties of the call
*/
async getCallConnectionProperties(options = {}) {
const { targets, sourceCallerIdNumber, answeredBy, source, answeredFor, ...result } = await this.callConnection.getCall(this.callConnectionId, options);
const callConnectionProperties = {
...result,
source: source ? (0, import_converters.communicationIdentifierConverter)(source) : void 0,
answeredby: (0, import_converters.communicationUserIdentifierConverter)(answeredBy),
answeredFor: answeredFor ? (0, import_converters.phoneNumberIdentifierConverter)(answeredFor) : void 0,
targetParticipants: targets?.map((target) => (0, import_converters.communicationIdentifierConverter)(target)),
sourceCallerIdNumber: sourceCallerIdNumber ? (0, import_converters.phoneNumberIdentifierConverter)(sourceCallerIdNumber) : void 0
};
return callConnectionProperties;
}
/**
* Hang up the call for itself or terminate the whole call.
*
* @param isForEveryOne - Determine if every one in the call would be hung up or not.
*/
async hangUp(isForEveryone, options = {}) {
if (isForEveryone) {
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
await this.callConnection.terminateCall(this.callConnectionId, optionsInternal);
} else {
await this.callConnection.hangupCall(this.callConnectionId, options);
}
return;
}
/**
* Get a participant from the call
*
* @param targetParticipant - The communication identifier of requested participant.
*/
async getParticipant(targetParticipant, options = {}) {
let rawId = (0, import_converters.communicationIdentifierModelConverter)(targetParticipant).rawId;
rawId = rawId === void 0 ? "" : rawId;
const result = await this.callConnection.getParticipant(this.callConnectionId, rawId, options);
const callParticipant = {
identifier: result.identifier ? (0, import_converters.communicationIdentifierConverter)(result.identifier) : void 0,
isMuted: result.isMuted,
isOnHold: result.isOnHold
};
return callParticipant;
}
/**
* Get all participants from the call
*/
async listParticipants(options = {}) {
const result = this.callConnection.listParticipants(this.callConnectionId, options);
const participants = [];
const pages = result?.byPage();
for await (const page of pages) {
for (const participant of page) {
participants.push((0, import_converters.callParticipantConverter)(participant));
}
}
const listParticipantResponse = {
...result,
values: participants
};
return listParticipantResponse;
}
createCustomCallingContextInternal(customCallingContext) {
const sipHeaders = {};
const voipHeaders = {};
let teamsPhoneCallDetails = void 0;
if (customCallingContext) {
for (const header of customCallingContext) {
if (header.kind === "sipuui") {
sipHeaders[`User-To-User`] = header.value;
} else if (header.kind === "sipx") {
if (header.sipHeaderPrefix === "X-") {
sipHeaders[`X-${header.key}`] = header.value;
} else {
sipHeaders[`X-MS-Custom-${header.key}`] = header.value;
}
} else if (header.kind === "voip") {
voipHeaders[`${header.key}`] = header.value;
} else if (header.kind === "TeamsPhoneCallDetails") {
teamsPhoneCallDetails = (0, import_converters.teamsPhoneCallDetailsModelConverter)(header);
}
}
}
return {
sipHeaders,
voipHeaders,
teamsPhoneCallDetails
};
}
/**
* Add a participant to the call
*
* @param participant - The participant is going to be added.
*/
async addParticipant(targetParticipant, options = {}) {
const addParticipantRequest = {
participantToAdd: (0, import_converters.communicationIdentifierModelConverter)(targetParticipant.targetParticipant),
sourceCallerIdNumber: (0, import_converters.PhoneNumberIdentifierModelConverter)(
targetParticipant.sourceCallIdNumber
),
sourceDisplayName: targetParticipant.sourceDisplayName,
invitationTimeoutInSeconds: options.invitationTimeoutInSeconds,
operationContext: options.operationContext,
operationCallbackUri: options.operationCallbackUrl,
customCallingContext: this.createCustomCallingContextInternal(
targetParticipant.customCallingContext
)
};
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.addParticipant(
this.callConnectionId,
addParticipantRequest,
optionsInternal
);
const addParticipantsResult = {
...result,
participant: {
...result.participant,
identifier: result.participant?.identifier ? (0, import_converters.communicationIdentifierConverter)(result.participant?.identifier) : void 0
}
};
return addParticipantsResult;
}
/**
* Transfer the call to a target participant
*
* @param targetParticipant - The target to be transferred to.
*/
async transferCallToParticipant(targetParticipant, options = {}) {
const transferToParticipantRequest = {
targetParticipant: (0, import_converters.communicationIdentifierModelConverter)(targetParticipant),
operationContext: options.operationContext ? options.operationContext : (0, import_core_util.randomUUID)(),
operationCallbackUri: options.operationCallbackUrl,
transferee: options.transferee && (0, import_converters.communicationIdentifierModelConverter)(options.transferee),
customCallingContext: this.createCustomCallingContextInternal(options.customCallingContext),
sourceCallerIdNumber: (0, import_converters.PhoneNumberIdentifierModelConverter)(options.sourceCallIdNumber)
};
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.transferToParticipant(
this.callConnectionId,
transferToParticipantRequest,
optionsInternal
);
const transferCallResult = {
...result
};
return transferCallResult;
}
/**
* Remove a participant from the call
*
* @param participant - The participant is going to be removed from the call.
*/
async removeParticipant(participant, options = {}) {
const removeParticipantRequest = {
participantToRemove: (0, import_converters.communicationIdentifierModelConverter)(participant),
operationContext: options.operationContext ? options.operationContext : (0, import_core_util.randomUUID)(),
operationCallbackUri: options.operationCallbackUrl
};
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.removeParticipant(
this.callConnectionId,
removeParticipantRequest,
optionsInternal
);
const removeParticipantsResult = {
...result
};
return removeParticipantsResult;
}
/**
* Mute participant from the call.
*
* @param participant - Participant to be muted from the call.
* @param options - Additional attributes for mute participant.
*/
async muteParticipant(participant, options = {}) {
const muteParticipantsRequest = {
targetParticipants: [(0, import_converters.communicationIdentifierModelConverter)(participant)],
operationContext: options.operationContext
};
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.mute(
this.callConnectionId,
muteParticipantsRequest,
optionsInternal
);
const muteParticipantResult = {
...result
};
return muteParticipantResult;
}
/** Cancel add participant request.
*
* @param invitationId - Invitation ID used to cancel the add participant request.
*/
async cancelAddParticipantOperation(invitationId, options = {}) {
const {
operationContext,
operationCallbackUrl: operationCallbackUri,
...operationOptions
} = options;
const cancelAddParticipantRequest = {
invitationId,
operationContext: operationContext ? operationContext : (0, import_core_util.randomUUID)(),
operationCallbackUri
};
const optionsInternal = {
...operationOptions,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.cancelAddParticipant(
this.callConnectionId,
cancelAddParticipantRequest,
optionsInternal
);
const cancelAddParticipantResult = {
...result
};
return cancelAddParticipantResult;
}
/**
* Move participants to the call.
*
* @param targetParticipants - The participants to move to the call.
* @param fromCall - The CallConnectionId for the call you want to move the participant from.
* @param options - Additional options for moving participants.
*/
async moveParticipants(targetParticipants, fromCall, options = {}) {
const {
operationContext,
operationCallbackUrl: operationCallbackUri,
...operationOptions
} = options;
const moveParticipantsRequest = {
targetParticipants: targetParticipants.map(
(participant) => (0, import_converters.communicationIdentifierModelConverter)(participant)
),
fromCall,
operationContext: operationContext ? operationContext : (0, import_core_util.randomUUID)(),
operationCallbackUri
};
const optionsInternal = {
...operationOptions,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const result = await this.callConnection.moveParticipants(
this.callConnectionId,
moveParticipantsRequest,
optionsInternal
);
const moveParticipantsResult = {
...result,
participants: result.participants?.map(
(participant) => (0, import_converters.callParticipantConverter)(participant)
),
fromCall
};
return moveParticipantsResult;
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CallConnection
});
//# sourceMappingURL=callConnection.js.map