Sends a room-level reaction.
Room reactions are ephemeral events that are not associated with specific messages. They're commonly used for live interactions like floating emojis, applause, or other real-time feedback in chat rooms. Unlike message reactions, room reactions are not persisted and are only visible to users currently connected to the room.
Note:
The reaction parameters
Promise that resolves when the reaction has been sent, or rejects with:
import * as Ably from 'ably';
import { ChatClient } from '@ably/chat';
const chatClient: ChatClient; // existing ChatClient instance
const room = await chatClient.rooms.get('live-event');
// Attach to the room to send room reactions
await room.attach();
// Send a simple room reaction
try {
await room.reactions.send({
name: '❤️'
});
console.log('Heart reaction sent to room');
} catch (error) {
console.error('Failed to send reaction:', error);
}
Subscribes to room-level reaction events.
Receives all room reactions sent by any user in the room. This is useful for displaying floating reactions, triggering animations, or showing live audience engagement in real-time. Room reactions are ephemeral and not persisted.
Note: The room should be attached to receive reaction events.
Callback invoked when a room reaction is received
Subscription object with an unsubscribe method
import * as Ably from 'ably';
import { ChatClient, RoomReactionEvent } from '@ably/chat';
const chatClient: ChatClient; // existing ChatClient instance
const room = await chatClient.rooms.get('webinar-room');
// Subscribe to room reactions for live animations
const subscription = room.reactions.subscribe((event: RoomReactionEvent) => {
const { reaction } = event;
console.log(`${reaction.clientId} sent ${reaction.name}`);
console.log(`Sent at: ${reaction.createdAt.toISOString()}`);
// Handle different reaction types
switch (reaction.name) {
case '❤️':
// Show floating heart animation
showFloatingHeart(reaction.isSelf ? 'own' : 'other');
break;
case '👏':
// Show applause indicator
showApplauseAnimation(reaction.clientId);
break;
default:
// Handle generic reactions
showGenericReaction(reaction.name);
}
// Check if reaction is from current user
if (reaction.isSelf) {
console.log('You sent a reaction:', reaction.name);
}
});
// Attach to the room to start receiving events
await room.attach();
// Later, unsubscribe when done
subscription.unsubscribe();
This interface is used to interact with room-level reactions in a chat room: subscribing to reactions and sending them.
Get an instance via Room.reactions.