@eleven-am/pondsocket 0.1.16 → 0.1.18

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.
Files changed (39) hide show
  1. package/{dist/client → client}/channel.js +13 -15
  2. package/client.d.ts +4 -0
  3. package/{dist/client/index.js → client.js} +2 -2
  4. package/enums.d.ts +19 -0
  5. package/enums.js +22 -0
  6. package/express.d.ts +3 -0
  7. package/{dist/express/index.js → express.js} +1 -1
  8. package/index.d.ts +3 -0
  9. package/package.json +3 -18
  10. package/{dist/index.d.ts → types.d.ts} +184 -2
  11. package/dist/client/index.d.ts +0 -122
  12. package/dist/express/index.d.ts +0 -36
  13. /package/{dist/index.js → index.js} +0 -0
  14. /package/{dist/server → server}/abstracts/abstractRequest.js +0 -0
  15. /package/{dist/server → server}/abstracts/abstractRequest.test.js +0 -0
  16. /package/{dist/server → server}/abstracts/abstractResponse.js +0 -0
  17. /package/{dist/server → server}/abstracts/middleware.js +0 -0
  18. /package/{dist/server → server}/abstracts/middleware.test.js +0 -0
  19. /package/{dist/server → server}/channel/channelEngine.js +0 -0
  20. /package/{dist/server → server}/channel/channelEngine.test.js +0 -0
  21. /package/{dist/server → server}/channel/channelRequest.test.js +0 -0
  22. /package/{dist/server → server}/channel/channelResponse.test.js +0 -0
  23. /package/{dist/server → server}/channel/eventRequest.js +0 -0
  24. /package/{dist/server → server}/channel/eventResponse.js +0 -0
  25. /package/{dist/server → server}/endpoint/connectionResponse.js +0 -0
  26. /package/{dist/server → server}/endpoint/endpoint.js +0 -0
  27. /package/{dist/server → server}/endpoint/endpoint.test.js +0 -0
  28. /package/{dist/server → server}/endpoint/endpointResponse.test.js +0 -0
  29. /package/{dist/server → server}/pondChannel/joinRequest.js +0 -0
  30. /package/{dist/server → server}/pondChannel/joinResponse.js +0 -0
  31. /package/{dist/server → server}/pondChannel/pondChannel.js +0 -0
  32. /package/{dist/server → server}/pondChannel/pondChannelResponse.test.js +0 -0
  33. /package/{dist/server → server}/presence/presenceEngine.js +0 -0
  34. /package/{dist/server → server}/presence/presenceEngine.test.js +0 -0
  35. /package/{dist/server → server}/server/pondSocket.js +0 -0
  36. /package/{dist/server → server}/server/server.test.js +0 -0
  37. /package/{dist/server → server}/utils/matchPattern.js +0 -0
  38. /package/{dist/server → server}/utils/matchPattern.test.js +0 -0
  39. /package/{dist/server → server}/utils/subjectUtils.js +0 -0
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Channel = void 0;
4
- const channelEngine_1 = require("../server/channel/channelEngine");
5
- const endpoint_1 = require("../server/endpoint/endpoint");
6
- const presenceEngine_1 = require("../server/presence/presenceEngine");
4
+ const enums_1 = require("../enums");
7
5
  const subjectUtils_1 = require("../server/utils/subjectUtils");
