Skip to content

Commit 46801f5

Browse files
committed
Resolved PR Comments
1 parent fd4165d commit 46801f5

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

callautomation-connect-rooms-quickstart/.env

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ PORT=8080
22
CONNECTION_STRING="<YOUR_CONNECTION_STRING>"
33
ACS_RESOURCE_PHONE_NUMBER ="<YOUR_ACS_NUMBER>"
44
TARGET_PHONE_NUMBER="<+1XXXXXXXXXX>"
5-
CALLBACK_URI="<VS_TUNNEL_URL>"
5+
CALLBACK_URI="<VS_TUNNEL_URL>"
6+
COGNITIVE_SERVICES_ENDPOINT="<COGNITIVE_SERVICES_ENDPOINT>"

callautomation-connect-rooms-quickstart/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Open the `.env` file to configure the following settings
5050
2. `ACS_RESOURCE_PHONE_NUMBER`: Phone number associated with the Azure Communication Service resource. For e.g. "+1425XXXAAAA"
5151
3. `TARGET_PHONE_NUMBER`: Target phone number to add in the call. For e.g. "+1425XXXAAAA"
5252
4. `CALLBACK_URI`: Base url of the app. (For local development replace the dev tunnel url)
53+
5. `COGNITIVE_SERVICES_ENDPOINT` : Cognitive service endpoint.
5354

5455
### Run app locally
5556

callautomation-connect-rooms-quickstart/src/app.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
ConnectCallOptions,
88
CallLocator,
99
CallInvite,
10-
AddParticipantOptions
10+
AddParticipantOptions,
11+
TextSource
1112
} from "@azure/communication-call-automation";
1213
import { CommunicationIdentityClient, CommunicationUserToken } from '@azure/communication-identity';
1314
import { 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
122129
app.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
178199
app.listen(PORT, async () => {
179200
console.log(`Server is listening on port ${PORT}`);

callautomation-connect-rooms-quickstart/src/webpage/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ <h2>Connect Rooms Call Quickstart</h2>
1313
<div>
1414
<input type="submit" formaction="/connectCall" value="Connect call!">
1515
<input type="submit" formaction="/addParticipant" value="Add participant!">
16+
<input type="submit" formaction="/playMedia" value="Play media!">
1617
<input type="submit" formaction="/hangup" value="Hangup call!">
1718
</div>
1819

0 commit comments

Comments
 (0)