import { HMSPeerID, HMSRoleName } from '@100mslive/hms-video-store'; import { hooksErrHandler } from './types'; export interface useCustomEventInput { /** * type of the event, for example, MODERATOR_EVENT, EMOJI_REACTIONS etc. */ type: string; /** * the handler function for when the custom event comes. It's recommended * to use `useCallback` for the function passed in here for performance * reasons. * The callback is optional in case you want to decouple sending event and * handling event in the UI. */ onEvent?: (data: T) => void; /** * flag to treat event payload as json. * If true, the payload will be stringified before sending and * parsed before calling the onEvent handler function. * * Set it to `false` if you want to send/receive only string messages * * Set it to `true` if you want to send/receive objects * * default value is true */ json?: boolean; /** * function to handle errors happening during sending the event */ handleError?: hooksErrHandler; } export interface EventReceiver { peerId?: HMSPeerID; roleNames?: HMSRoleName[]; } export interface useCustomEventResult { /** * sends the event data to others in the room who will receive it in onEvent * * @example to send message to peers of specific roles * ```js * sendEvent(data, {roleNames: ['host','guest']}) * ``` * * @example to send message to single peer * ```js * sendEvent(data, {peerId}) * ``` */ sendEvent: (data: T, receiver?: EventReceiver) => void; } /** * A generic function to implement [custom events](https://www.100ms.live/docs/javascript/v2/features/chat#custom-events) in your UI. * The data to be sent to remote is expected to be a serializable JSON. The serialization * and deserialization is taken care of by the hook. */ export declare const useCustomEvent: ({ type, json, onEvent, handleError, }: useCustomEventInput) => useCustomEventResult;