8
6
  class Channel {
9
7
  constructor(publisher, clientState, name, receiver, params = {}) {
@@ -26,9 +24,9 @@ class Channel {
26
24
  throw new Error('This channel has been closed');
27
25
  }
28
26
  const joinMessage = {
29
- action: endpoint_1.ClientActions.JOIN_CHANNEL,
27
+ action: enums_1.ClientActions.JOIN_CHANNEL,
30
28
  channelName: this._name,
31
- event: endpoint_1.ClientActions.JOIN_CHANNEL,
29
+ event: enums_1.ClientActions.JOIN_CHANNEL,
32
30
  payload: this._joinParams,
33
31
  };
34
32
  this._publish(joinMessage);
@@ -38,9 +36,9 @@ class Channel {
38
36
  */
39
37
  leave() {
40
38
  const leaveMessage = {
41
- action: endpoint_1.ClientActions.LEAVE_CHANNEL,
39
+ action: enums_1.ClientActions.LEAVE_CHANNEL,
42
40
  channelName: this._name,
43
- event: endpoint_1.ClientActions.LEAVE_CHANNEL,
41
+ event: enums_1.ClientActions.LEAVE_CHANNEL,
44
42
  payload: {},
45
43
  };
46
44
  this._publish(leaveMessage);
@@ -54,7 +52,7 @@ class Channel {
54
52
  */
55
53
  onMessage(event, callback) {
56
54
  return this._receiver.subscribe((data) => {
57
- if (data.action === channelEngine_1.ServerActions.BROADCAST && data.event === event && data.channelName === this._name) {
55
+ if (data.action === enums_1.ServerActions.BROADCAST && data.event === event && data.channelName === this._name) {
58
56
  return callback(data.payload);
59
57
  }
60
58
  });
@@ -74,7 +72,7 @@ class Channel {
74
72
  */
75
73
  onJoin(callback) {
76
74
  return this._receiver.subscribe((data) => {
77
- if (data.action === channelEngine_1.ServerActions.PRESENCE && data.event === presenceEngine_1.PresenceEventTypes.JOIN && data.channelName === this._name) {
75
+ if (data.action === enums_1.ServerActions.PRESENCE && data.event === enums_1.PresenceEventTypes.JOIN && data.channelName === this._name) {
78
76
  return callback(data.payload.changed);
79
77
  }
80
78
  });
@@ -85,7 +83,7 @@ class Channel {
85
83
  */
86
84
  onLeave(callback) {
87
85
  return this._receiver.subscribe((data) => {
88
- if (data.action === channelEngine_1.ServerActions.PRESENCE && data.event === presenceEngine_1.PresenceEventTypes.LEAVE && data.channelName === this._name) {
86
+ if (data.action === enums_1.ServerActions.PRESENCE && data.event === enums_1.PresenceEventTypes.LEAVE && data.channelName === this._name) {
89
87
  return callback(data.payload.changed);
90
88
  }
91
89
  });
@@ -96,7 +94,7 @@ class Channel {
96
94
  */
97
95
  onPresenceChange(callback) {
98
96
  return this._receiver.subscribe((data) => {
99
- if (data.action === channelEngine_1.ServerActions.PRESENCE && data.event === presenceEngine_1.PresenceEventTypes.UPDATE && data.channelName === this._name) {
97
+ if (data.action === enums_1.ServerActions.PRESENCE && data.event === enums_1.PresenceEventTypes.UPDATE && data.channelName === this._name) {
100
98
  return callback(data.payload);
101
99
  }
102
100
  });
@@ -155,7 +153,7 @@ class Channel {
155
153
  }
156
154
  _send(event, payload, receivers = 'all_users') {
157
155
  const message = {
158
- action: endpoint_1.ClientActions.BROADCAST,
156
+ action: enums_1.ClientActions.BROADCAST,
159
157
  channelName: this._name,
160
158
  event,
161
159
  payload,
@@ -174,9 +172,9 @@ class Channel {
174
172
  const unsubStateChange = this._clientState.subscribe((state) => {
175
173
  if (state === 'OPEN') {
176
174
  const joinMessage = {
177
- action: endpoint_1.ClientActions.JOIN_CHANNEL,
175
+ action: enums_1.ClientActions.JOIN_CHANNEL,
178
176
  channelName: this._name,
179
- event: endpoint_1.ClientActions.JOIN_CHANNEL,
177
+ event: enums_1.ClientActions.JOIN_CHANNEL,
180
178
  payload: this._joinParams,
181
179
  };
182
180
  this._publisher(joinMessage);
@@ -187,7 +185,7 @@ class Channel {
187
185
  }
188
186
  });
189
187
  const unsubPresence = this._receiver.subscribe((data) => {
190
- if (data.action === channelEngine_1.ServerActions.PRESENCE && data.channelName === this._name) {
188
+ if (data.action === enums_1.ServerActions.PRESENCE && data.channelName === this._name) {
191
189
  this._presence.publish(data.payload.presence);
192
190
  }
193
191
  });
package/client.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ // eslint-disable-next-line import/no-unresolved
2
+ import { PondSocketClient } from './types';
3
+
4
+ export default PondSocketClient;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const channel_1 = require("./channel");
4
- const subjectUtils_1 = require("../server/utils/subjectUtils");
3
+ const channel_1 = require("./client/channel");
4
+ const subjectUtils_1 = require("./server/utils/subjectUtils");
5
5
  class PondClient {
6
6
  constructor(endpoint, params = {}) {
7
7
  let address;
package/enums.d.ts ADDED
@@ -0,0 +1,19 @@
1
+
2
+ export enum PresenceEventTypes {
3
+ JOIN = 'JOIN',
4
+ LEAVE = 'LEAVE',
5
+ UPDATE = 'UPDATE'
6
+ }
7
+
8
+ export enum ServerActions {
9
+ PRESENCE = 'PRESENCE',
10
+ SYSTEM = 'SYSTEM',
11
+ BROADCAST = 'BROADCAST',
12
+ ERROR = 'ERROR',
13
+ }
14
+
15
+ export enum ClientActions {
16
+ JOIN_CHANNEL = 'JOIN_CHANNEL',
17
+ LEAVE_CHANNEL = 'LEAVE_CHANNEL',
18
+ BROADCAST = 'BROADCAST',
19
+ }
package/enums.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ClientActions = exports.ServerActions = exports.PresenceEventTypes = void 0;
4
+ var PresenceEventTypes;
5
+ (function (PresenceEventTypes) {
6
+ PresenceEventTypes["JOIN"] = "JOIN";
7
+ PresenceEventTypes["LEAVE"] = "LEAVE";
8
+ PresenceEventTypes["UPDATE"] = "UPDATE";
9
+ })(PresenceEventTypes = exports.PresenceEventTypes || (exports.PresenceEventTypes = {}));
10
+ var ServerActions;
11
+ (function (ServerActions) {
12
+ ServerActions["PRESENCE"] = "PRESENCE";
13
+ ServerActions["SYSTEM"] = "SYSTEM";
14
+ ServerActions["BROADCAST"] = "BROADCAST";
15
+ ServerActions["ERROR"] = "ERROR";
16
+ })(ServerActions = exports.ServerActions || (exports.ServerActions = {}));
17
+ var ClientActions;
18
+ (function (ClientActions) {
19
+ ClientActions["JOIN_CHANNEL"] = "JOIN_CHANNEL";
20
+ ClientActions["LEAVE_CHANNEL"] = "LEAVE_CHANNEL";
21
+ ClientActions["BROADCAST"] = "BROADCAST";
22
+ })(ClientActions = exports.ClientActions || (exports.ClientActions = {}));
package/express.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { PondSocketFromExpress } from './types';
2
+
3
+ export default PondSocketFromExpress;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const http_1 = require("http");
4
- const pondSocket_1 = require("../server/server/pondSocket");
4
+ const pondSocket_1 = require("./server/server/pondSocket");
5
5
  /**
6
6
  * @desc Creates a pond socket server
7
7
  * @param app - The Express app to be used by the server
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { PondSocket } from './types';
2
+
3
+ export default PondSocket;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eleven-am/pondsocket",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "description": "PondSocket is a fast simple socket server",
5
5
  "keywords": [
6
6
  "socket",
@@ -21,11 +21,8 @@
21
21
  },
22
22
  "author": "Roy OSSAI",
23
23
  "license": "GPL-3.0",
24
- "main": "dist/index.js",
25
- "types": "dist/index.d.ts",
26
- "files": [
27
- "dist/**/*"
28
- ],
24
+ "main": "index.js",
25
+ "types": "index.d.ts",
29
26
  "repository": {
30
27
  "type": "git",
31
28
  "url": "git+https://github.com/Eleven-am/pondSocket.git"
@@ -33,18 +30,6 @@
33
30
  "dependencies": {
34
31
  "ws": "^8.12.0"
35
32
  },
36
- "exports": {
37
- ".": "./dist/index.js",
38
- "./express": "./dist/express/index.js",
39
- "./client": "./dist/client/index.js"
40
- },
41
- "typesVersions": {
42
- "*": {
43
- "*": [
44
- "dist/*"
45
- ]
46
- }
47
- },
48
33
  "devDependencies": {
49
34
  "@types/express": "^4.17.14",
50
35
  "@types/jest": "^29.5.0",
@@ -5,6 +5,8 @@ import internal from 'stream';
5
5
  import { Express } from 'express';
6
6
  import { WebSocketServer, WebSocket } from 'ws';
7
7
 
8
+ import { ClientActions, PresenceEventTypes } from './enums.d';
9
+
8
10
  export type PondPath = string | RegExp;
9
11
  type NextFunction = () => void;
10
12
  export type JoinParams = Record<string, any>;
@@ -15,7 +17,29 @@ export type EndpointHandler = (req: IncomingConnection, res: ConnectionResponse)
15
17
  type SocketCache = Pick<RequestCache, 'socket' | 'clientId' | 'assigns'>;
16
18
  type AuthorizeMiddleware = (request: JoinRequest, response: JoinResponse) => void | Promise<void>;
17
19
  type SocketMiddlewareFunction = (req: IncomingMessage, socket: internal.Duplex, head: Buffer, next: NextFunction) => void;
20
+ export type ChannelReceivers = 'all_users' | 'all_except_sender' | string[];
21
+ export type ChannelSenders = 'channel' | string;
22
+ export type ChannelEvent = Event | PresenceEvent;
18
23
 
24
+ interface Event {
25
+ action: 'SYSTEM' | 'BROADCAST' | 'ERROR';
26
+ event: string;
27
+ payload: PondMessage;
28
+ channelName: string;
29
+ }
30
+ export interface ClientMessage {
31
+ action: ClientActions;
32
+ channelName: string;
33
+ event: string;
34
+ payload: Record<string, any>;
35
+ addresses?: ChannelReceivers;
36
+ }
37
+ interface PresenceEvent {
38
+ action: 'PRESENCE';
39
+ event: PresenceEventTypes;
40
+ channelName: string;
41
+ payload: PresencePayload;
42
+ }
19
43
  interface RequestCache {
20
44
  clientId: string;
21
45
  socket: WebSocket;
@@ -50,6 +74,158 @@ interface UserPresences {
50
74
  [userId: string]: PondPresence;
51
75
  }
52
76
 
77
+ declare global {
78
+ // eslint-disable-next-line @typescript-eslint/no-namespace
79
+ namespace Express {
80
+ export interface Application {
81
+ upgrade(path: PondPath, handler: EndpointHandler): Endpoint;
82
+ }
83
+ }
84
+ }
85
+
86
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
87
+ // @ts-ignore
88
+ interface PondSocketExpressApp extends Express {
89
+
90
+ /**
91
+ * @desc Accepts a new socket upgrade request on the provided endpoint using the handler function to authenticate the socket
92
+ * @param path - the pattern to accept || can also be a regex
93
+ * @param handler - the handler function to authenticate the socket
94
+ * @example
95
+ * const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
96
+ * const token = req.query.token;
97
+ * if (!token)
98
+ * return res.reject("No token provided");
99
+ * res.accept({
100
+ * assign: {
101
+ * token
102
+ * }
103
+ * });
104
+ * })
105
+ */
106
+ upgrade(path: PondPath, handler: EndpointHandler): Endpoint;
107
+ }
108
+ export type PondState = 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';
109
+ type Unsubscribe = () => void;
110
+
111
+ export interface PresencePayload {
112
+ changed: PondPresence;
113
+ presence: PondPresence[];
114
+ }
115
+
116
+ export declare class Channel {
117
+ /**
118
+ * @desc Connects to the channel.
119
+ */
120
+ public join(): void;
121
+
122
+ /**
123
+ * @desc Disconnects from the channel.
124
+ */
125
+ public leave(): void;
126
+
127
+ /**
128
+ * @desc Monitors the channel for messages.
129
+ * @param event - The event to monitor.
130
+ * @param callback - The callback to call when a message is received.
131
+ */
132
+ public onMessage(event: string, callback: (message: PondMessage) => void): Unsubscribe;
133
+
134
+ /**
135
+ * @desc Monitors the connection state of the channel.
136
+ * @param callback - The callback to call when the connection state changes.
137
+ */
138
+ public onConnectionChange(callback: (connected: boolean) => void): Unsubscribe;
139
+
140
+ /**
141
+ * @desc Detects when clients join the channel.
142
+ * @param callback - The callback to call when a client joins the channel.
143
+ */
144
+ public onJoin(callback: (presence: PondPresence) => void): Unsubscribe;
145
+
146
+ /**
147
+ * @desc Detects when clients leave the channel.
148
+ * @param callback - The callback to call when a client leaves the channel.
149
+ */
150
+ public onLeave(callback: (presence: PondPresence) => void): Unsubscribe;
151
+
152
+ /**
153
+ * @desc Detects when clients change their presence in the channel.
154
+ * @param callback - The callback to call when a client changes their presence in the channel.
155
+ */
156
+ public onPresenceChange(callback: (presence: PresencePayload) => void): Unsubscribe;
157
+
158
+ /**
159
+ * @desc Sends a message to specific clients in the channel.
160
+ * @param event - The event to send.
161
+ * @param payload - The message to send.
162
+ * @param recipient - The clients to send the message to.
163
+ */
164
+ public sendMessage(event: string, payload: PondMessage, recipient: string[]): void;
165
+
166
+ /**
167
+ * @desc Broadcasts a message to every other client in the channel except yourself.
168
+ * @param event - The event to send.
169
+ * @param payload - The message to send.
170
+ */
171
+ public broadcastFrom(event: string, payload: PondMessage): void;
172
+
173
+ /**
174
+ * @desc Broadcasts a message to the channel, including yourself.
175
+ * @param event - The event to send.
176
+ * @param payload - The message to send.
177
+ */
178
+ public broadcast(event: string, payload: PondMessage): void;
179
+
180
+ /**
181
+ * @desc Gets the current connection state of the channel.
182
+ */
183
+ public isConnected(): boolean;
184
+
185
+
186
+ /**
187
+ * @desc check is the channel has been closed.
188
+ */
189
+ public hasClosed(): boolean;
190
+
191
+ /**
192
+ * @desc Gets the current presence of the channel.
193
+ */
194
+ public getPresence(): PondPresence[];
195
+
196
+ /**
197
+ * @desc Monitors the presence of the channel.
198
+ * @param callback - The callback to call when the presence changes.
199
+ */
200
+ public onUsersChange(callback: (users: PondPresence[]) => void): Unsubscribe;
201
+ }
202
+
203
+ export declare class PondSocketClient {
204
+ constructor(endpoint: string, params?: Record<string, any>);
205
+
206
+ /**
207
+ * @desc Connects to the server and returns the socket.
208
+ */
209
+ public connect(backoff?: number): void;
210
+
211
+ /**
212
+ * @desc Returns the current state of the socket.
213
+ */
214
+ public getState(): PondState;
215
+
216
+ /**
217
+ * @desc Disconnects the socket.
218
+ */
219
+ public disconnect(): void;
220
+
221
+ /**
222
+ * @desc Creates a channel with the given name and params.
223
+ * @param name - The name of the channel.
224
+ * @param params - The params to send to the server.
225
+ */
226
+ public createChannel(name: string, params?: JoinParams): Channel;
227
+ }
228
+
53
229
  declare class AbstractRequest {
54
230
  get event (): EventObject;
55
231
 
@@ -296,7 +472,7 @@ export declare class Endpoint {
296
472
  closeConnection (clientIds: string | string[]): void;
297
473
  }
298
474
 
299
- declare class PondSocket {
475
+ export declare class PondSocket {
300
476
  constructor (server?: HTTPServer, socketServer?: WebSocketServer);
301
477
 
302
478
  /**
@@ -337,4 +513,10 @@ declare class PondSocket {
337
513
  use (middleware: SocketMiddlewareFunction): void;
338
514
  }
339
515
 
340
- export default PondSocket;
516
+ /**
517
+ * @desc Creates a pond socket server
518
+ * @param app - The Express app to be used by the server
519
+ * @constructor
520
+ */
521
+ export declare const PondSocketFromExpress: (app: Express) => PondSocketExpressApp;
522
+
@@ -1,122 +0,0 @@
1
- // eslint-disable-next-line import/no-unresolved
2
- import { PondMessage, JoinParams, PondPresence } from '../index';
3
- export type PondState = 'CONNECTING' | 'OPEN' | 'CLOSING' | 'CLOSED';
4
- type Unsubscribe = () => void;
5
-
6
- export interface PresencePayload {
7
- changed: PondPresence;
8
- presence: PondPresence[];
9
- }
10
-
11
- export declare class Channel {
12
- /**
13
- * @desc Connects to the channel.
14
- */
15
- public join(): void;
16
-
17
- /**
18
- * @desc Disconnects from the channel.
19
- */
20
- public leave(): void;
21
-
22
- /**
23
- * @desc Monitors the channel for messages.
24
- * @param event - The event to monitor.
25
- * @param callback - The callback to call when a message is received.
26
- */
27
- public onMessage(event: string, callback: (message: PondMessage) => void): Unsubscribe;
28
-
29
- /**
30
- * @desc Monitors the connection state of the channel.
31
- * @param callback - The callback to call when the connection state changes.
32
- */
33
- public onConnectionChange(callback: (connected: boolean) => void): Unsubscribe;
34
-
35
- /**
36
- * @desc Detects when clients join the channel.
37
- * @param callback - The callback to call when a client joins the channel.
38
- */
39
- public onJoin(callback: (presence: PondPresence) => void): Unsubscribe;
40
-
41
- /**
42
- * @desc Detects when clients leave the channel.
43
- * @param callback - The callback to call when a client leaves the channel.
44
- */
45
- public onLeave(callback: (presence: PondPresence) => void): Unsubscribe;
46
-
47
- /**
48
- * @desc Detects when clients change their presence in the channel.
49
- * @param callback - The callback to call when a client changes their presence in the channel.
50
- */
51
- public onPresenceChange(callback: (presence: PresencePayload) => void): Unsubscribe;
52
-
53
- /**
54
- * @desc Sends a message to specific clients in the channel.
55
- * @param event - The event to send.
56
- * @param payload - The message to send.
57
- * @param recipient - The clients to send the message to.
58
- */
59
- public sendMessage(event: string, payload: PondMessage, recipient: string[]): void;
60
-
61
- /**
62
- * @desc Broadcasts a message to every other client in the channel except yourself.
63
- * @param event - The event to send.
64
- * @param payload - The message to send.
65
- */
66
- public broadcastFrom(event: string, payload: PondMessage): void;
67
-
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
- public broadcast(event: string, payload: PondMessage): void;
74
-
75
- /**
76
- * @desc Gets the current connection state of the channel.
77
- */
78
- public isConnected(): boolean;
79
-
80
-
81
- /**
82
- * @desc check is the channel has been closed.
83
- */
84
- public hasClosed(): boolean;
85
-
86
- /**
87
- * @desc Gets the current presence of the channel.
88
- */
89
- public getPresence(): PondPresence[];
90
-
91
- /**
92
- * @desc Monitors the presence of the channel.
93
- * @param callback - The callback to call when the presence changes.
94
- */
95
- public onUsersChange(callback: (users: PondPresence[]) => void): Unsubscribe;
96
- }
97
-
98
- export default class PondClient {
99
- constructor(endpoint: string, params?: Record<string, any>);
100
-
101
- /**
102
- * @desc Connects to the server and returns the socket.
103
- */
104
- public connect(backoff?: number): void;
105
-
106
- /**
107
- * @desc Returns the current state of the socket.
108
- */
109
- public getState(): PondState;
110
-
111
- /**
112
- * @desc Disconnects the socket.
113
- */
114
- public disconnect(): void;
115
-
116
- /**
117
- * @desc Creates a channel with the given name and params.
118
- * @param name - The name of the channel.
119
- * @param params - The params to send to the server.
120
- */
121
- public createChannel(name: string, params?: JoinParams): Channel;
122
- }
@@ -1,36 +0,0 @@
1
- /* eslint-disable import/no-unresolved */
2
- import { Express } from 'express';
3
-
4
- import { EndpointHandler, Endpoint, PondPath } from '../index';
5
-
6
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
7
- // @ts-ignore
8
- interface PondSocketExpressApp extends Express {
9
-
10
- /**
11
- * @desc Accepts a new socket upgrade request on the provided endpoint using the handler function to authenticate the socket
12
- * @param path - the pattern to accept || can also be a regex
13
- * @param handler - the handler function to authenticate the socket
14
- * @example
15
- * const endpoint = pond.createEndpoint('/api/socket', (req, res) => {
16
- * const token = req.query.token;
17
- * if (!token)
18
- * return res.reject("No token provided");
19
- * res.accept({
20
- * assign: {
21
- * token
22
- * }
23
- * });
24
- * })
25
- */
26
- upgrade(path: PondPath, handler: EndpointHandler): Endpoint;
27
- }
28
-
29
- /**
30
- * @desc Creates a pond socket server
31
- * @param app - The Express app to be used by the server
32
- * @constructor
33
- */
34
- declare const PondSocket: (app: Express) => PondSocketExpressApp;
35
-
36
- export default PondSocket;
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes