@@ -6,7 +6,6 @@ import { InternalPipelineOptions } from "@azure/core-rest-pipeline";
66import {
77 parseClientArguments ,
88 isKeyCredential ,
9- createCommunicationAuthPolicy ,
109 CommunicationIdentifier ,
1110 CommunicationUserIdentifier ,
1211} from "@azure/communication-common" ;
@@ -39,7 +38,7 @@ import {
3938 PhoneNumberIdentifierModelConverter ,
4039} from "./utli/converters" ;
4140import { v4 as uuidv4 } from "uuid" ;
42- import { createCallAutomationAuthPolicy } from "./credential/callAutomationAuthPolicy" ;
41+ import { createCustomCallAutomationApiClient } from "./credential/callAutomationAuthPolicy" ;
4342import { CallAutomationEventProcessor } from "./eventprocessor/callAutomationEventProcessor" ;
4443import { AnswerCallEventResult , CreateCallEventResult } from "./eventprocessor/eventResponses" ;
4544/**
@@ -69,6 +68,7 @@ export class CallAutomationClient {
6968 private readonly credential : TokenCredential | KeyCredential ;
7069 private readonly internalPipelineOptions : InternalPipelineOptions ;
7170 private readonly callAutomationEventProcessor : CallAutomationEventProcessor ;
71+ private readonly endpoint : string ;
7272 /**
7373 * Initializes a new instance of the CallAutomationClient class.
7474 * @param connectionString - Connection string to connect to an Azure Communication Service resource.
@@ -112,29 +112,19 @@ export class CallAutomationClient {
112112 } ;
113113
114114 const { url, credential } = parseClientArguments ( connectionStringOrUrl , credentialOrOptions ) ;
115+ this . endpoint = url ;
115116
116117 this . credential = credential ;
117118
118119 // create event processor
119120 this . callAutomationEventProcessor = new CallAutomationEventProcessor ( ) ;
120121
121- // read environment variable for callAutomation auth
122- const customEnabled = process . env . COMMUNICATION_CUSTOM_ENDPOINT_ENABLED ;
123- const customUrl = process . env . COMMUNICATION_CUSTOM_URL ;
124-
125- if ( customEnabled ?. toLowerCase ( ) === "true" && customUrl ) {
126- // add custom header for Call Automation auth when flag is true
127- this . callAutomationApiClient = new CallAutomationApiClient (
128- customUrl ,
129- this . internalPipelineOptions
130- ) ;
131- const callAutomationAuthPolicy = createCallAutomationAuthPolicy ( credential , url ) ;
132- this . callAutomationApiClient . pipeline . addPolicy ( callAutomationAuthPolicy ) ;
133- } else {
134- this . callAutomationApiClient = new CallAutomationApiClient ( url , this . internalPipelineOptions ) ;
135- const authPolicy = createCommunicationAuthPolicy ( credential ) ;
136- this . callAutomationApiClient . pipeline . addPolicy ( authPolicy ) ;
137- }
122+ // create api client (using custom api endpoint if available)
123+ this . callAutomationApiClient = createCustomCallAutomationApiClient (
124+ credential ,
125+ this . internalPipelineOptions ,
126+ this . endpoint
127+ ) ;
138128
139129 this . sourceIdentity = communicationUserIdentifierModelConverter ( options . sourceIdentity ) ;
140130 }
@@ -146,7 +136,7 @@ export class CallAutomationClient {
146136 public getCallConnection ( callConnectionId : string ) : CallConnection {
147137 return new CallConnection (
148138 callConnectionId ,
149- this . callAutomationApiClient . endpoint ,
139+ this . endpoint ,
150140 this . credential ,
151141 this . callAutomationEventProcessor ,
152142 this . internalPipelineOptions
@@ -157,11 +147,7 @@ export class CallAutomationClient {
157147 * Initializes a new instance of CallRecording.
158148 */
159149 public getCallRecording ( ) : CallRecording {
160- return new CallRecording (
161- this . callAutomationApiClient . endpoint ,
162- this . credential ,
163- this . internalPipelineOptions
164- ) ;
150+ return new CallRecording ( this . endpoint , this . credential , this . internalPipelineOptions ) ;
165151 }
166152
167153 /**
@@ -205,7 +191,7 @@ export class CallAutomationClient {
205191 } ;
206192 const callConnection = new CallConnection (
207193 callConnectionId ,
208- this . callAutomationApiClient . endpoint ,
194+ this . endpoint ,
209195 this . credential ,
210196 this . callAutomationEventProcessor ,
211197 this . internalPipelineOptions
@@ -339,7 +325,7 @@ export class CallAutomationClient {
339325 } ;
340326 const callConnection = new CallConnection (
341327 callConnectionId ,
342- this . callAutomationApiClient . endpoint ,
328+ this . endpoint ,
343329 this . credential ,
344330 this . callAutomationEventProcessor ,
345331 this . internalPipelineOptions
0 commit comments