|
| 1 | +--- |
| 2 | +author: probableprime |
| 3 | +ms.service: azure-communication-services |
| 4 | +ms.topic: include |
| 5 | +ms.date: 10/03/2025 |
| 6 | +ms.author: dmceachern |
| 7 | +--- |
| 8 | + |
| 9 | +[!INCLUDE [Install SDK](../install-sdk/install-sdk-web.md)] |
| 10 | + |
| 11 | +## Active Call Management |
| 12 | +Active Call Transfer is a feature of the core `CallAgent` API. This guide talks about how you can manage and track any ongoing calls for your users and how to transfer their client to that active call. |
| 13 | + |
| 14 | +**Note:** This feature is also enabled for the `TeamsCallAgent` as this feature is supported for Teams users as well. |
| 15 | + |
| 16 | +This guide assumes you went through the QuickStart or that you implemented an application that is able to make and receive calls. If you didn't complete the getting starting guide, refer to our [Quickstart](../../../../quickstarts/voice-video-calling/getting-started-with-calling.md). |
| 17 | + |
| 18 | +### Fetch your Active Call |
| 19 | + |
| 20 | +When your user signs to the `CallAgent` there is a new method that you can use to fetch the ongoing calls `getActiveCallDetails` the response will return to you the active call, or active meeting that your users are in. |
| 21 | + |
| 22 | +```js |
| 23 | +const activeCallDetails = await callAgent.getActiveCallDetails(); |
| 24 | +``` |
| 25 | + |
| 26 | +The function `getActiveCallDetails` a way that you can manually query for this data. Once you have the active call details, you can use it to switch the client to the call that was found. This function returns `undefined` if there is no active call ongoing for your user. You can use `getActiveCallDetails` to fetch any ongoing calls when you first sign into the `CallAgent` to pick up on any calls that are already ongoing. |
| 27 | + |
| 28 | +### Switch your Active Call |
| 29 | + |
| 30 | +Once you have your active call data, you can switch the client over to the new call. This call switching behavior can be done with the `activeCallTransfer` function. |
| 31 | + |
| 32 | +```js |
| 33 | +const activeCallDetails = await callAgent.getActiveCallDetails(); |
| 34 | +const call = await callAgent.activeCallTransfer(activeCallDetails, {isTransfer: true}); |
| 35 | +``` |
| 36 | + |
| 37 | +This function returns the call object for your applications state. |
| 38 | + |
| 39 | +### Companion mode |
| 40 | + |
| 41 | +When transferring the active call to your client, you can just bring the client into the call without hanging up on the device that initiated the call the user is in. |
| 42 | + |
| 43 | +```js |
| 44 | +const activeCallDetails = await callAgent.getActiveCallDetails(); |
| 45 | +const call = await callAgent.activeCallTransfer(activeCallDetails, {isTransfer: false}); // <-- isTransfer: false - does not remove the original client. |
| 46 | +``` |
| 47 | + |
| 48 | +### Subscribe to Active Call Notification events |
| 49 | + |
| 50 | +There are two new events that you can subscribe to so you can receive events notifying you of your user joining a call on another client. The first event notifies the application that the user is in a call on another device. This event is also emitted when the user logs into the `CallAgent` if they are on a call already elsewhere. |
| 51 | + |
| 52 | +```js |
| 53 | +callAgent.on("activeCallsUpdated", (args) => { |
| 54 | + // show UI indicating that the user is in another call on another device |
| 55 | + await callAgent.activeCallTransfer(args.activeCallDetails, {isTransfer: true}); |
| 56 | +}); |
| 57 | +``` |
| 58 | +The second event notifies the application that the user is no longer in an active call anywhere else. This event is to be used to hide any UI indicating that they are in a call elsewhere, and any controls to manually transfer the call over. |
| 59 | + |
| 60 | +```js |
| 61 | +callAgent.on("NoActiveCalls", () => { |
| 62 | + // hide UI indicating that the user is in a call elsewhere |
| 63 | +}); |
| 64 | +``` |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | + |
0 commit comments