import { W3Notification } from "./notification"; import { W3StorageService } from "../storage/storage.service"; interface DataObj { [key: string]: any; } export interface SwChannel { name: string; listen(event: string, func: (e: any) => void): SwChannel; notification(func: (e: W3Notification) => void): SwChannel; } export interface SwInChannel extends SwChannel { here(func: (users: T[]) => void): SwInChannel; joining(func: (user: T) => void): SwInChannel; leaving(func: (user: T) => void): SwInChannel; listenForWhisper(eventName: string, func: (e: DataObj) => void): SwInChannel; whisper(eventName: string, e: T): SwInChannel; } /** * Service para conexões por Socket. * [Laravel Echo]{@link https://github.com/laravel/echo} * * * * @example * const options: Echo = new Echo({ * broadcaster: 'pusher', * key: 'asd75gasd581as', * cluster: 'us2', * authEndpoint: 'myapi/broadcasting/auth', * logToConsole: true, * auth: { * headers: { * Authorization: 'Bearer ...' * } * } * }); * * ngOnInit(){ * this.socket.connect(options); * * const channel = this.socket.createPrivateChannel(`MeuCanal.User.${userId}`) * * channel.listen(`MeuCanal.User.${userId}`, e => { * console.log('novo evento') * }) * * channel.notification(n: W3Notification) => { * console.log('nova notificação') * } * * } */ export declare class W3WebSocketService { private storage; private _echo; private _channels; constructor(storage: W3StorageService); readonly echo: any; /** * * @param connectOptions Instancia do LaravelEcho */ connect(connectOptions: any): W3WebSocketService; /** * * @param channel Nome do canal ao qual deseja receber eventos */ joinChannel(channel: string): SwInChannel; /** * Método para criação de novo canal privado * @param channel nome do canal */ createPrivateChannel(channel: string): SwChannel; /** * Método para criação de novo canal público * @param channel nome do canal */ createPublicChannel(channel: string): SwChannel; /** * cancelar recebimento de informação do canal * @param ch */ leave(ch: SwChannel): void; /** * Sair de todos os canais */ reset(): void; } export {};