@socket-mesh/server 17.3.5 → 17.3.6
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/package.json +1 -1
- package/server-options.d.ts +0 -3
- package/server.js +11 -8
package/package.json
CHANGED
package/server-options.d.ts
CHANGED
|
@@ -7,9 +7,6 @@ import { AuthEngine } from "@socket-mesh/server-auth";
|
|
|
7
7
|
export type ProtocolVersions = 1 | 2;
|
|
8
8
|
export interface ServerOptions {
|
|
9
9
|
httpServer?: HttpServer;
|
|
10
|
-
wsEngine?: string | {
|
|
11
|
-
Server: ws.Server;
|
|
12
|
-
};
|
|
13
10
|
wsEngineServerOptions?: ws.ServerOptions;
|
|
14
11
|
authKey?: jwt.Secret;
|
|
15
12
|
perMessageDeflate?: boolean | ws.PerMessageDeflateOptions;
|
package/server.js
CHANGED
|
@@ -22,6 +22,7 @@ import { InvalidArgumentsError, InvalidOptionsError, InvalidActionError, ServerP
|
|
|
22
22
|
import { MiddlewareType } from "./middleware-type";
|
|
23
23
|
import { MiddlewareStream } from "./middleware-stream";
|
|
24
24
|
import { ActionHandshakeWS } from "./action";
|
|
25
|
+
import ws from "ws";
|
|
25
26
|
import base64id from 'base64id';
|
|
26
27
|
import { ServerSocket } from "./serversocket";
|
|
27
28
|
import url from "url";
|
|
@@ -151,12 +152,14 @@ export class Server extends AsyncStreamEmitter {
|
|
|
151
152
|
this.emit('ready', {});
|
|
152
153
|
}))();
|
|
153
154
|
}
|
|
154
|
-
let wsEngine = typeof opts.wsEngine === 'string' ? require(opts.wsEngine) : opts.wsEngine;
|
|
155
|
-
if (!wsEngine || !wsEngine.Server) {
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
// let wsEngine = typeof opts.wsEngine === 'string' ? require(opts.wsEngine) : opts.wsEngine;
|
|
156
|
+
// if (!wsEngine || !wsEngine.Server) {
|
|
157
|
+
// throw new InvalidOptionsError(
|
|
158
|
+
// 'The wsEngine option must be a path or module name which points ' +
|
|
159
|
+
// 'to a valid WebSocket engine module with a compatible interface'
|
|
160
|
+
// );
|
|
161
|
+
// }
|
|
162
|
+
// let WSServer = wsEngine.Server;
|
|
160
163
|
if (opts.authPrivateKey != null || opts.authPublicKey != null) {
|
|
161
164
|
if (opts.authPrivateKey == null) {
|
|
162
165
|
throw new InvalidOptionsError('The authPrivateKey option must be specified if authPublicKey is specified');
|
|
@@ -207,7 +210,7 @@ export class Server extends AsyncStreamEmitter {
|
|
|
207
210
|
this.clientsCount = 0;
|
|
208
211
|
this.pendingClients = {};
|
|
209
212
|
this.pendingClientsCount = 0;
|
|
210
|
-
|
|
213
|
+
const wsServerOptions = opts.wsEngineServerOptions || {};
|
|
211
214
|
wsServerOptions.server = this.httpServer;
|
|
212
215
|
wsServerOptions.verifyClient = this._verifyHandshake.bind(this);
|
|
213
216
|
if (wsServerOptions.path == null && this._path != null) {
|
|
@@ -225,7 +228,7 @@ export class Server extends AsyncStreamEmitter {
|
|
|
225
228
|
if (wsServerOptions.clientTracking == null) {
|
|
226
229
|
wsServerOptions.clientTracking = false;
|
|
227
230
|
}
|
|
228
|
-
this.wsServer = new
|
|
231
|
+
this.wsServer = new ws.Server(wsServerOptions);
|
|
229
232
|
this.wsServer.on('error', this._handleServerError.bind(this));
|
|
230
233
|
this.wsServer.on('connection', this._handleSocketConnection.bind(this));
|
|
231
234
|
}
|