createWebSocketServer option
This commit is contained in:
parent
e2854ca9b1
commit
077260a3a4
2
dist/src/instance.js
vendored
2
dist/src/instance.js
vendored
@ -32,8 +32,6 @@ const createInstance = ({ app, server, options }) => {
|
||||
realm,
|
||||
config: customConfig
|
||||
});
|
||||
app.set('peerWs', wss);
|
||||
app.emit('peerWs', wss);
|
||||
wss.on("connection", (client) => {
|
||||
const messageQueue = realm.getMessageQueueById(client.getId());
|
||||
if (messageQueue) {
|
||||
|
8
dist/src/services/webSocketServer/index.js
vendored
8
dist/src/services/webSocketServer/index.js
vendored
@ -18,7 +18,13 @@ class WebSocketServer extends events_1.default {
|
||||
this.config = config;
|
||||
const path = this.config.path;
|
||||
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
||||
this.socketServer = new ws_1.default.Server(Object.assign({ path: this.path, server }, this.config.ws));
|
||||
const options = {
|
||||
path: this.path,
|
||||
server,
|
||||
};
|
||||
this.socketServer = (config.createWebSocketServer ?
|
||||
config.createWebSocketServer(options) :
|
||||
new ws_1.default.Server(options));
|
||||
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));
|
||||
this.socketServer.on("error", (error) => this._onSocketError(error));
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import {ServerOptions as WsConfig} from 'ws';
|
||||
import {Server, ServerOptions} from 'ws';
|
||||
|
||||
export interface IConfig {
|
||||
readonly host: string;
|
||||
@ -16,7 +16,7 @@ export interface IConfig {
|
||||
cert: string;
|
||||
};
|
||||
readonly generateClientId?: () => string;
|
||||
readonly ws?: WsConfig;
|
||||
readonly createWebSocketServer?: (options: ServerOptions) => Server;
|
||||
}
|
||||
|
||||
const defaultConfig: IConfig = {
|
||||
|
@ -45,9 +45,6 @@ export const createInstance = ({ app, server, options }: {
|
||||
config: customConfig
|
||||
});
|
||||
|
||||
app.set('peerWs', wss);
|
||||
app.emit('peerWs', wss);
|
||||
|
||||
wss.on("connection", (client: IClient) => {
|
||||
const messageQueue = realm.getMessageQueueById(client.getId());
|
||||
|
||||
|
@ -18,7 +18,7 @@ interface IAuthParams {
|
||||
key?: string;
|
||||
}
|
||||
|
||||
type CustomConfig = Pick<IConfig, 'path' | 'key' | 'concurrent_limit' | 'ws'>;
|
||||
type CustomConfig = Pick<IConfig, 'path' | 'key' | 'concurrent_limit' | 'createWebSocketServer'>;
|
||||
|
||||
const WS_PATH = 'peerjs';
|
||||
|
||||
@ -40,11 +40,16 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
|
||||
const path = this.config.path;
|
||||
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
||||
|
||||
this.socketServer = new WebSocketLib.Server({
|
||||
const options = {
|
||||
path: this.path,
|
||||
server,
|
||||
...this.config.ws,
|
||||
});
|
||||
};
|
||||
|
||||
this.socketServer = (
|
||||
config.createWebSocketServer ?
|
||||
config.createWebSocketServer(options) :
|
||||
new WebSocketLib.Server(options)
|
||||
);
|
||||
|
||||
this.socketServer.on("connection", (socket: MyWebSocket, req) => this._onSocketConnection(socket, req));
|
||||
this.socketServer.on("error", (error: Error) => this._onSocketError(error));
|
||||
|
Loading…
x
Reference in New Issue
Block a user