/*! * Copyright (c) Microsoft Corporation and contributors. All rights reserved. * Licensed under the MIT License. */ import type { Listenable, Off } from "@fluidframework/core-interfaces"; import type { InternalTypes } from "./exposedInternalTypes.js"; import type { InternalUtilityTypes } from "./exposedUtilityTypes.js"; import type { Attendee, PresenceWithNotifications as Presence } from "./presence.js"; /** * @sealed * @alpha */ export interface NotificationsManagerEvents { /** * Raised when notification is received, but no subscribers were found. * * @eventProperty */ unattendedNotification: (name: string, sender: Attendee, ...content: unknown[]) => void; } /** * An object which allows the registration of listeners so that subscribers can be * notified when a notification happens. * * @sealed * @alpha */ export interface NotificationListenable> { /** * Register a notification listener. * @param notificationName - the name of the notification * @param listener - The listener function to run when the notification is fired. * @returns A {@link @fluidframework/core-interfaces#Off | function} which will deregister the listener when called. * Calling the deregistration function more than once will have no effect. * * Listeners may also be deregistered by passing the listener to {@link NotificationListenable.off | off()}. * @remarks Registering the exact same `listener` object for the same notification more than once will throw an error. * If registering the same listener for the same notification multiple times is desired, consider using a wrapper function for the second subscription. */ on>(notificationName: K, listener: (sender: Attendee, ...args: InternalUtilityTypes.JsonDeserializedParameters) => void): Off; /** * Deregister notification listener. * @param notificationName - The name of the notification. * @param listener - The listener function to remove from the current set of notification listeners. * @remarks If `listener` is not currently registered, this method will have no effect. * * Listeners may also be deregistered by calling the {@link @fluidframework/core-interfaces#Off | deregistration function} returned when they are {@link NotificationListenable.on | registered}. */ off>(notificationName: K, listener: (sender: Attendee, ...args: InternalUtilityTypes.JsonDeserializedParameters) => void): void; } /** * Record of notification subscription signatures transformed from listener emit signatures. * * @remarks * Prepends the `sender: Attendee` parameter to each notification listener signature. * * @sealed * @alpha */ export type NotificationSubscriberSignatures> = { [K in keyof InternalUtilityTypes.NotificationListeners]: (sender: Attendee, ...args: InternalUtilityTypes.JsonDeserializedParameters) => void; }; /** * Interface for a notification emitter that can send typed notification to other clients. * * @sealed * @alpha */ export interface NotificationEmitter> { /** * Emits a notification with the specified name and arguments, notifying all clients. * @param notificationName - the name of the notification to fire * @param args - the arguments sent with the notification */ broadcast>(notificationName: K, ...args: Parameters): void; /** * Emits a notification with the specified name and arguments, notifying a single attendee. * @param notificationName - the name of the notification to fire * @param targetAttendee - the single attendee to notify * @param args - the arguments sent with the notification */ unicast>(notificationName: K, targetAttendee: Attendee, ...args: Parameters): void; } /** * Provides notifications from this client to others and subscription * to their notifications. * * @remarks Create using {@link @fluidframework/presence#(Notifications:1)} registered to * {@link NotificationsWorkspace} or {@link StatesWorkspace}. * * @sealed * @alpha */ export interface NotificationsManager> { /** * Containing {@link Presence} */ readonly presence: Presence; /** * Events for Notifications manager. */ readonly events: Listenable; /** * Send notifications to other clients. */ readonly emit: NotificationEmitter; /** * Provides subscription to notifications from other clients. */ readonly notifications: NotificationListenable; } /** * Type alias for the return type of {@link @fluidframework/presence#(Notifications:1)}. * * @remarks * Use this type instead of any InternalPresenceTypes that may be revealed from * examining factory return type. * * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain * allowed registration keys for this Notification within a workspace. * Specification is recommended to highlight connection between schema and * factory when spread across modules. * * @alpha * @sealed */ export type NotificationsConfiguration, RegistrationKeyRestrictions extends string = string> = InternalTypes.ManagerFactory, NotificationsManager>; /** * Type alias for the return type of {@link @fluidframework/presence#(Notifications:2)}. * * @remarks * Use this type instead of any InternalPresenceTypes that may be revealed from * examining factory return type. * * @typeparam RegistrationKeyRestrictions - Optional type parameter to constrain * allowed registration keys for this Notification within a workspace. * Specification is recommended to highlight connection between schema and * factory when spread across modules. * * @alpha * @sealed */ export type NotificationsWithSubscriptionsConfiguration, RegistrationKeyRestrictions extends string = string> = InternalTypes.ManagerFactory, NotificationsManager>>; //# sourceMappingURL=notificationsManagerTypes.d.ts.map