@eleven-am/pondsocket 0.1.64 → 0.1.65
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/README.md +275 -111
- package/client.js +1 -1
- package/enums.js +8 -8
- package/package.json +13 -13
- package/types.d.ts +6 -15
package/README.md
CHANGED
|
@@ -1,139 +1,303 @@
|
|
|
1
|
-
|
|
2
1
|
# PondSocket
|
|
3
2
|
|
|
4
|
-
PondSocket is a
|
|
5
|
-
|
|
3
|
+
PondSocket is a high-performance, minimalist, and bidirectional socket framework designed for Node.js. It provides a seamless way to handle real-time communication between server and client applications, making it an ideal choice for building WebSocket-based projects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To integrate PondSocket into your Node.js project, simply install it via npm:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm install @eleven-am/pondsocket
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const endpoint = pond.createEndpoint('/api/socket', (req, res, _endpoint) => {
|
|
26
|
-
const token = req.query.token;
|
|
27
|
-
if (!token)
|
|
28
|
-
return res.reject('No token provided');
|
|
29
|
-
res.accept({
|
|
30
|
-
assign: {
|
|
31
|
-
token
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
})
|
|
35
|
-
```
|
|
13
|
+
## Overview
|
|
14
|
+
|
|
15
|
+
PondSocket simplifies the complexity of handling WebSocket connections by abstracting the communication process into individual requests rather than dealing with intricate callbacks within the connection event. It offers a lightweight yet powerful solution for managing bidirectional communication channels, enabling real-time updates and collaboration between server and client components.
|
|
16
|
+
|
|
17
|
+
## Server-side Usage
|
|
18
|
+
|
|
19
|
+
When setting up the server, PondSocket allows you to create multiple endpoints, each serving as a gateway for sockets to connect and communicate. Each endpoint operates independently, ensuring that sockets from one endpoint cannot interact with sockets from another. This isolation enhances security and simplifies resource management.
|
|
20
|
+
|
|
21
|
+
```javascript
|
|
22
|
+
import PondSocket from "@eleven-am/pondsocket";
|
|
23
|
+
|
|
24
|
+
const pond = new PondSocket();
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const channel = endpoint.createChannel(/^channel(.*?)/, (req, res, channel) => {
|
|
42
|
-
const isAdmin = req.clientAssigns.admin;
|
|
43
|
-
if (!isAdmin)
|
|
44
|
-
return res.reject('You are not an admin');
|
|
45
|
-
|
|
46
|
-
res.accept({
|
|
47
|
-
assign: {
|
|
48
|
-
admin: true,
|
|
49
|
-
joinedDate: new Date()
|
|
50
|
-
},
|
|
51
|
-
presence: {
|
|
52
|
-
state: 'online'
|
|
53
|
-
},
|
|
54
|
-
channelData: {
|
|
55
|
-
locked: true,
|
|
56
|
-
numberOfUsers: channel.presence.length
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
});
|
|
26
|
+
// Create an endpoint for handling socket connections
|
|
27
|
+
const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
|
|
28
|
+
// Handle socket connection and authentication
|
|
29
|
+
});
|
|
60
30
|
```
|
|
61
31
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```js
|
|
69
|
-
channel.on('hello', (req, res, channel) => {
|
|
70
|
-
const users = channel.presence;
|
|
71
|
-
res.assign({
|
|
72
|
-
assign: {
|
|
73
|
-
pingDate: new Date(),
|
|
74
|
-
users: users.length
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
// res.reject('curse words are not allowed on a child friendly channel')
|
|
79
|
-
// channel.closeFromChannel(req.client.clientId);
|
|
80
|
-
})
|
|
32
|
+
Within each endpoint, sockets interact through channels. Channels provide an organized way to group users and manage efficient communication among them. When users join a channel, they can participate in real-time events and exchange information with other users in the same channel.
|
|
33
|
+
|
|
34
|
+
```javascript
|
|
35
|
+
const channel = endpoint.createChannel('/channel/:id', (req, res) => {
|
|
36
|
+
// Handle channel-specific events and actions
|
|
37
|
+
});
|
|
81
38
|
```
|
|
82
39
|
|
|
83
|
-
|
|
84
|
-
You can choose to decline the message being sent, or you can allow the message to be sent as usual. You can also do all the normal assigns to the channel, or user.
|
|
85
|
-
In case there is no *on* function, the message will be sent without any action being taken.
|
|
40
|
+
## Client-side Usage
|
|
86
41
|
|
|
87
|
-
|
|
42
|
+
On the client-side, PondSocket provides the PondClient class to establish connections with the server. Clients can easily initiate connections, join channels, and participate in real-time interactions.
|
|
88
43
|
|
|
89
|
-
```
|
|
90
|
-
|
|
44
|
+
```javascript
|
|
45
|
+
import PondClient from "@eleven-am/pondsocket/client";
|
|
91
46
|
|
|
92
|
-
|
|
93
|
-
|
|
47
|
+
const socket = new PondClient('/api/socket', {});
|
|
48
|
+
socket.connect();
|
|
94
49
|
```
|
|
95
50
|
|
|
96
|
-
|
|
97
|
-
|
|
51
|
+
Once connected, clients can create and join channels to engage in real-time communication with other users and the server.
|
|
52
|
+
|
|
53
|
+
```javascript
|
|
54
|
+
const channel = socket.createChannel('/channel/123');
|
|
55
|
+
channel.join();
|
|
56
|
+
```
|
|
98
57
|
|
|
99
|
-
|
|
100
|
-
You can just create multiple channels and maintain the single socket connection.
|
|
58
|
+
### Node Client
|
|
101
59
|
|
|
102
|
-
|
|
103
|
-
const channelTopic = 'channel:one';
|
|
104
|
-
const options = {
|
|
105
|
-
username: 'eleven-am'
|
|
106
|
-
}
|
|
60
|
+
PondSocket also offers a Node.js client, which can be imported using:
|
|
107
61
|
|
|
108
|
-
|
|
109
|
-
|
|
62
|
+
```javascript
|
|
63
|
+
import PondClient from "@eleven-am/pondsocket/node";
|
|
110
64
|
```
|
|
111
65
|
|
|
112
|
-
|
|
66
|
+
This node client allows you to turn another server into a client, enabling easy communication between different server instances.
|
|
113
67
|
|
|
114
|
-
|
|
115
|
-
const subscriptionPresence = channel.onPresenceUpdate(presence => {
|
|
116
|
-
// handle the presence changes of the channel
|
|
117
|
-
});
|
|
68
|
+
## Key Features
|
|
118
69
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
70
|
+
- **Simple and Efficient API**: PondSocket offers an easy-to-use API, making WebSocket communication straightforward and hassle-free.
|
|
71
|
+
- **Organized Channels**: Channels provide a structured approach for grouping users and facilitating efficient communication.
|
|
72
|
+
- **Assigns**: PondSocket allows the storage of private information for users and channels, enhancing data security.
|
|
73
|
+
- **Presence**: The presence feature keeps track of users' current states and notifies other users about any changes.
|
|
74
|
+
- **Broadcasting**: PondSocket enables broadcasting messages to all users or specific groups within a channel, facilitating real-time updates.
|
|
75
|
+
- **Typed and Well-documented**: The codebase is thoroughly documented and typed, providing a seamless development experience with improved IDE suggestions.
|
|
122
76
|
|
|
123
|
-
|
|
124
|
-
subscriptionPresence.unsubscribe();
|
|
125
|
-
subscriptionMessage.unsubscribe();
|
|
126
|
-
```
|
|
77
|
+
## License
|
|
127
78
|
|
|
128
|
-
|
|
129
|
-
suggestions should be provided by your IDE.
|
|
79
|
+
PondSocket is released under the MIT License. Please refer to the `LICENSE` file for detailed licensing information.
|
|
130
80
|
|
|
131
|
-
|
|
132
|
-
channel.broadcast('hello', {
|
|
133
|
-
name: 'eleven-am',
|
|
134
|
-
message: 'I am the man, man'
|
|
135
|
-
})
|
|
81
|
+
## API Documentation
|
|
136
82
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
83
|
+
Apologies for the confusion. Let me remove "Class" from the title of each section:
|
|
84
|
+
|
|
85
|
+
### PondSocket
|
|
86
|
+
|
|
87
|
+
The `PondSocket` class is the core class that represents the socket server.
|
|
88
|
+
|
|
89
|
+
**Constructor:**
|
|
90
|
+
|
|
91
|
+
- `constructor(server?: HTTPServer, socketServer?: WebSocketServer)`: Creates a new instance of the PondSocket with an optional HTTP server and WebSocket server.
|
|
92
|
+
|
|
93
|
+
**Methods:**
|
|
94
|
+
|
|
95
|
+
- `listen(...args: any[]): HTTPServer`: Specifies the port to listen on with the provided arguments.
|
|
96
|
+
|
|
97
|
+
- `close(callback?: () => void): HTTPServer`: Closes the server, and an optional callback can be provided.
|
|
98
|
+
|
|
99
|
+
- `createEndpoint<Path extends string>(path: PondPath<Path>, handler: (request: IncomingConnection<Path>, response: ConnectionResponse) => void | Promise<void>): Endpoint`: Accepts a new socket upgrade request on the provided endpoint using the handler function to authenticate the socket.
|
|
100
|
+
|
|
101
|
+
### ConnectionResponse
|
|
102
|
+
|
|
103
|
+
The `ConnectionResponse` class represents the response object for the incoming connection.
|
|
104
|
+
|
|
105
|
+
**Methods:**
|
|
106
|
+
|
|
107
|
+
- `accept(assigns?: PondAssigns): void`: Accepts the request and optionally assigns data to the client.
|
|
108
|
+
|
|
109
|
+
- `reject(message?: string, errorCode?: number): void`: Rejects the request with the given error message and optional error code.
|
|
110
|
+
|
|
111
|
+
- `send(event: string, payload: PondMessage, assigns?: PondAssigns): void`: Emits a direct message to the client with the specified event and payload.
|
|
112
|
+
|
|
113
|
+
### Endpoint
|
|
114
|
+
|
|
115
|
+
The `Endpoint` class represents an endpoint in the PondSocket server where channels can be created.
|
|
116
|
+
|
|
117
|
+
**Methods:**
|
|
118
|
+
|
|
119
|
+
- `createChannel<Path extends string>(path: PondPath<Path>, handler: (request: JoinRequest<Path>, response: JoinResponse) => void | Promise<void>): PondChannel`: Adds a new PondChannel to this path on this endpoint with the provided handler function to authenticate the client.
|
|
120
|
+
|
|
121
|
+
- `broadcast(event: string, payload: PondMessage): void`: Broadcasts a message to all clients connected to this endpoint with the specified event and payload.
|
|
122
|
+
|
|
123
|
+
- `closeConnection(clientIds: string | string[]): void`: Closes specific clients connected to this endpoint identified by the provided clientIds.
|
|
124
|
+
|
|
125
|
+
### JoinRequest
|
|
126
|
+
|
|
127
|
+
The `JoinRequest` class represents the request object when a client joins a channel.
|
|
128
|
+
|
|
129
|
+
**Properties:**
|
|
130
|
+
|
|
131
|
+
- `event: PondEvent<Path>`: The event associated with the request.
|
|
132
|
+
|
|
133
|
+
- `channelName: string`: The name of the channel.
|
|
134
|
+
|
|
135
|
+
- `assigns: UserAssigns`: The assigns data for the client.
|
|
136
|
+
|
|
137
|
+
- `presence: UserPresences`: The presence data for the client.
|
|
138
|
+
|
|
139
|
+
- `joinParams: JoinParams`: The join parameters for the client.
|
|
140
|
+
|
|
141
|
+
- `user: UserData`: The user data associated with the client.
|
|
142
|
+
|
|
143
|
+
- `client: Client`: The Client instance associated with the request.
|
|
144
|
+
|
|
145
|
+
### JoinResponse
|
|
146
|
+
|
|
147
|
+
The `JoinResponse` class represents the response object for the join request.
|
|
148
|
+
|
|
149
|
+
**Methods:**
|
|
150
|
+
|
|
151
|
+
- `accept(assigns?: PondAssigns): JoinResponse`: Accepts the join request and optionally assigns data to the client.
|
|
152
|
+
|
|
153
|
+
- `reject(message?: string, errorCode?: number): JoinResponse`: Rejects the join request with the given error message and optional error code.
|
|
154
|
+
|
|
155
|
+
- `send(event: string, payload: PondMessage, assigns?: PondAssigns): JoinResponse`: Emits a direct message to the client with the specified event, payload, and optional assigns data.
|
|
156
|
+
|
|
157
|
+
- `broadcast(event: string, payload: PondMessage): JoinResponse`: Emits a message to all clients in the channel with the specified event and payload.
|
|
158
|
+
|
|
159
|
+
- `broadcastFromUser(event: string, payload: PondMessage): JoinResponse`: Emits a message to all clients in the channel except the sender with the specified event and payload.
|
|
160
|
+
|
|
161
|
+
- `sendToUsers(event: string, payload: PondMessage, userIds: string[]): JoinResponse`: Emits a message to a specific set of clients identified by the provided userIds with the specified event and payload.
|
|
162
|
+
|
|
163
|
+
- `trackPresence(presence: PondPresence): JoinResponse`: Tracks the presence of the client in the channel.
|
|
164
|
+
|
|
165
|
+
### PondChannel
|
|
166
|
+
|
|
167
|
+
The `PondChannel` class represents a Generic channel in the PondSocket server. It is used to create a channel whose path matches the provided PondPath.
|
|
168
|
+
|
|
169
|
+
**Methods:**
|
|
170
|
+
|
|
171
|
+
- `onEvent<Event extends string>(event: PondPath<Event>, handler: (request: EventRequest<Event>, response: EventResponse) => void | Promise<void>): void`: Handles an event request made by a user for the specified event with the provided handler function.
|
|
172
|
+
|
|
173
|
+
- `broadcast(event: string, payload: PondMessage, channelName?: string): void`: Broadcasts a message to all users in the channel with the specified event and payload. Optionally, a specific channel name can be provided to broadcast the message only to users in that channel.
|
|
174
|
+
|
|
175
|
+
### EventRequest
|
|
176
|
+
|
|
177
|
+
The `EventRequest` class represents the request object when an event is received from a client.
|
|
178
|
+
|
|
179
|
+
**Properties:**
|
|
180
|
+
|
|
181
|
+
- `event: PondEvent<Path>`: The event associated with the request.
|
|
182
|
+
|
|
183
|
+
- `channelName: string`: The name of the channel.
|
|
184
|
+
|
|
185
|
+
- `assigns: UserAssigns`: The assigns data for the client.
|
|
186
|
+
|
|
187
|
+
- `presence: UserPresences`: The presence data for the client.
|
|
188
|
+
|
|
189
|
+
- `user: UserData`: The user data associated with the client.
|
|
190
|
+
|
|
191
|
+
- `client: Client`: The Client instance associated with the request.
|
|
192
|
+
|
|
193
|
+
### EventResponse
|
|
194
|
+
|
|
195
|
+
The `EventResponse` class represents the response object for handling events from clients.
|
|
196
|
+
|
|
197
|
+
**Methods:**
|
|
198
|
+
|
|
199
|
+
- `accept(assigns?: PondAssigns): EventResponse`: Accepts the request and optionally assigns data to the client.
|
|
200
|
+
|
|
201
|
+
- `reject(message?: string, errorCode?: number, assigns?: PondAssigns): EventResponse`: Rejects the request with the given error message, optional error code, and optional assigns data.
|
|
202
|
+
|
|
203
|
+
- `send(event: string, payload: PondMessage, assigns?: PondAssigns): void`: Emits a direct message to the client with the specified event, payload, and optional assigns data.
|
|
204
|
+
|
|
205
|
+
- `broadcast(event: string, payload: PondMessage): EventResponse`: Sends a message to all clients in the channel with the specified event and payload.
|
|
206
|
+
|
|
207
|
+
- `broadcastFromUser(event: string, payload: PondMessage): EventResponse`: Sends a message to all clients in the channel except the sender with the specified event and payload.
|
|
208
|
+
|
|
209
|
+
- `sendToUsers(event: string, payload: PondMessage, userIds: string[]): EventResponse`: Sends
|
|
210
|
+
|
|
211
|
+
a message to a specific set of clients identified by the provided userIds with the specified event and payload.
|
|
212
|
+
|
|
213
|
+
- `trackPresence(presence: PondPresence, userId?: string): EventResponse`: Tracks a user's presence in the channel.
|
|
214
|
+
|
|
215
|
+
- `updatePresence(presence: PondPresence, userId?: string): EventResponse`: Updates a user's presence in the channel.
|
|
216
|
+
|
|
217
|
+
- `unTrackPresence(userId?: string): EventResponse`: Removes a user's presence from the channel.
|
|
218
|
+
|
|
219
|
+
- `evictUser(reason: string, userId?: string): void`: Evicts a user from the channel.
|
|
220
|
+
|
|
221
|
+
- `closeChannel(reason: string): void`: Closes the channel from the server-side for all clients.
|
|
222
|
+
|
|
223
|
+
### Client
|
|
224
|
+
|
|
225
|
+
The `Client` class represents a single Channel created by the PondSocket server. Note that a PondChannel can have multiple clients.
|
|
226
|
+
|
|
227
|
+
**Methods:**
|
|
228
|
+
|
|
229
|
+
- `getAssigns: UserAssigns`: Gets the current assign data for the client.
|
|
230
|
+
|
|
231
|
+
- `getUserData(userId: string): UserData`: Gets the assign data for a specific user identified by the provided `userId`.
|
|
232
|
+
|
|
233
|
+
- `broadcastMessage(event: string, payload: PondMessage): void`: Broadcasts a message to every client in the channel with the specified event and payload.
|
|
234
|
+
|
|
235
|
+
- `sendToUser(userId: string, event: string, payload: PondMessage): void`: Sends a message to a specific client in the channel identified by the provided `userId`, with the specified event and payload.
|
|
236
|
+
|
|
237
|
+
- `banUser(userId: string, reason?: string): void`: Bans a user from the channel identified by the provided `userId`. Optionally, you can provide a `reason` for the ban.
|
|
238
|
+
|
|
239
|
+
- `trackPresence(userId: string, presence: PondPresence): void`: Tracks a user's presence in the channel identified by the provided `userId`.
|
|
240
|
+
|
|
241
|
+
- `removePresence(userId: string): void`: Removes a user's presence from the channel identified by the provided `userId`.
|
|
242
|
+
|
|
243
|
+
- `updatePresence(userId: string, presence: PondPresence): void`: Updates a user's presence in the channel identified by the provided `userId`.
|
|
244
|
+
|
|
245
|
+
### PondClient
|
|
246
|
+
|
|
247
|
+
The `PondClient` class represents a client that connects to the PondSocket server.
|
|
248
|
+
|
|
249
|
+
**Constructor:**
|
|
250
|
+
|
|
251
|
+
- `constructor(endpoint: string, params?: Record<string, any>)`: Creates a new instance of the PondClient with the provided endpoint URL and optional parameters.
|
|
252
|
+
|
|
253
|
+
**Methods:**
|
|
254
|
+
|
|
255
|
+
- `connect(backoff?: number): void`: Connects to the server with an optional backoff time.
|
|
256
|
+
|
|
257
|
+
- `getState(): boolean`: Returns the current state of the socket.
|
|
258
|
+
|
|
259
|
+
- `disconnect(): void`: Disconnects the socket.
|
|
260
|
+
|
|
261
|
+
- `createChannel(name: string, params?: JoinParams): Channel`: Creates a channel with the given name and optional join parameters.
|
|
262
|
+
|
|
263
|
+
- `onConnectionChange(callback: (state: boolean) => void): Unsubscribe`: Subscribes to the connection state changes and calls the provided callback when the state changes.
|
|
264
|
+
|
|
265
|
+
### Channel
|
|
266
|
+
|
|
267
|
+
The `Channel` class represents a channel in the PondSocket server.
|
|
268
|
+
|
|
269
|
+
**Methods:**
|
|
270
|
+
|
|
271
|
+
- `join(): void`: Connects to the channel.
|
|
272
|
+
|
|
273
|
+
- `leave(): void`: Disconnects from the channel.
|
|
274
|
+
|
|
275
|
+
- `onMessage(callback: (event: string, message: PondMessage) => void): Unsubscribe`: Monitors the channel for messages and calls the provided callback when a message is received.
|
|
276
|
+
|
|
277
|
+
- `onMessageEvent(event: string, callback: (message: PondMessage) => void): Unsubscribe`: Monitors the channel for messages with the specified event and calls the provided callback when a message is received.
|
|
278
|
+
|
|
279
|
+
- `onChannelStateChange(callback: (connected: ChannelState) => void): Unsubscribe`: Monitors the channel state of the channel and calls the provided callback when the connection state changes.
|
|
280
|
+
|
|
281
|
+
- `onJoin(callback: (presence: PondPresence) => void): Unsubscribe`: Detects when clients join the channel and calls the provided callback when a client joins the channel.
|
|
282
|
+
|
|
283
|
+
- `onLeave(callback: (presence: PondPresence) => void): Unsubscribe`: Detects when clients leave the channel and calls the provided callback when a client leaves the channel.
|
|
284
|
+
|
|
285
|
+
- `onPresenceChange(callback: (presence: PresencePayload) => void): Unsubscribe`: Detects when clients change their presence in the channel and calls the provided callback when a client changes their presence in the channel.
|
|
286
|
+
|
|
287
|
+
- `sendMessage(event: string, payload: PondMessage, recipient: string[]): void`: Sends a message to specific clients in the channel with the specified event, payload, and recipient.
|
|
288
|
+
|
|
289
|
+
- `broadcastFrom(event: string, payload: PondMessage): void`: Broadcasts a message to every other client in the channel except yourself with the specified event and payload.
|
|
290
|
+
|
|
291
|
+
- `broadcast(event: string, payload: PondMessage): void`: Broadcasts a message to the channel, including yourself, with the specified event and payload.
|
|
292
|
+
|
|
293
|
+
- `getPresence(): PondPresence[]`: Gets the current presence of the channel.
|
|
294
|
+
|
|
295
|
+
- `onUsersChange(callback: (users: PondPresence[]) => void): Unsubscribe`: Monitors the presence of the channel and calls the provided callback when the presence changes.
|
|
296
|
+
|
|
297
|
+
- `isConnected(): boolean`: Gets the current connection state of the channel.
|
|
298
|
+
|
|
299
|
+
- `onConnectionChange(callback: (connected: boolean) => void): Unsubscribe`: Monitors the connection state of the channel and calls the provided callback when the connection state changes.
|
|
300
|
+
|
|
301
|
+
## Conclusion
|
|
302
|
+
|
|
303
|
+
PondSocket is a powerful and versatile solution for building real-time applications that require efficient bidirectional communication between server and client components. Its minimalist design and comprehensive feature set make it an excellent choice for WebSocket-based projects, providing developers with a straightforward and reliable tool for building real-time communication systems. With the Node.js client, it also allows for easy communication between multiple server instances, expanding its capabilities even further.
|
package/client.js
CHANGED
|
@@ -95,7 +95,6 @@ class PondClient {
|
|
|
95
95
|
return this._connectionState.subscribe(callback);
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
exports.default = PondClient;
|
|
99
98
|
_PondClient_channels = new WeakMap(), _PondClient_instances = new WeakSet(), _PondClient_createPublisher = function _PondClient_createPublisher() {
|
|
100
99
|
return (message) => {
|
|
101
100
|
if (this._connectionState.value) {
|
|
@@ -103,3 +102,4 @@ _PondClient_channels = new WeakMap(), _PondClient_instances = new WeakSet(), _Po
|
|
|
103
102
|
}
|
|
104
103
|
};
|
|
105
104
|
};
|
|
105
|
+
exports.default = PondClient;
|
package/enums.js
CHANGED
|
@@ -6,20 +6,20 @@ var PresenceEventTypes;
|
|
|
6
6
|
PresenceEventTypes["JOIN"] = "JOIN";
|
|
7
7
|
PresenceEventTypes["LEAVE"] = "LEAVE";
|
|
8
8
|
PresenceEventTypes["UPDATE"] = "UPDATE";
|
|
9
|
-
})(PresenceEventTypes
|
|
9
|
+
})(PresenceEventTypes || (exports.PresenceEventTypes = PresenceEventTypes = {}));
|
|
10
10
|
var ServerActions;
|
|
11
11
|
(function (ServerActions) {
|
|
12
12
|
ServerActions["PRESENCE"] = "PRESENCE";
|
|
13
13
|
ServerActions["SYSTEM"] = "SYSTEM";
|
|
14
14
|
ServerActions["BROADCAST"] = "BROADCAST";
|
|
15
15
|
ServerActions["ERROR"] = "ERROR";
|
|
16
|
-
})(ServerActions
|
|
16
|
+
})(ServerActions || (exports.ServerActions = ServerActions = {}));
|
|
17
17
|
var ClientActions;
|
|
18
18
|
(function (ClientActions) {
|
|
19
19
|
ClientActions["JOIN_CHANNEL"] = "JOIN_CHANNEL";
|
|
20
20
|
ClientActions["LEAVE_CHANNEL"] = "LEAVE_CHANNEL";
|
|
21
21
|
ClientActions["BROADCAST"] = "BROADCAST";
|
|
22
|
-
})(ClientActions
|
|
22
|
+
})(ClientActions || (exports.ClientActions = ClientActions = {}));
|
|
23
23
|
var ChannelState;
|
|
24
24
|
(function (ChannelState) {
|
|
25
25
|
ChannelState["IDLE"] = "IDLE";
|
|
@@ -27,7 +27,7 @@ var ChannelState;
|
|
|
27
27
|
ChannelState["JOINED"] = "JOINED";
|
|
28
28
|
ChannelState["STALLED"] = "STALLED";
|
|
29
29
|
ChannelState["CLOSED"] = "CLOSED";
|
|
30
|
-
})(ChannelState
|
|
30
|
+
})(ChannelState || (exports.ChannelState = ChannelState = {}));
|
|
31
31
|
var ErrorTypes;
|
|
32
32
|
(function (ErrorTypes) {
|
|
33
33
|
ErrorTypes["UNAUTHORIZED_CONNECTION"] = "UNAUTHORIZED_CONNECTION";
|
|
@@ -39,18 +39,18 @@ var ErrorTypes;
|
|
|
39
39
|
ErrorTypes["CHANNEL_ERROR"] = "CHANNEL_ERROR";
|
|
40
40
|
ErrorTypes["ENDPOINT_ERROR"] = "ENDPOINT_ERROR";
|
|
41
41
|
ErrorTypes["INTERNAL_SERVER_ERROR"] = "INTERNAL_SERVER_ERROR";
|
|
42
|
-
})(ErrorTypes
|
|
42
|
+
})(ErrorTypes || (exports.ErrorTypes = ErrorTypes = {}));
|
|
43
43
|
var SystemSender;
|
|
44
44
|
(function (SystemSender) {
|
|
45
45
|
SystemSender["ENDPOINT"] = "ENDPOINT";
|
|
46
46
|
SystemSender["CHANNEL"] = "CHANNEL";
|
|
47
|
-
})(SystemSender
|
|
47
|
+
})(SystemSender || (exports.SystemSender = SystemSender = {}));
|
|
48
48
|
var ChannelReceiver;
|
|
49
49
|
(function (ChannelReceiver) {
|
|
50
50
|
ChannelReceiver["ALL_USERS"] = "ALL_USERS";
|
|
51
51
|
ChannelReceiver["ALL_EXCEPT_SENDER"] = "ALL_EXCEPT_SENDER";
|
|
52
|
-
})(ChannelReceiver
|
|
52
|
+
})(ChannelReceiver || (exports.ChannelReceiver = ChannelReceiver = {}));
|
|
53
53
|
var Events;
|
|
54
54
|
(function (Events) {
|
|
55
55
|
Events["ACKNOWLEDGE"] = "ACKNOWLEDGE";
|
|
56
|
-
})(Events
|
|
56
|
+
})(Events || (exports.Events = Events = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eleven-am/pondsocket",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.65",
|
|
4
4
|
"description": "PondSocket is a fast simple socket server",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"socket",
|
|
@@ -22,30 +22,30 @@
|
|
|
22
22
|
},
|
|
23
23
|
"author": "Roy OSSAI",
|
|
24
24
|
"license": "GPL-3.0",
|
|
25
|
-
"main": "index.js",
|
|
26
|
-
"types": "index.d.ts",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
29
|
"url": "git+https://github.com/Eleven-am/pondSocket.git"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"websocket": "^1.0.34",
|
|
33
|
-
"ws": "^8.
|
|
33
|
+
"ws": "^8.13.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/express": "^4.17.
|
|
37
|
-
"@types/jest": "^29.5.
|
|
38
|
-
"@types/node": "^
|
|
36
|
+
"@types/express": "^4.17.17",
|
|
37
|
+
"@types/jest": "^29.5.3",
|
|
38
|
+
"@types/node": "^20.4.4",
|
|
39
39
|
"@types/websocket": "^1.0.5",
|
|
40
|
-
"@types/ws": "^8.5.
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
42
|
-
"eslint": "^8.
|
|
40
|
+
"@types/ws": "^8.5.5",
|
|
41
|
+
"@typescript-eslint/eslint-plugin": "^6.1.0",
|
|
42
|
+
"eslint": "^8.45.0",
|
|
43
43
|
"eslint-plugin-file-progress": "^1.3.0",
|
|
44
44
|
"eslint-plugin-import": "^2.27.5",
|
|
45
|
-
"jest": "^29.
|
|
45
|
+
"jest": "^29.6.1",
|
|
46
46
|
"superwstest": "^2.0.3",
|
|
47
|
-
"ts-jest": "^29.1.
|
|
47
|
+
"ts-jest": "^29.1.1",
|
|
48
48
|
"ts-node": "^10.9.1",
|
|
49
|
-
"typescript": "^
|
|
49
|
+
"typescript": "^5.1.6"
|
|
50
50
|
}
|
|
51
51
|
}
|
package/types.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { WebSocketServer } from 'ws';
|
|
|
4
4
|
|
|
5
5
|
type Unsubscribe = () => void;
|
|
6
6
|
|
|
7
|
-
export type default_t<T = any> = Record<string, T>;
|
|
8
7
|
type IsParam<Path> = Path extends `:${infer Param}` ? Param : never;
|
|
9
8
|
|
|
10
9
|
type FilteredParams<Path> = Path extends `${infer First}/${infer Second}`
|
|
@@ -22,7 +21,12 @@ type EventParams<Path> = {
|
|
|
22
21
|
params: Params<Path>;
|
|
23
22
|
}
|
|
24
23
|
|
|
25
|
-
type
|
|
24
|
+
type Primitives = number | string | boolean | null | undefined;
|
|
25
|
+
|
|
26
|
+
type PondObject = {
|
|
27
|
+
[key: string]: Primitives | PondObject | PondObject[];
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
type PondPresence = PondObject;
|
|
27
31
|
type PondMessage = PondObject;
|
|
28
32
|
type PondAssigns = PondObject;
|
|
@@ -52,13 +56,6 @@ type IncomingConnection<Path> = EventParams<Path> & {
|
|
|
52
56
|
address: string;
|
|
53
57
|
}
|
|
54
58
|
|
|
55
|
-
interface LeaveEvent {
|
|
56
|
-
userId: string;
|
|
57
|
-
assigns: PondAssigns;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
type LeaveCallback = (event: LeaveEvent) => void;
|
|
61
|
-
|
|
62
59
|
interface UserData {
|
|
63
60
|
assigns: PondAssigns;
|
|
64
61
|
presence: PondPresence;
|
|
@@ -482,12 +479,6 @@ export declare class PondChannel {
|
|
|
482
479
|
*});
|
|
483
480
|
*/
|
|
484
481
|
broadcast (event: string, payload: PondMessage, channelName?: string): void;
|
|
485
|
-
|
|
486
|
-
/**
|
|
487
|
-
* @desc Handles the leave event for a user, can occur when a user disconnects or leaves a channel, use this to clean up any resources
|
|
488
|
-
* @param callback - The callback to execute when a user leaves
|
|
489
|
-
*/
|
|
490
|
-
public onLeave (callback: LeaveCallback): void;
|
|
491
482
|
}
|
|
492
483
|
|
|
493
484
|
declare class PondSocket {
|