Merge pull request #292 from redexp/master
This commit is contained in:
commit
5e3dedcd72
1
index.d.ts
vendored
1
index.d.ts
vendored
@ -26,6 +26,7 @@ declare interface IConfig {
|
|||||||
cert: string;
|
cert: string;
|
||||||
};
|
};
|
||||||
readonly generateClientId?: () => string;
|
readonly generateClientId?: () => string;
|
||||||
|
readonly createWebSocketServer?: (options: WebSocketLib.ServerOptions) => WebSocketLib.Server;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare interface IClient {
|
declare interface IClient {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type {Server, ServerOptions} from 'ws';
|
||||||
|
|
||||||
export interface IConfig {
|
export interface IConfig {
|
||||||
readonly host: string;
|
readonly host: string;
|
||||||
readonly port: number;
|
readonly port: number;
|
||||||
@ -14,6 +16,7 @@ export interface IConfig {
|
|||||||
cert: string;
|
cert: string;
|
||||||
};
|
};
|
||||||
readonly generateClientId?: () => string;
|
readonly generateClientId?: () => string;
|
||||||
|
readonly createWebSocketServer?: (options: ServerOptions) => Server;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultConfig: IConfig = {
|
const defaultConfig: IConfig = {
|
||||||
|
@ -18,7 +18,7 @@ interface IAuthParams {
|
|||||||
key?: string;
|
key?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
type CustomConfig = Pick<IConfig, 'path' | 'key' | 'concurrent_limit'>;
|
type CustomConfig = Pick<IConfig, 'path' | 'key' | 'concurrent_limit' | 'createWebSocketServer'>;
|
||||||
|
|
||||||
const WS_PATH = 'peerjs';
|
const WS_PATH = 'peerjs';
|
||||||
|
|
||||||
@ -40,7 +40,16 @@ export class WebSocketServer extends EventEmitter implements IWebSocketServer {
|
|||||||
const path = this.config.path;
|
const path = this.config.path;
|
||||||
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
this.path = `${path}${path.endsWith('/') ? "" : "/"}${WS_PATH}`;
|
||||||
|
|
||||||
this.socketServer = new WebSocketLib.Server({ path: this.path, server });
|
const options: WebSocketLib.ServerOptions = {
|
||||||
|
path: this.path,
|
||||||
|
server,
|
||||||
|
};
|
||||||
|
|
||||||
|
this.socketServer = (
|
||||||
|
config.createWebSocketServer ?
|
||||||
|
config.createWebSocketServer(options) :
|
||||||
|
new WebSocketLib.Server(options)
|
||||||
|
);
|
||||||
|
|
||||||
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));
|
this.socketServer.on("connection", (socket, req) => this._onSocketConnection(socket, req));
|
||||||
this.socketServer.on("error", (error: Error) => this._onSocketError(error));
|
this.socketServer.on("error", (error: Error) => this._onSocketError(error));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user