UNPKG

@experteam-mx/ngx-services

Version:

Angular common services for Experteam apps

50 lines (49 loc) 2.55 kB
import { Channel } from 'pusher-js'; import { Observable } from 'rxjs'; import { Environment } from '../ngx-services.models'; import * as i0 from "@angular/core"; export declare class WebSocketsService { private environments; private pusher; constructor(environments: Environment); /** * Publishes an event to the specified channel with the given data. * * @param {Channel} channel - The channel instance where the event will be published. * @param {string} eventName - The name of the event to be published. * @param {T} data - The payload data to be sent with the event. * @return {Promise<boolean>} A promise that resolves to a boolean indicating * whether the event was successfully triggered on the channel. */ pub<T>(channel: Channel, eventName: string, data: T): Promise<boolean>; /** * Subscribes to a specified channel, retrying multiple times upon failure. * * @param {string} channelName - The name of the channel to be subscribed to. * @return {Promise<Channel>} A promise that resolves to the subscribed channel object if successful. * @throws {Error} If the subscription fails after the maximum number of retry attempts. */ channelSub(channelName: string): Promise<Channel>; /** * Binds an event listener to a specified event on a given channel using Pusher or a Channel object, * and returns an Observable that emits event data of type T. * * @param {Channel|string} channel - The channel to bind the event to. It can be a Channel object or a string representing the channel name. * @param {string} event - The name of the event to bind to the channel. * @return {Observable<T>} An Observable that emits data of type T when the specified event is triggered. */ eventBind<T>(channel: Channel | string, event: string): Observable<T>; /** * Unbinds an event from the specified channel and returns an observable * that emits data when the event callback is triggered. * * @param {Channel} channel - The channel object from which the event should be unbound. * @param {string} event - The name of the event to unbind. * @return {Observable<T>} An observable that emits data from the unbound event callback. */ eventUnbind<T>(channel: Channel, event: string): Observable<unknown>; private connect; private wait; static ɵfac: i0.ɵɵFactoryDeclaration<WebSocketsService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<WebSocketsService>; }