import ChannelCore, { ChPreparedData } from './ChannelCore'; import Bag from '../Bag'; import Socket from '../Socket'; import { ChannelConfig } from '../../main/config/definitions/parts/channelConfig'; import { ComplexTypesOption } from 'ziron-worker'; import { UnsubscribeTrigger } from '../../main/channel/channelDefinitions'; /** * Channels implements the subscribe/publish architecture. * They ideal for sending something to multiple clients. * When you want to reach that data should be kept up to date * on a client in real-time you should use Databoxes instead. * * You can override these methods: * - initialize * * events: * - onSubscription * - onUnsubscription * - onPublish */ export default class StaticChannel extends ChannelCore { /** * Maps the sockets to the kick out function. */ private readonly _subSockets; private readonly _chId; private _internalRegistered; private _unregisterTimout; private readonly _onPublish; private readonly _onSubscription; private readonly _onUnsubscription; constructor(identifier: string, bag: Bag, chPreparedData: ChPreparedData, apiLevel: number | undefined); private _addSocket; private _unsubscribeSocket; private _rmSocket; /** * Clears the timeout to unregister. * @private */ private _clearUnregisterTimeout; /** * Creates (set or renew) the timeout to unregister. * @private */ private _createUnregisterTimeout; /** * Processes an internal publish. * @private */ private _processPublish; /** * Registers for listening to the internal channel. * @private */ private _register; /** * Unregister for listening to the internal channel. * @private */ private _unregister; private _sendToServers; /** * Close this Channel. * @param closePackage * @private */ private _close; private _internalClose; /** * **Not override this method.** * Publish into this channel. * @param event * @param data * @param processComplexTypes * @param publisherSid * The publisher sid indicates the socket sid that publishes the data. * If you provide one the published data will not send to the publisher socket. */ publish(event: string, data?: any, { processComplexTypes, publisherSid }?: ComplexTypesOption & { publisherSid?: string; }): void; /** * **Not override this method.** * The close function will close the Channel for every client on every server. * You optionally can provide a code or any other information for the client. * Usually, the close function is used when the data is completely deleted from the system. * For example, a chat that doesn't exist anymore. * @param code * @param metadata * @param forEveryServer * @return The returned promise is resolved when * the close is fully processed on the current server. */ close(code?: number | string, metadata?: any, forEveryServer?: boolean): Promise; /** * **Not override this method.** * Kicks out a socket from this channel. * @param socket * @param code * @param metadata */ kickOut(socket: Socket, code?: number | string, metadata?: any): void; /** * **Can be overridden.** * A function that gets triggered when a socket subscribes to this channel. * @param socket */ protected onSubscription(socket: Socket): Promise | void; /** * **Can be overridden.** * A function that gets triggered when a socket unsubscribes this channel. * @param socket * @param trigger */ protected onUnsubscription(socket: Socket, trigger: UnsubscribeTrigger): Promise | void; /** * **Can be overridden.** * A function that gets triggered when data is published into this channel. * @param event * @param data */ protected onPublish(event: string, data: any): Promise | void; } export declare type StaticChannelClass = (new (...args: any[]) => StaticChannel) & { config: ChannelConfig; prototype: StaticChannel; };