Skip to content

Commit 56af8b8

Browse files
authored
cleaned up
1 parent 105a49a commit 56af8b8

File tree

2 files changed

+36
-69
lines changed

2 files changed

+36
-69
lines changed

articles/communication-services/how-tos/calling-sdk/call-context.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@ It’s important to note that all custom context data remains transparent to the
3131
> [!IMPORTANT]
3232
> To use the ability to pass User-to-User Information (UUI) data using the calling SDK you must use the calling WebJS SDK GA or public preview version `1.29.1` or later.
3333
34-
## Prerequisites
35-
36-
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
37-
- A deployed Communication Services resource. [Create a Communication Services resource](../../quickstarts/create-communication-resource.md).
38-
- A user access token to enable the calling client. For more information, see [Create and manage access tokens](../../quickstarts/identity/access-tokens.md).
39-
- Optional: Complete the quickstart to [add voice calling to your application](../../quickstarts/voice-video-calling/getting-started-with-calling.md)
40-
41-
4234
[!INCLUDE [Passing Contextual Data - Client-side JavaScript](./includes/call-context/call-context-web.md)]
4335

4436
## Next steps

articles/communication-services/how-tos/calling-sdk/includes/call-context/call-context-web.md

Lines changed: 36 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ ms.topic: include
55
ms.date: 09/13/2024
66
ms.author: micahvivion
77
---
8-
[!INCLUDE [Install SDK](../install-sdk/install-sdk-web.md)]
98

109
## Technical parameters
1110
The calling SDK supports adding up to 5 custom SIP headers and 1000 custom VOIP headers. Additionally, developers can include a dedicated User-To-User header as part of SIP headers list.
@@ -18,75 +17,51 @@ The maximum length of a VOIP header key is 64 chars. The maximum length of VOIP
1817

1918
When adding these custom headers as a developer you can choose to add only SIP headers, only VoIP headers or both can be included.
2019

21-
Currently, adding custom User-to-User Information headers is only supported when initiating a 1:1 call. After starting the 1:1 call, you can include additional participants while maintaining the User-to-User Information within the calls.
22-
23-
## Place a call with contextual Information
24-
25-
```js
26-
// Set up customContext
27-
this.callOptions.customContext = {
28-
userToUser: <USER_TO_USER_VALUE>,
29-
xHeaders: [
30-
{ key: <CUSTOM_HEADER_KEY>, value: <CUSTOM_HEADER_VALUE> },
31-
]
32-
};
33-
```
34-
For a "1:1" call to a user, use the following code:
35-
36-
```js
37-
const userId = { communicationUserId: 'ACS_USER_ID' };
38-
this.currentCall = this.callAgent.startCall([userId], this.callOptions);
39-
```
20+
> [!NOTE]
21+
> Currently, adding custom User-to-User Information headers is only supported when initiating a 1:1 call. Passing User-to-User Information headers in group calls is not currently supported. To work around this after starting the 1:1 call, you can include additional participants while maintaining the User-to-User Information within the calls.
4022
41-
To place a call to a public switched telephone network (PSTN), use the `startCall` method on `callAgent` and pass the recipient's `PhoneNumberIdentifier`. Your Communication Services resource must be configured to allow PSTN calling.
4223

43-
When you call a PSTN number, specify your alternate caller ID. An alternate caller ID is a phone number (based on the E.164 standard) that identifies the caller in a PSTN call. It's the phone number the call recipient sees for an incoming call.
24+
## Place a call with User-to-User Information (UUI) data
4425

45-
For a 1:1 call to a PSTN number, use the following code:
4626
```js
47-
const phoneNumber = { phoneNumber: <ACS_PHONE_NUMBER> };
48-
this.callOptions.alternateCallerId = { phoneNumber: <ALTERNATE_CALLER_ID>}
49-
this.currentCall = this.callAgent.startCall([phoneNumber], this.callOptions);
27+
// Setting custom context UUI Headers
28+
const callOptions = {
29+
customContext: {
30+
voipHeaders: [
31+
{key: 'voip-key-1', value: 'voip-value-1'},
32+
{key: 'voip-key-2', value: 'voip-value-2'}
33+
],
34+
35+
sipHeaders: [
36+
{key: 'sip-key-1', value: 'sip-value-1'},
37+
{key: 'sip-key-2', value: 'sip-value-2'}
38+
],
39+
userToUser: 'userToUserHeader',
40+
},
41+
};
42+
});
5043
```
5144

52-
> [!NOTE]
53-
> Passing contextual information in group call and add participant scenarios are not supported
5445

55-
## Receive an incoming call
46+
## Read and parse User-to-User Information headers in a call
5647

5748
The `callAgent` instance emits an `incomingCall` event when the logged-in identity receives an incoming call. To listen to this event and extract contextual info, subscribe by using one of these options:
5849

5950
```js
60-
const incomingCallHandler = async (args: { incomingCall: IncomingCall }) => {
51+
let info = '';
52+
53+
callAgent.on("incomingCall", (args) => {
6154
const incomingCall = args.incomingCall;
62-
63-
// receiving customContext
64-
const customContext = args.incomingCall.customContext;
65-
66-
// Get incoming call ID
67-
var incomingCallId = incomingCall.id
68-
69-
// Get information about this Call. This API is provided as a preview for developers
70-
// and may change based on feedback that we receive. Do not use this API in a production environment.
71-
// To use this api please use 'beta' release of Azure Communication Services Calling Web SDK
72-
var callInfo = incomingCall.info;
73-
74-
// Get information about caller
75-
var callerInfo = incomingCall.callerInfo
76-
77-
// Accept the call
78-
var call = await incomingCall.accept();
79-
80-
// Reject the call
81-
incomingCall.reject();
82-
83-
// Subscribe to callEnded event and get the call end reason
84-
incomingCall.on('callEnded', args => {
85-
console.log(args.callEndReason);
86-
});
87-
88-
// callEndReason is also a property of IncomingCall
89-
var callEndReason = incomingCall.callEndReason;
90-
};
91-
callAgentInstance.on('incomingCall', incomingCallHandler);
92-
```
55+
if (incomingCall.customContext) {
56+
if (incomingCall.customContext.userToUser) {
57+
info += `userToUser: '${incomingCall.customContext.userToUser}'\n`;
58+
}
59+
if (incomingCall.customContext.sipHeaders) {
60+
incomingCall.customContext.sipHeaders.forEach(header => info += `sip: ${header.key}: '${header.value}'\n`);
61+
}
62+
if (incomingCall.customContext.voipHeaders) {
63+
incomingCall.customContext.voipHeaders.forEach(header => info += `voip: ${header.key}: '${header.value}'\n`);
64+
}
65+
}
66+
});
67+
```

0 commit comments

Comments
 (0)