UNPKG

4.17 kBTypeScriptView Raw
1import { Channel, NullChannel, NullEncryptedPrivateChannel, NullPresenceChannel, NullPrivateChannel, PresenceChannel, PusherChannel, PusherEncryptedPrivateChannel, PusherPresenceChannel, PusherPrivateChannel, SocketIoChannel, SocketIoPresenceChannel, SocketIoPrivateChannel } from './channel';
2import { Connector, PusherConnector, SocketIoConnector, NullConnector } from './connector';
3/**
4 * This class is the primary API for interacting with broadcasting.
5 */
6export default class Echo<T extends keyof Broadcaster> {
7 /**
8 * The broadcasting connector.
9 */
10 connector: Broadcaster[T]['connector'];
11 /**
12 * The Echo options.
13 */
14 options: EchoOptions<T>;
15 /**
16 * Create a new class instance.
17 */
18 constructor(options: EchoOptions<T>);
19 /**
20 * Get a channel instance by name.
21 */
22 channel(channel: string): Broadcaster[T]['public'];
23 /**
24 * Create a new connection.
25 */
26 connect(): void;
27 /**
28 * Disconnect from the Echo server.
29 */
30 disconnect(): void;
31 /**
32 * Get a presence channel instance by name.
33 */
34 join(channel: string): Broadcaster[T]['presence'];
35 /**
36 * Leave the given channel, as well as its private and presence variants.
37 */
38 leave(channel: string): void;
39 /**
40 * Leave the given channel.
41 */
42 leaveChannel(channel: string): void;
43 /**
44 * Leave all channels.
45 */
46 leaveAllChannels(): void;
47 /**
48 * Listen for an event on a channel instance.
49 */
50 listen(channel: string, event: string, callback: Function): Broadcaster[T]['public'];
51 /**
52 * Get a private channel instance by name.
53 */
54 private(channel: string): Broadcaster[T]['private'];
55 /**
56 * Get a private encrypted channel instance by name.
57 */
58 encryptedPrivate(channel: string): Broadcaster[T]['encrypted'];
59 /**
60 * Get the Socket ID for the connection.
61 */
62 socketId(): string;
63 /**
64 * Register 3rd party request interceptiors. These are used to automatically
65 * send a connections socket id to a Laravel app with a X-Socket-Id header.
66 */
67 registerInterceptors(): void;
68 /**
69 * Register a Vue HTTP interceptor to add the X-Socket-ID header.
70 */
71 registerVueRequestInterceptor(): void;
72 /**
73 * Register an Axios HTTP interceptor to add the X-Socket-ID header.
74 */
75 registerAxiosRequestInterceptor(): void;
76 /**
77 * Register jQuery AjaxPrefilter to add the X-Socket-ID header.
78 */
79 registerjQueryAjaxSetup(): void;
80 /**
81 * Register the Turbo Request interceptor to add the X-Socket-ID header.
82 */
83 registerTurboRequestInterceptor(): void;
84}
85/**
86 * Export channel classes for TypeScript.
87 */
88export { Connector, Channel, PresenceChannel };
89export { EventFormatter } from './util';
90/**
91 * Specifies the broadcaster
92 */
93declare type Broadcaster = {
94 reverb: {
95 connector: PusherConnector;
96 public: PusherChannel;
97 private: PusherPrivateChannel;
98 encrypted: PusherEncryptedPrivateChannel;
99 presence: PusherPresenceChannel;
100 };
101 pusher: {
102 connector: PusherConnector;
103 public: PusherChannel;
104 private: PusherPrivateChannel;
105 encrypted: PusherEncryptedPrivateChannel;
106 presence: PusherPresenceChannel;
107 };
108 'socket.io': {
109 connector: SocketIoConnector;
110 public: SocketIoChannel;
111 private: SocketIoPrivateChannel;
112 encrypted: never;
113 presence: SocketIoPresenceChannel;
114 };
115 null: {
116 connector: NullConnector;
117 public: NullChannel;
118 private: NullPrivateChannel;
119 encrypted: NullEncryptedPrivateChannel;
120 presence: NullPresenceChannel;
121 };
122 function: {
123 connector: any;
124 public: any;
125 private: any;
126 encrypted: any;
127 presence: any;
128 };
129};
130declare type Constructor<T = {}> = new (...args: any[]) => T;
131declare type EchoOptions<T extends keyof Broadcaster> = {
132 /**
133 * The broadcast connector.
134 */
135 broadcaster: T extends 'function' ? Constructor<InstanceType<Broadcaster[T]['connector']>> : T;
136 [key: string]: any;
137};