@folklore/socket 0.4.29 → 0.4.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,129 @@
1
+ import { EventEmitter } from '@folklore/events';
2
+ import * as react from 'react';
3
+ import { ReactNode, JSX } from 'react';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
6
+ interface SocketAdapterOptions {
7
+ [key: string]: unknown;
8
+ }
9
+ type SocketAdapterEvents = {
10
+ ready?: void;
11
+ start?: void;
12
+ started?: void;
13
+ stop?: number;
14
+ message?: unknown;
15
+ };
16
+ interface SocketAdapter extends EventEmitter<SocketAdapterEvents> {
17
+ destroy: () => void;
18
+ start: () => void;
19
+ stop: () => void;
20
+ send: (data: unknown) => void;
21
+ updateChannels: (channels: string[] | string) => void;
22
+ }
23
+ interface SocketAdapterContructor {
24
+ new (options?: SocketAdapterOptions): SocketAdapter;
25
+ }
26
+
27
+ type SocketEvents = {
28
+ ready: void;
29
+ start: void;
30
+ started: void;
31
+ stop: void;
32
+ message: unknown;
33
+ };
34
+ declare class Socket extends EventEmitter<SocketEvents> {
35
+ static adapters: Record<string, SocketAdapterContructor>;
36
+ options: {
37
+ adapter: string | SocketAdapterContructor | null;
38
+ host: string | null;
39
+ namespace: string | null;
40
+ uuid: string | null;
41
+ publishKey: string | null;
42
+ subscribeKey: string | null;
43
+ secretKey: string | null;
44
+ channels: string[];
45
+ [key: string]: unknown;
46
+ };
47
+ adapter: SocketAdapter | null;
48
+ channels: string[];
49
+ shouldStart: boolean;
50
+ started: boolean;
51
+ starting: boolean;
52
+ ready: boolean;
53
+ static getAdapters(): Record<string, SocketAdapterContructor>;
54
+ static getAdapter(adapter: any): SocketAdapterContructor;
55
+ static addAdapter(name: any, adapter: any): typeof Socket;
56
+ static setAdapters(adapters: any): typeof Socket;
57
+ constructor(opts: any);
58
+ onAdapterReady(): void;
59
+ onAdapterStart(): void;
60
+ onAdapterStarted(): void;
61
+ onAdapterStop(): void;
62
+ onAdapterMessage(message: unknown): void;
63
+ getChannelWithoutNamespace(name: any): any;
64
+ getChannelWithNamespace(name: any): string;
65
+ setChannels(channels: any): void;
66
+ addChannel(channel: any): void;
67
+ addChannels(channels: any): void;
68
+ removeChannel(channel: any): void;
69
+ removeChannels(channels: any): void;
70
+ updateChannels(channels: any): void;
71
+ hasChannel(channel: any): boolean;
72
+ getChannels(): any[];
73
+ init(): void;
74
+ destroy(): void;
75
+ restart(): void;
76
+ start(): void;
77
+ stop(): void;
78
+ send(data: any, channel: any): void | Promise<never>;
79
+ isStarted(): boolean;
80
+ }
81
+
82
+ type SocketContextType = {
83
+ socket: Socket | null;
84
+ subscribe: (channels: string[] | string) => void;
85
+ unsubscribe: (channels: string[] | string) => void;
86
+ channels?: string[];
87
+ };
88
+ declare const SocketContext: react.Context<SocketContextType>;
89
+
90
+ type SocketContainerProps = {
91
+ children?: ReactNode;
92
+ socket?: Socket | null;
93
+ autoStart?: boolean;
94
+ adapter?: string | null;
95
+ host?: string | null;
96
+ namespace?: string | null;
97
+ uuid?: string | null;
98
+ publishKey?: string | null;
99
+ subscribeKey?: string | null;
100
+ secretKey?: string | null;
101
+ channels?: string[];
102
+ [key: string]: unknown;
103
+ };
104
+ declare function SocketContainer({ children, socket, autoStart, adapter, host, namespace, uuid, publishKey, subscribeKey, secretKey, channels: initialChannels, ...props }: SocketContainerProps): JSX.Element;
105
+
106
+ declare const withSocket: (WrappedComponent: any) => {
107
+ (props: any): react_jsx_runtime.JSX.Element;
108
+ displayName: string;
109
+ };
110
+
111
+ interface UseSocketOptions {
112
+ socket?: Socket;
113
+ onMessage?: (...args: unknown[]) => void;
114
+ keepAlive?: boolean;
115
+ }
116
+ declare function useSocket(channelNames?: string | string[] | null, opts?: UseSocketOptions): {
117
+ socket: Socket;
118
+ started: boolean;
119
+ subscribe: (channels: string[] | string) => void;
120
+ unsubscribe: (channels: string[] | string) => void;
121
+ };
122
+
123
+ type debugCreator = (namespace: string) => debug;
124
+ type debug = (...args: unknown[]) => void;
125
+ declare let debug: debug;
126
+ declare function setDebug(newDebug: debugCreator | string): void;
127
+
128
+ export { Socket, SocketContainer, SocketContext, debug, Socket as default, setDebug, useSocket, withSocket };
129
+ export type { SocketAdapter, SocketAdapterContructor, SocketAdapterEvents, SocketAdapterOptions };