This article describes how to implement reactions for Azure Communication Services Calling SDKs. This capability enables participants in a group call or meeting to send and receive reactions with participants in Azure Communication Services and Microsoft Teams.
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.
With the CallClient instance, you can create a CallAgent instance by calling the createCallAgent. This method asynchronously returns a CallAgent instance object.
The createCallAgent method uses CommunicationTokenCredential as an argument. It accepts a user access token.
You can use the getDeviceManager method on the CallClient instance to access deviceManager.
JavaScript
const { CallClient } = require('@azure/communication-calling');
const { AzureCommunicationTokenCredential} = require('@azure/communication-common');
const { AzureLogger, setLogLevel } = require("@azure/logger");
// Set the logger's log level
setLogLevel('verbose');
// Redirect log output to console, file, buffer, REST API, or whatever location you want
AzureLogger.log = (...args) => {
console.log(...args); // Redirect log output to console
};
const userToken = '<USER_TOKEN>';
callClient = new CallClient(options);
const tokenCredential = new AzureCommunicationTokenCredential(userToken);
const callAgent = await callClient.createCallAgent(tokenCredential, {displayName: 'optional Azure Communication Services user name'});
const deviceManager = await callClient.getDeviceManager()
How to best manage SDK connectivity to Microsoft infrastructure
The Call Agent instance helps you manage calls (to join or start calls). In order to work your calling SDK needs to connect to Microsoft infrastructure to get notifications of incoming calls and coordinate other call details. Your Call Agent has two possible states:
Connected - A Call Agent connectionStatue value of Connected means the client SDK is connected and capable of receiving notifications from Microsoft infrastructure.
Disconnected - A Call Agent connectionStatue value of Disconnected states there's an issue that is preventing the SDK it from properly connecting. Call Agent should be re-created.
invalidToken: If a token is expired or is invalid Call Agent instance disconnects with this error.
connectionIssue: If there's an issue with the client connecting to Microsoft infrascture, after many retries Call Agent exposes the connectionIssue error.
You can check if your local Call Agent is connected to Microsoft infrastructure by inspecting the current value of connectionState property. During an active call you can listen to the connectionStateChanged event to determine if Call Agent changes from Connected to Disconnected state.
JavaScript
const connectionState = callAgentInstance.connectionState;
console.log(connectionState); // it may return either of 'Connected' | 'Disconnected'const connectionStateCallback = (args) => {
console.log(args); // it will return an object with oldState and newState, each of having a value of either of 'Connected' | 'Disconnected'// it will also return reason, either of 'invalidToken' | 'connectionIssue'
}
callAgentInstance.on('connectionStateChanged', connectionStateCallback);
Implement reactions for meeting participants
In Azure Communication Services participants can send and receive reactions during a group call:
Like
Love
Applause
Laugh
Surprise
To send a reaction, use the sendReaction(reactionMessage) API. To receive a reaction, the message builds with type ReactionMessage using Reaction enums as an attribute.
You need to subscribe to events that provide the subscriber event data:
JavaScript
export interface ReactionEventPayload {
/**
* identifier for a participant
*/
identifier: CommunicationUserIdentifier | MicrosoftTeamsUserIdentifier;
/**
* reaction type received
*/
reactionMessage: ReactionMessage;
}
You can determine which reaction is coming from which participant using the identifier attribute and getting the reaction type from ReactionMessage.
Sample showing how to send a reaction in a meeting
The Microsoft Teams JavaScript client library can help you integrate native Teams features right in your application. In this module, you'll learn how to integrate the Teams chat capability in your app by using the Teams JavaScript client library.