77 ConnectCallOptions ,
88 CallLocator ,
99 CallInvite ,
10- AddParticipantOptions
10+ AddParticipantOptions ,
11+ TextSource
1112} from "@azure/communication-call-automation" ;
1213import { CommunicationIdentityClient , CommunicationUserToken } from '@azure/communication-identity' ;
1314import { CreateRoomOptions , RoomsClient } from '@azure/communication-rooms' ;
@@ -109,6 +110,7 @@ async function connectCall() {
109110 console . log ( `Callback Url:-->${ callBackUri } ` )
110111 const response = await acsClient . connectCall ( callLocator , callBackUri , connectCallOptions )
111112 console . log ( "connecting call please wait...." )
113+ console . log ( `Connect request correlation Id:--> ${ response . callConnectionProperties . correlationId } ` )
112114 } else {
113115 console . log ( "Room id is empty or room is not available." )
114116 }
@@ -118,6 +120,11 @@ async function hangUpCall() {
118120 await callConnection . hangUp ( true ) ;
119121}
120122
123+ async function playMedia ( ) {
124+ const play : TextSource = { text : "Hello, welcome to connect room contoso app." , voiceName : "en-US-NancyNeural" , kind : "textSource" }
125+ await callConnection . getCallMedia ( ) . playToAll ( [ play ] ) ;
126+ }
127+
121128// POST endpoint to handle ongoing call events
122129app . post ( "/api/callbacks" , async ( req : any , res : any ) => {
123130 const event = req . body [ 0 ] ;
@@ -139,6 +146,14 @@ app.post("/api/callbacks", async (req: any, res: any) => {
139146 console . log ( `Code:->${ eventData . resultInformation . code } , Subcode:->${ eventData . resultInformation . subCode } ` )
140147 console . log ( `Message:->${ eventData . resultInformation . message } ` ) ;
141148 }
149+ else if ( event . type === "Microsoft.Communication.PlayCompleted" ) {
150+ console . log ( "Received PlayCompleted event" ) ;
151+ }
152+ else if ( event . type === "Microsoft.Communication.playFailed" ) {
153+ console . log ( "Received playFailed event" ) ;
154+ console . log ( `Code:->${ eventData . resultInformation . code } , Subcode:->${ eventData . resultInformation . subCode } ` )
155+ console . log ( `Message:->${ eventData . resultInformation . message } ` ) ;
156+ }
142157 else if ( event . type === "Microsoft.Communication.CallDisconnected" ) {
143158 console . log ( "Received CallDisconnected event" ) ;
144159 console . log ( `Correlation id:-> ${ eventData . correlationId } ` )
@@ -174,6 +189,12 @@ app.get('/hangup', async (req, res) => {
174189 res . redirect ( '/' ) ;
175190} ) ;
176191
192+ // GET endpoint to play media to call.
193+ app . get ( '/playMedia' , async ( req , res ) => {
194+ await playMedia ( ) ;
195+ res . redirect ( '/' ) ;
196+ } ) ;
197+
177198// Start the server
178199app . listen ( PORT , async ( ) => {
179200 console . log ( `Server is listening on port ${ PORT } ` ) ;
0 commit comments