|
| 1 | +--- |
| 2 | +author: charithgunaratna |
| 3 | +ms.service: azure-communication-services |
| 4 | +ms.topic: include |
| 5 | +ms.date: 02/04/2025 |
| 6 | +ms.author: charithg |
| 7 | +--- |
| 8 | + |
| 9 | +> [!NOTE] |
| 10 | +> This API is provided as a preview for developers and might change based on feedback that we receive. Don't use this API in a production environment. To use this API, use the beta release of the Azure Communication Services Calling Web SDK (1.31.1-beta.1 or higher). |
| 11 | +
|
| 12 | +## Install the SDK |
| 13 | + |
| 14 | +Use the `npm install` command to install the Azure Communication Services Common and Calling SDK for JavaScript: |
| 15 | + |
| 16 | +```console |
| 17 | +npm install @azure/communication-common --save |
| 18 | +npm install @azure/communication-calling --save |
| 19 | +``` |
| 20 | + |
| 21 | +## Initialize required objects |
| 22 | + |
| 23 | +A `CallClient` instance is required for most call operations. When you create a new `CallClient` instance, you can configure it with custom options like a `Logger` instance. |
| 24 | + |
| 25 | +With the `CallClient` instance, you can create a `TeamsCallAgent` instance by calling the `createTeamsCallAgent`. This method asynchronously returns a `TeamsCallAgent` instance object. |
| 26 | + |
| 27 | +The `createTeamsCallAgent` method uses `CommunicationTokenCredential` as an argument. It accepts a [user access token](../../../../quickstarts/identity/access-tokens.md). |
| 28 | + |
| 29 | +You can use the `getDeviceManager` method on the `CallClient` instance to access `deviceManager`. |
| 30 | + |
| 31 | +```js |
| 32 | +const { CallClient } = require('@azure/communication-calling'); |
| 33 | +const { AzureCommunicationTokenCredential} = require('@azure/communication-common'); |
| 34 | +const { AzureLogger, setLogLevel } = require("@azure/logger"); |
| 35 | + |
| 36 | +// Set the logger's log level |
| 37 | +setLogLevel('verbose'); |
| 38 | + |
| 39 | +// Redirect log output to console, file, buffer, REST API, or whatever location you want |
| 40 | +AzureLogger.log = (...args) => { |
| 41 | + console.log(...args); // Redirect log output to console |
| 42 | +}; |
| 43 | + |
| 44 | +const userToken = '<USER_TOKEN>'; |
| 45 | +const callClient = new CallClient(options); |
| 46 | +const tokenCredential = new AzureCommunicationTokenCredential(userToken); |
| 47 | +const callAgent = await callClient.createTeamsCallAgent(tokenCredential, {displayName: 'optional Azure Communication Services user name'}); |
| 48 | +const deviceManager = await callClient.getDeviceManager(); |
| 49 | +await deviceManager.askDevicePermission({ audio: true, video: true }); |
| 50 | +``` |
| 51 | + |
| 52 | +## Place a call on behalf of a Microsoft Teams user |
| 53 | + |
| 54 | +Before placing a call behalf of a delegator, make sure delegate placing the call has `make calls` permission through [delegator call settings in Microsoft Teams](https://support.microsoft.com/office/share-a-phone-line-with-a-delegate-in-microsoft-teams-16307929-a51f-43fc-8323-3b1bf115e5a8) |
| 55 | + |
| 56 | +To place a call on behalf of a Microsoft Teams user, specify `OnBehalfOfOptions` during start call. Replace `xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx` with the userId of the delegator and `yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy` with the userId of the callee. |
| 57 | + |
| 58 | +```js |
| 59 | +const onBehalfOfOptions = { userId: { microsoftTeamsUserId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" } } |
| 60 | +const teamsCallOptions = { onBehalfOfOptions: onBehalfOfOptions }; |
| 61 | +const call = teamsCallAgent.startCall([{ microsoftTeamsUserId: "yyyyyyyy-yyyy-yyyy-yyyy-yyyyyyyyyyyy" }], teamsCallOptions); |
| 62 | +``` |
| 63 | + |
| 64 | +## Receive a call on behalf of a Microsoft Teams user |
| 65 | + |
| 66 | +To receive calls on behalf of a delegator, |
| 67 | + |
| 68 | +- update delegate permission to enable "receive calls" through [delegator call settings in Microsoft Teams](https://support.microsoft.com/office/share-a-phone-line-with-a-delegate-in-microsoft-teams-16307929-a51f-43fc-8323-3b1bf115e5a8) |
| 69 | +- set up simultaneous ring for delegates through [delegator call settings in Microsoft Teams](https://support.microsoft.com/office/call-forwarding-call-groups-and-simultaneous-ring-in-microsoft-teams-a88da9e8-1343-4d3c-9bda-4b9615e4183e) |
0 commit comments