Skip to content

Commit a491d92

Browse files
azure board review comments (Azure#25642)
### Packages impacted by this PR Communication-call-automation ### Describe the problem that is addressed by this PR feedback from azure board review General - callInvite is now an interface instead of a class - rename target/s to targetParticipant/s - append EventData to events - event parser parse is now a function instead of a class - update uri to url CallMediaUpdates - move all required params in options to method signature CallConnectionUpdates - rename callConnectionImpl to callConnection - getParticipant takes a CommunicationIdentifier instead of a participantMri string. CallRecordingUpdates - remove "recording from method names" ex startRecording is now start. --------- Co-authored-by: Juntu Chen <95723208+juntuchen-msft@users.noreply.github.com>
1 parent 81997b7 commit a491d92

19 files changed

+916
-616
lines changed

sdk/communication/communication-call-automation/review/communication-call-automation.api.md

Lines changed: 56 additions & 86 deletions
Large diffs are not rendered by default.

sdk/communication/communication-call-automation/samples-dev/createCallOperations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export async function main() {
2525
const callAutomationClient = new CallAutomationClient(connectionString);
2626

2727
// create invitation
28-
const callInvite = new CallInvite(user);
28+
const callInvite: CallInvite = { targetParticipant: user };
2929

3030
// Create Call
3131
console.log("Creating call...");

sdk/communication/communication-call-automation/src/callAutomationClient.ts

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import {
2020
RedirectCallRequest,
2121
RejectCallRequest,
2222
} from "./generated/src";
23-
import { CallConnectionImpl, CallMediaImpl, CallRecordingImpl } from "./generated/src/operations";
2423
import { CallConnection } from "./callConnection";
2524
import { CallRecording } from "./callRecording";
2625
import {
@@ -37,7 +36,6 @@ import {
3736
phoneNumberIdentifierConverter,
3837
PhoneNumberIdentifierModelConverter,
3938
} from "./utli/converters";
40-
import { ContentDownloaderImpl } from "./contentDownloader";
4139
import { v4 as uuidv4 } from "uuid";
4240

4341
/**
@@ -63,12 +61,9 @@ const isCallAutomationClientOptions = (options: any): options is CallAutomationC
6361
*/
6462
export class CallAutomationClient {
6563
private readonly callAutomationApiClient: CallAutomationApiClient;
66-
private readonly callConnectionImpl: CallConnectionImpl;
67-
private readonly callRecordingImpl: CallRecordingImpl;
68-
private readonly contentDownloaderImpl: ContentDownloaderImpl;
69-
private readonly callMediaImpl: CallMediaImpl;
7064
private readonly sourceIdentity?: CommunicationIdentifierModel;
71-
65+
private readonly credential: TokenCredential | KeyCredential;
66+
private readonly internalPipelineOptions: InternalPipelineOptions;
7267
/**
7368
* Initializes a new instance of the CallAutomationClient class.
7469
* @param connectionString - Connection string to connect to an Azure Communication Service resource.
@@ -78,20 +73,16 @@ export class CallAutomationClient {
7873
constructor(connectionString: string, options?: CallAutomationClientOptions);
7974

8075
/**
81-
* Initializes a new instance of the CallAutomationClient class using an Azure KeyCredential.
82-
* @param endpoint - The endpoint of the service (ex: https://contoso.eastus.communications.azure.net).
83-
* @param credential - An object that is used to authenticate requests to the service. Use the Azure KeyCredential or `@azure/identity` to create a credential.
84-
* @param options - Optional. Options to configure the HTTP pipeline.
85-
*/
86-
constructor(endpoint: string, credential: KeyCredential, options?: CallAutomationClientOptions);
87-
88-
/**
89-
* Initializes a new instance of the CallAutomationClient class using a TokenCredential.
76+
* Initializes a new instance of the CallAutomationClient class using a TokenCredential or KeyCredential.
9077
* @param endpoint - The endpoint of the service (ex: https://contoso.eastus.communications.azure.net).
91-
* @param credential - TokenCredential that is used to authenticate requests to the service.
78+
* @param credential - TokenCredential or KeyCredential that is used to authenticate requests to the service.
9279
* @param options - Optional. Options to configure the HTTP pipeline.
9380
*/
94-
constructor(endpoint: string, credential: TokenCredential, options?: CallAutomationClientOptions);
81+
constructor(
82+
endpoint: string,
83+
credential: TokenCredential | KeyCredential,
84+
options?: CallAutomationClientOptions
85+
);
9586

9687
constructor(
9788
connectionStringOrUrl: string,
@@ -113,7 +104,7 @@ export class CallAutomationClient {
113104
options.userAgentOptions.userAgentPrefix = libInfo;
114105
}
115106

116-
const internalPipelineOptions: InternalPipelineOptions = {
107+
this.internalPipelineOptions = {
117108
...options,
118109
...{
119110
loggingOptions: {
@@ -125,12 +116,9 @@ export class CallAutomationClient {
125116
const { url, credential } = parseClientArguments(connectionStringOrUrl, credentialOrOptions);
126117
const authPolicy = createCommunicationAuthPolicy(credential);
127118

128-
this.callAutomationApiClient = new CallAutomationApiClient(url, internalPipelineOptions);
119+
this.credential = credential;
120+
this.callAutomationApiClient = new CallAutomationApiClient(url, this.internalPipelineOptions);
129121
this.callAutomationApiClient.pipeline.addPolicy(authPolicy);
130-
this.callConnectionImpl = new CallConnectionImpl(this.callAutomationApiClient);
131-
this.callMediaImpl = new CallMediaImpl(this.callAutomationApiClient);
132-
this.callRecordingImpl = new CallRecordingImpl(this.callAutomationApiClient);
133-
this.contentDownloaderImpl = new ContentDownloaderImpl(this.callAutomationApiClient);
134122
this.sourceIdentity = options.sourceIdentity
135123
? communicationIdentifierModelConverter(options.sourceIdentity)
136124
: undefined;
@@ -141,14 +129,23 @@ export class CallAutomationClient {
141129
* @param callConnectionId - The CallConnection id for the CallConnection instance. (ex: 421CONTOSO-cRD6-4RDc-a078-99dRANDOMf).
142130
*/
143131
public getCallConnection(callConnectionId: string): CallConnection {
144-
return new CallConnection(callConnectionId, this.callConnectionImpl, this.callMediaImpl);
132+
return new CallConnection(
133+
callConnectionId,
134+
this.callAutomationApiClient.endpoint,
135+
this.credential,
136+
this.internalPipelineOptions
137+
);
145138
}
146139

147140
/**
148141
* Initializes a new instance of CallRecording.
149142
*/
150143
public getCallRecording(): CallRecording {
151-
return new CallRecording(this.callRecordingImpl, this.contentDownloaderImpl);
144+
return new CallRecording(
145+
this.callAutomationApiClient.endpoint,
146+
this.credential,
147+
this.internalPipelineOptions
148+
);
152149
}
153150

154151
/**
@@ -177,7 +174,7 @@ export class CallAutomationClient {
177174
sourceIdentity: result.sourceIdentity
178175
? communicationIdentifierConverter(result.sourceIdentity)
179176
: undefined,
180-
targets: result.targets?.map((returnedTarget) =>
177+
targetParticipants: result.targets?.map((returnedTarget) =>
181178
communicationIdentifierConverter(returnedTarget)
182179
),
183180
sourceCallerIdNumber: result.sourceCallerIdNumber
@@ -186,8 +183,9 @@ export class CallAutomationClient {
186183
};
187184
const callConnection = new CallConnection(
188185
result.callConnectionId,
189-
this.callConnectionImpl,
190-
this.callMediaImpl
186+
this.callAutomationApiClient.endpoint,
187+
this.credential,
188+
this.internalPipelineOptions
191189
);
192190
const createCallResult: CreateCallResult = {
193191
callConnectionProperties: callConnectionPropertiesDto,
@@ -200,47 +198,49 @@ export class CallAutomationClient {
200198

201199
/**
202200
* Create an outgoing call from source to a target identity.
203-
* @param target - A single target.
201+
* @param targetParticipant - A single target.
204202
* @param callbackUrl - The callback url.
205203
* @param options - Additional request options contains createCallConnection api options.
206204
*/
207205
public async createCall(
208-
target: CallInvite,
206+
targetParticipant: CallInvite,
209207
callbackUrl: string,
210208
options: CreateCallOptions = {}
211209
): Promise<CreateCallResult> {
212210
const request: CreateCallRequest = {
213211
sourceIdentity: this.sourceIdentity,
214-
targets: [communicationIdentifierModelConverter(target.target)],
212+
targets: [communicationIdentifierModelConverter(targetParticipant.targetParticipant)],
215213
callbackUri: callbackUrl,
216214
operationContext: options.operationContext,
217215
azureCognitiveServicesEndpointUrl: options.azureCognitiveServicesEndpointUrl,
218216
mediaStreamingConfiguration: options.mediaStreamingConfiguration,
219217
customContext: {
220-
sipHeaders: target.sipHeaders,
221-
voipHeaders: target.voipHeaders,
218+
sipHeaders: targetParticipant.sipHeaders,
219+
voipHeaders: targetParticipant.voipHeaders,
222220
},
223-
sourceCallerIdNumber: PhoneNumberIdentifierModelConverter(target.sourceCallIdNumber),
224-
sourceDisplayName: target.sourceDisplayName,
221+
sourceCallerIdNumber: PhoneNumberIdentifierModelConverter(
222+
targetParticipant.sourceCallIdNumber
223+
),
224+
sourceDisplayName: targetParticipant.sourceDisplayName,
225225
};
226226

227227
return this.createCallInternal(request, options);
228228
}
229229

230230
/**
231231
* Create an outgoing call from source to a group of targets identities.
232-
* @param targets - A group of targets identities.
232+
* @param targetParticipants - A group of targets identities.
233233
* @param callbackUrl - The callback url.
234234
* @param options - Additional request options contains createCallConnection api options.
235235
*/
236236
public async createGroupCall(
237-
targets: CommunicationIdentifier[],
237+
targetParticipants: CommunicationIdentifier[],
238238
callbackUrl: string,
239239
options: CreateCallOptions = {}
240240
): Promise<CreateCallResult> {
241241
const request: CreateCallRequest = {
242242
sourceIdentity: this.sourceIdentity,
243-
targets: targets.map((target) => communicationIdentifierModelConverter(target)),
243+
targets: targetParticipants.map((target) => communicationIdentifierModelConverter(target)),
244244
callbackUri: callbackUrl,
245245
operationContext: options.operationContext,
246246
azureCognitiveServicesEndpointUrl: options.azureCognitiveServicesEndpointUrl,
@@ -286,15 +286,18 @@ export class CallAutomationClient {
286286
sourceIdentity: result.sourceIdentity
287287
? communicationIdentifierConverter(result.sourceIdentity)
288288
: undefined,
289-
targets: result.targets?.map((target) => communicationIdentifierConverter(target)),
289+
targetParticipants: result.targets?.map((target) =>
290+
communicationIdentifierConverter(target)
291+
),
290292
sourceCallerIdNumber: result.sourceCallerIdNumber
291293
? phoneNumberIdentifierConverter(result.sourceCallerIdNumber)
292294
: undefined,
293295
};
294296
const callConnection = new CallConnection(
295297
result.callConnectionId,
296-
this.callConnectionImpl,
297-
this.callMediaImpl
298+
this.callAutomationApiClient.endpoint,
299+
this.credential,
300+
this.internalPipelineOptions
298301
);
299302
const answerCallResult: AnswerCallResult = {
300303
callConnectionProperties: callConnectionProperties,
@@ -309,22 +312,20 @@ export class CallAutomationClient {
309312
* Redirect the call.
310313
*
311314
* @param incomingCallContext - The context associated with the call.
312-
* @param target - The target identity to redirect the call to.
315+
* @param targetParticipant - The target identity to redirect the call to.
313316
* @param options - Additional request options contains redirectCall api options.
314317
*/
315318
public async redirectCall(
316319
incomingCallContext: string,
317-
target: CallInvite,
320+
targetParticipant: CallInvite,
318321
options: RedirectCallOptions = {}
319322
): Promise<void> {
320323
const request: RedirectCallRequest = {
321324
incomingCallContext: incomingCallContext,
322-
target: communicationIdentifierModelConverter(target.target),
325+
target: communicationIdentifierModelConverter(targetParticipant.targetParticipant),
323326
customContext: {
324-
sipHeaders:
325-
target instanceof CallInvite ? target.sipHeaders : options.sipHeaders ?? undefined,
326-
voipHeaders:
327-
target instanceof CallInvite ? target.voipHeaders : options.voipHeaders ?? undefined,
327+
sipHeaders: targetParticipant.sipHeaders ?? options.sipHeaders ?? undefined,
328+
voipHeaders: targetParticipant.voipHeaders ?? options.voipHeaders ?? undefined,
328329
},
329330
};
330331
const optionsInternal = {

0 commit comments

Comments
 (0)