@ably/chat
Version:
Ably Chat is a set of purpose-built APIs for a host of chat features enabling you to create 1:1, 1:Many, Many:1 and Many:Many chat rooms for any scale. It is designed to meet a wide range of chat use cases, such as livestreams, in-game communication, cust
35 lines (31 loc) • 939 B
text/typescript
import * as Ably from 'ably';
/**
* Convenience function that takes an event name and optional data and turns it into a
* message that the server will recognize as ephemeral.
* @param name The name of the event.
* @param data Optional data to send with the event.
* @returns An Ably message.
*/
export const ephemeralMessage = (name: string, data?: unknown): Ably.Message => ({
name: name,
data: data,
extras: {
ephemeral: true,
},
});
/**
* Takes an existing Ably message and converts it to an ephemeral message by adding
* the ephemeral flag in the extras field.
* @param message The Ably message to convert.
* @returns A new Ably message with the ephemeral flag set.
*/
export const messageToEphemeral = (message: Ably.Message): Ably.Message => {
const extras = message.extras ? (message.extras as object) : {};
return {
...message,
extras: {
...extras,
ephemeral: true,
},
};
};