@eleven-am/pondsocket-client 0.0.6 → 0.0.7
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.
- package/dist.d.ts +165 -0
- package/index.d.ts +3 -3
- package/package.json +3 -3
- package/browser/client.d.ts +0 -33
- package/browser/client.test.d.ts +0 -1
- package/core/channel.d.ts +0 -100
- package/core/channel.test.d.ts +0 -1
- package/node/node.d.ts +0 -7
- package/types.d.ts +0 -10
package/dist.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PondEventMap,
|
|
3
|
+
JoinParams,
|
|
4
|
+
PondPresence,
|
|
5
|
+
PresencePayload,
|
|
6
|
+
PondMessage,
|
|
7
|
+
EventWithResponse,
|
|
8
|
+
PayloadForResponse,
|
|
9
|
+
ResponseForEvent, Unsubscribe,
|
|
10
|
+
} from '@eleven-am/pondsocket-common';
|
|
11
|
+
|
|
12
|
+
export enum ChannelState {
|
|
13
|
+
IDLE = 'IDLE',
|
|
14
|
+
JOINING = 'JOINING',
|
|
15
|
+
JOINED = 'JOINED',
|
|
16
|
+
STALLED = 'STALLED',
|
|
17
|
+
CLOSED = 'CLOSED',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class Channel<EventMap extends PondEventMap = PondEventMap> {
|
|
21
|
+
/**
|
|
22
|
+
* @desc Gets the current connection state of the channel.
|
|
23
|
+
*/
|
|
24
|
+
get channelState (): ChannelState;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @desc Connects to the channel.
|
|
28
|
+
*/
|
|
29
|
+
join (): void;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @desc Disconnects from the channel.
|
|
33
|
+
*/
|
|
34
|
+
leave (): void;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @desc Monitors the channel for messages.
|
|
38
|
+
* @param callback - The callback to call when a message is received.
|
|
39
|
+
*/
|
|
40
|
+
onMessage<Event extends keyof EventMap> (callback: (event: Event, message: EventMap[Event]) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @desc Monitors the channel for messages.
|
|
44
|
+
* @param event - The event to monitor.
|
|
45
|
+
* @param callback - The callback to call when a message is received.
|
|
46
|
+
*/
|
|
47
|
+
onMessageEvent<Event extends keyof EventMap> (event: Event, callback: (message: EventMap[Event]) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @desc Monitors the channel state of the channel.
|
|
51
|
+
* @param callback - The callback to call when the connection state changes.
|
|
52
|
+
*/
|
|
53
|
+
onChannelStateChange (callback: (connected: ChannelState) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @desc Detects when clients join the channel.
|
|
57
|
+
* @param callback - The callback to call when a client joins the channel.
|
|
58
|
+
*/
|
|
59
|
+
onJoin (callback: (presence: PondPresence) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @desc Detects when clients leave the channel.
|
|
63
|
+
* @param callback - The callback to call when a client leaves the channel.
|
|
64
|
+
*/
|
|
65
|
+
onLeave (callback: (presence: PondPresence) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @desc Detects when clients change their presence in the channel.
|
|
69
|
+
* @param callback - The callback to call when a client changes their presence in the channel.
|
|
70
|
+
*/
|
|
71
|
+
onPresenceChange (callback: (presence: PresencePayload) => void): import('@eleven-am/pondsocket-common/subjects/types').Unsubscribe;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @desc Sends a message to specific clients in the channel.
|
|
75
|
+
* @param event - The event to send.
|
|
76
|
+
* @param payload - The message to send.
|
|
77
|
+
* @param recipient - The clients to send the message to.
|
|
78
|
+
*/
|
|
79
|
+
sendMessage (event: string, payload: PondMessage, recipient: string[]): void;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @desc Sends a message to the server and waits for a response.
|
|
83
|
+
* @param sentEvent - The event to send.
|
|
84
|
+
* @param payload - The message to send.
|
|
85
|
+
*/
|
|
86
|
+
sendForResponse<Event extends EventWithResponse<EventMap>> (sentEvent: Event, payload: PayloadForResponse<EventMap, Event>): Promise<ResponseForEvent<EventMap, Event>>;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
90
|
+
* @param event - The event to send.
|
|
91
|
+
* @param payload - The message to send.
|
|
92
|
+
*/
|
|
93
|
+
broadcastFrom<Event extends keyof EventMap> (event: Event, payload: EventMap[Event]): void;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @desc Broadcasts a message to the channel, including yourself.
|
|
97
|
+
* @param event - The event to send.
|
|
98
|
+
* @param payload - The message to send.
|
|
99
|
+
*/
|
|
100
|
+
broadcast<Event extends keyof EventMap> (event: Event, payload: EventMap[Event]): void;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @desc Gets the current presence of the channel.
|
|
104
|
+
*/
|
|
105
|
+
getPresence (): PondPresence[];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @desc Monitors the presence of the channel.
|
|
109
|
+
* @param callback - The callback to call when the presence changes.
|
|
110
|
+
*/
|
|
111
|
+
onUsersChange (callback: (users: PondPresence[]) => void): Unsubscribe;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* @desc Checks if the channel is connected.
|
|
115
|
+
*/
|
|
116
|
+
isConnected (): boolean;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @desc Checks if the channel is stalled.
|
|
120
|
+
*/
|
|
121
|
+
isStalled (): boolean;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @desc Checks if the channel is closed.
|
|
125
|
+
*/
|
|
126
|
+
isClosed (): boolean;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @desc Monitors the connection state of the channel.
|
|
130
|
+
* @param callback - The callback to call when the connection state changes.
|
|
131
|
+
*/
|
|
132
|
+
onConnectionChange (callback: (connected: boolean) => void): Unsubscribe;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare class PondClient {
|
|
136
|
+
constructor (endpoint: string, params?: Record<string, any>);
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* @desc Connects to the server and returns the socket.
|
|
140
|
+
*/
|
|
141
|
+
connect (backoff?: number): void;
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* @desc Returns the current state of the socket.
|
|
145
|
+
*/
|
|
146
|
+
getState (): boolean;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @desc Disconnects the socket.
|
|
150
|
+
*/
|
|
151
|
+
disconnect (): void;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* @desc Creates a channel with the given name and params.
|
|
155
|
+
* @param name - The name of the channel.
|
|
156
|
+
* @param params - The params to send to the server.
|
|
157
|
+
*/
|
|
158
|
+
createChannel<EventType extends PondEventMap = PondEventMap> (name: string, params?: JoinParams): Channel<EventType>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @desc Subscribes to the connection state.
|
|
162
|
+
* @param callback - The callback to call when the state changes.
|
|
163
|
+
*/
|
|
164
|
+
onConnectionChange (callback: (state: boolean) => void): Unsubscribe;
|
|
165
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export default
|
|
1
|
+
import { PondClient } from './dist';
|
|
2
|
+
|
|
3
|
+
export default PondClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket-client",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"build": "rimraf dist && tsc",
|
|
25
25
|
"lint": "eslint --ext .ts src",
|
|
26
26
|
"lint:fix": "eslint --fix --ext .ts src",
|
|
27
|
-
"copy": "cp package.json dist && cp README.md dist && cp LICENSE dist",
|
|
27
|
+
"copy": "cp package.json dist && cp README.md dist && cp LICENSE dist && cp src/index.d.ts dist && cp src/dist.d.ts dist",
|
|
28
28
|
"push": "npm version patch && npm run copy && cd dist && npm publish && cd ..",
|
|
29
|
-
"pipeline": "npm run
|
|
29
|
+
"pipeline": "npm run test && npm run build && npm run push"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@eleven-am/pondsocket-common": "^0.0.6",
|
package/browser/client.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { SimpleSubject, SimpleBehaviorSubject, ChannelEvent, JoinParams } from '@eleven-am/pondsocket-common';
|
|
2
|
-
import { Channel } from '../core/channel';
|
|
3
|
-
export default class PondClient {
|
|
4
|
-
#private;
|
|
5
|
-
protected readonly _address: URL;
|
|
6
|
-
protected _socket: WebSocket | any | undefined;
|
|
7
|
-
protected readonly _broadcaster: SimpleSubject<ChannelEvent>;
|
|
8
|
-
protected readonly _connectionState: SimpleBehaviorSubject<boolean>;
|
|
9
|
-
constructor(endpoint: string, params?: Record<string, any>);
|
|
10
|
-
/**
|
|
11
|
-
* @desc Connects to the server and returns the socket.
|
|
12
|
-
*/
|
|
13
|
-
connect(backoff?: number): void;
|
|
14
|
-
/**
|
|
15
|
-
* @desc Returns the current state of the socket.
|
|
16
|
-
*/
|
|
17
|
-
getState(): boolean;
|
|
18
|
-
/**
|
|
19
|
-
* @desc Disconnects the socket.
|
|
20
|
-
*/
|
|
21
|
-
disconnect(): void;
|
|
22
|
-
/**
|
|
23
|
-
* @desc Creates a channel with the given name and params.
|
|
24
|
-
* @param name - The name of the channel.
|
|
25
|
-
* @param params - The params to send to the server.
|
|
26
|
-
*/
|
|
27
|
-
createChannel(name: string, params?: JoinParams): Channel<import("@eleven-am/pondsocket-common").PondEventMap>;
|
|
28
|
-
/**
|
|
29
|
-
* @desc Subscribes to the connection state.
|
|
30
|
-
* @param callback - The callback to call when the state changes.
|
|
31
|
-
*/
|
|
32
|
-
onConnectionChange(callback: (state: boolean) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
33
|
-
}
|
package/browser/client.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/core/channel.d.ts
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import { SimpleSubject, SimpleBehaviorSubject, ChannelState, JoinParams, ChannelEvent, PondPresence, PondMessage, PresencePayload, PondEventMap, EventWithResponse, PayloadForResponse, ResponseForEvent } from '@eleven-am/pondsocket-common';
|
|
2
|
-
import { Publisher } from '../types';
|
|
3
|
-
export declare class Channel<EventMap extends PondEventMap = PondEventMap> {
|
|
4
|
-
#private;
|
|
5
|
-
constructor(publisher: Publisher, clientState: SimpleBehaviorSubject<boolean>, name: string, receiver: SimpleSubject<ChannelEvent>, params: JoinParams);
|
|
6
|
-
/**
|
|
7
|
-
* @desc Gets the current connection state of the channel.
|
|
8
|
-
*/
|
|
9
|
-
get channelState(): ChannelState;
|
|
10
|
-
/**
|
|
11
|
-
* @desc Connects to the channel.
|
|
12
|
-
*/
|
|
13
|
-
join(): void;
|
|
14
|
-
/**
|
|
15
|
-
* @desc Disconnects from the channel.
|
|
16
|
-
*/
|
|
17
|
-
leave(): void;
|
|
18
|
-
/**
|
|
19
|
-
* @desc Monitors the channel for messages.
|
|
20
|
-
* @param callback - The callback to call when a message is received.
|
|
21
|
-
*/
|
|
22
|
-
onMessage<Event extends keyof EventMap>(callback: (event: Event, message: EventMap[Event]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
23
|
-
/**
|
|
24
|
-
* @desc Monitors the channel for messages.
|
|
25
|
-
* @param event - The event to monitor.
|
|
26
|
-
* @param callback - The callback to call when a message is received.
|
|
27
|
-
*/
|
|
28
|
-
onMessageEvent<Event extends keyof EventMap>(event: Event, callback: (message: EventMap[Event]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
29
|
-
/**
|
|
30
|
-
* @desc Monitors the channel state of the channel.
|
|
31
|
-
* @param callback - The callback to call when the connection state changes.
|
|
32
|
-
*/
|
|
33
|
-
onChannelStateChange(callback: (connected: ChannelState) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
34
|
-
/**
|
|
35
|
-
* @desc Detects when clients join the channel.
|
|
36
|
-
* @param callback - The callback to call when a client joins the channel.
|
|
37
|
-
*/
|
|
38
|
-
onJoin(callback: (presence: PondPresence) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
39
|
-
/**
|
|
40
|
-
* @desc Detects when clients leave the channel.
|
|
41
|
-
* @param callback - The callback to call when a client leaves the channel.
|
|
42
|
-
*/
|
|
43
|
-
onLeave(callback: (presence: PondPresence) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
44
|
-
/**
|
|
45
|
-
* @desc Detects when clients change their presence in the channel.
|
|
46
|
-
* @param callback - The callback to call when a client changes their presence in the channel.
|
|
47
|
-
*/
|
|
48
|
-
onPresenceChange(callback: (presence: PresencePayload) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
49
|
-
/**
|
|
50
|
-
* @desc Sends a message to specific clients in the channel.
|
|
51
|
-
* @param event - The event to send.
|
|
52
|
-
* @param payload - The message to send.
|
|
53
|
-
* @param recipient - The clients to send the message to.
|
|
54
|
-
*/
|
|
55
|
-
sendMessage(event: string, payload: PondMessage, recipient: string[]): void;
|
|
56
|
-
/**
|
|
57
|
-
* @desc Sends a message to the server and waits for a response.
|
|
58
|
-
* @param sentEvent - The event to send.
|
|
59
|
-
* @param payload - The message to send.
|
|
60
|
-
*/
|
|
61
|
-
sendForResponse<Event extends EventWithResponse<EventMap>>(sentEvent: Event, payload: PayloadForResponse<EventMap, Event>): Promise<ResponseForEvent<EventMap, Event>>;
|
|
62
|
-
/**
|
|
63
|
-
* @desc Broadcasts a message to every other client in the channel except yourself.
|
|
64
|
-
* @param event - The event to send.
|
|
65
|
-
* @param payload - The message to send.
|
|
66
|
-
*/
|
|
67
|
-
broadcastFrom<Event extends keyof EventMap>(event: Event, payload: EventMap[Event]): void;
|
|
68
|
-
/**
|
|
69
|
-
* @desc Broadcasts a message to the channel, including yourself.
|
|
70
|
-
* @param event - The event to send.
|
|
71
|
-
* @param payload - The message to send.
|
|
72
|
-
*/
|
|
73
|
-
broadcast<Event extends keyof EventMap>(event: Event, payload: EventMap[Event]): void;
|
|
74
|
-
/**
|
|
75
|
-
* @desc Gets the current presence of the channel.
|
|
76
|
-
*/
|
|
77
|
-
getPresence(): PondPresence[];
|
|
78
|
-
/**
|
|
79
|
-
* @desc Monitors the presence of the channel.
|
|
80
|
-
* @param callback - The callback to call when the presence changes.
|
|
81
|
-
*/
|
|
82
|
-
onUsersChange(callback: (users: PondPresence[]) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
83
|
-
/**
|
|
84
|
-
* @desc Checks if the channel is connected.
|
|
85
|
-
*/
|
|
86
|
-
isConnected(): boolean;
|
|
87
|
-
/**
|
|
88
|
-
* @desc Checks if the channel is stalled.
|
|
89
|
-
*/
|
|
90
|
-
isStalled(): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* @desc Checks if the channel is closed.
|
|
93
|
-
*/
|
|
94
|
-
isClosed(): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* @desc Monitors the connection state of the channel.
|
|
97
|
-
* @param callback - The callback to call when the connection state changes.
|
|
98
|
-
*/
|
|
99
|
-
onConnectionChange(callback: (connected: boolean) => void): import("@eleven-am/pondsocket-common/subjects/types").Unsubscribe;
|
|
100
|
-
}
|
package/core/channel.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/node/node.d.ts
DELETED
package/types.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { ChannelReceivers, ClientActions, PondMessage } from '@eleven-am/pondsocket-common';
|
|
2
|
-
export interface ClientMessage {
|
|
3
|
-
addresses: ChannelReceivers | string[];
|
|
4
|
-
action: ClientActions;
|
|
5
|
-
event: string;
|
|
6
|
-
payload: PondMessage;
|
|
7
|
-
channelName: string;
|
|
8
|
-
requestId: string;
|
|
9
|
-
}
|
|
10
|
-
export type Publisher = (data: ClientMessage) => void;
|