@azure/communication-call-automation
Version:
Azure client library for Azure Communication Call Automation services
225 lines (224 loc) • 9.64 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var callRecording_exports = {};
__export(callRecording_exports, {
CallRecording: () => CallRecording
});
module.exports = __toCommonJS(callRecording_exports);
var import_operations = require("./generated/src/operations/index.js");
var import_converters = require("./utli/converters.js");
var import_contentDownloader = require("./contentDownloader.js");
var import_node_fs = __toESM(require("node:fs"));
var import_core_util = require("@azure/core-util");
var import_src = require("./generated/src/index.js");
var import_communication_common = require("@azure/communication-common");
class CallRecording {
callRecordingImpl;
contentDownloader;
callAutomationApiClient;
constructor(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.callRecordingImpl = new import_operations.CallRecordingImpl(this.callAutomationApiClient);
this.contentDownloader = new import_contentDownloader.ContentDownloaderImpl(this.callAutomationApiClient);
}
/**
* Starts a call recording with the specified options.
* @param startCallRecordingRequest - options to start the call recording
* @param options - Operation options.
*/
async start(options) {
const startCallRecordingRequest = {
callLocator: options.callLocator ? options.callLocator : void 0
};
startCallRecordingRequest.recordingChannelType = options.recordingChannel;
startCallRecordingRequest.recordingContentType = options.recordingContent;
startCallRecordingRequest.recordingFormatType = options.recordingFormat;
startCallRecordingRequest.recordingStateCallbackUri = options.recordingStateCallbackEndpointUrl;
startCallRecordingRequest.pauseOnStart = options.pauseOnStart;
startCallRecordingRequest.recordingStorage = options.recordingStorage;
startCallRecordingRequest.callConnectionId = options.callConnectionId ? options.callConnectionId : void 0;
if (options.channelAffinity) {
startCallRecordingRequest.channelAffinity = [];
options.channelAffinity.forEach((identifier) => {
startCallRecordingRequest.channelAffinity?.push({
participant: (0, import_converters.communicationIdentifierModelConverter)(identifier.targetParticipant),
channel: identifier.channel
});
});
}
if (options.audioChannelParticipantOrdering) {
startCallRecordingRequest.audioChannelParticipantOrdering = [];
options.audioChannelParticipantOrdering.forEach((identifier) => {
startCallRecordingRequest.audioChannelParticipantOrdering?.push(
(0, import_converters.communicationIdentifierModelConverter)(identifier)
);
});
}
if (options.callLocator) {
if (options.callLocator.kind === "groupCallLocator") {
startCallRecordingRequest.callLocator = {
groupCallId: options.callLocator.id,
kind: "groupCallLocator"
};
} else if (options.callLocator.kind === "roomCallLocator") {
startCallRecordingRequest.callLocator = {
roomId: options.callLocator.id,
kind: "roomCallLocator"
};
} else {
startCallRecordingRequest.callLocator = {
serverCallId: options.callLocator.id,
kind: "serverCallLocator"
};
}
}
const optionsInternal = {
...options,
repeatabilityFirstSent: /* @__PURE__ */ new Date(),
repeatabilityRequestID: (0, import_core_util.randomUUID)()
};
const response = await this.callRecordingImpl.startRecording(
startCallRecordingRequest,
optionsInternal
);
const result = {
recordingId: response.recordingId,
recordingKind: response.recordingKind,
recordingState: response.recordingState
};
return result;
}
/**
* Returns call recording properties.
* @param recordingId - The recordingId associated with the recording.
* @param options - Additional request options contains getRecordingProperties api options.
*/
async getState(recordingId, options = {}) {
const response = await this.callRecordingImpl.getRecordingProperties(recordingId, options);
const result = {
recordingId: response.recordingId,
recordingKind: response.recordingKind,
recordingState: response.recordingState
};
return result;
}
/**
* Stops a call recording.
* @param recordingId - The recordingId associated with the recording.
* @param options - Additional request options contains stopRecording api options.
*/
async stop(recordingId, options = {}) {
return this.callRecordingImpl.stopRecording(recordingId, options);
}
/**
* Pauses a call recording.
* @param recordingId - The recordingId associated with the recording.
* @param options - Additional request options contains pauseRecording api options.
*/
async pause(recordingId, options = {}) {
return this.callRecordingImpl.pauseRecording(recordingId, options);
}
/**
* Resumes a call recording.
* @param recordingId - The recordingId associated with the recording.
* @param options - Additional request options contains resumeRecording api options.
*/
async resume(recordingId, options = {}) {
return this.callRecordingImpl.resumeRecording(recordingId, options);
}
/**
* Deletes a recording.
* @param recordingLocationUrl - The recording location url. Required.
* @param options - Additional request options contains deleteRecording api options.
*/
async delete(recordingLocationUrl, options = {}) {
await this.contentDownloader.deleteRecording(recordingLocationUrl, options);
}
/**
* Returns a stream with a call recording.
* @param sourceLocationUrl - The source location url. Required.
* @param options - Additional request options contains downloadRecording api options.
*/
async downloadStreaming(sourceLocationUrl, options = {}) {
const result = this.contentDownloader.download(sourceLocationUrl, options);
const recordingStream = (await result).readableStreamBody;
if (recordingStream) {
return recordingStream;
} else {
throw Error("failed to get stream");
}
}
/**
* Downloads a call recording file to the specified stream.
* @param sourceLocationUrl - The source location url. Required.
* @param destinationStream - The destination stream. Required.
* @param options - Additional request options contains downloadRecording api options.
*/
async downloadToStream(sourceLocationUrl, destinationStream, options = {}) {
const result = this.contentDownloader.download(sourceLocationUrl, options);
const recordingStream = (await result).readableStreamBody;
if (recordingStream) {
recordingStream.pipe(destinationStream);
const finish = new Promise((resolve, reject) => {
destinationStream.on("finish", resolve);
destinationStream.on("error", reject);
});
await finish;
} else {
throw Error("failed to get stream");
}
}
/**
* Downloads a call recording file to the specified path.
* @param sourceLocationUrl - The source location url. Required.
* @param destinationPath - The destination path. Required.
* @param options - Additional request options contains downloadRecording api options.
*/
async downloadToPath(sourceLocationUrl, destinationPath, options = {}) {
const result = this.contentDownloader.download(sourceLocationUrl, options);
const recordingStream = (await result).readableStreamBody;
if (recordingStream) {
const writeFileStream = import_node_fs.default.createWriteStream(destinationPath);
recordingStream.pipe(writeFileStream);
const finish = new Promise((resolve, reject) => {
writeFileStream.on("finish", resolve);
writeFileStream.on("error", reject);
});
await finish;
} else {
throw Error("failed to get stream");
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
CallRecording
});
//# sourceMappingURL=callRecording.js.map