bagman
Version:
js/ts client for Bagman
53 lines (52 loc) • 1.99 kB
TypeScript
import { ClientSocket, Presence } from "./types";
/**
* A class representing a Channel for the Bagman client.
*/
export declare class Channel {
private socket;
private channel;
/**
* @param deactivated - Whether this channel is deactivated.
*/
private deactivated;
/**
* Creates a new instance of Channel.
*
* @param socket - The socket.io client socket to use for communication.
* @param channel - The name of the channel to subscribe to.
*/
constructor(socket: ClientSocket, channel: string);
/**
* Registers a callback function to be executed when the specified event is emitted.
*
* @template T - The type of data to be passed as arguments to the callback function.
* @param event - The name of the event to listen for.
* @param cb - The callback function to be executed when the specified event is emitted.
*
* @returns void
*/
listen<T extends [...any[]]>(event: string, cb: (...args: T) => Promise<void> | void): void;
/**
* Fetch Presences of the current channel.
*
* @template T - the type of presence that you expected to receive
* @returns - list of presences that's within this channel
*/
presences<T>(): Promise<Presence<T>[]>;
/**
* Publishes an event to the channel.
*
* @template Data - The type of data to be passed along with the event.
* @param event - The name of the event to be published.
* @param data - The data to be passed along with the event.
*
* @returns Promise<void> - A promise that resolves if the event was successfully published, and rejects if there was an error.
*/
publish<Data extends any>(event: string, data: Data): Promise<void>;
/**
* Unsubscribes from the channel.
*
* @returns Promise<void> - A promise that resolves if the unsubscribe was successful, and rejects if there was an error.
*/
unsubscribe(): Promise<void>;
}