diff --git a/dist/README.md b/dist/README.md index 1028c7d..f704549 100644 --- a/dist/README.md +++ b/dist/README.md @@ -510,6 +510,9 @@ Mesa's Server component allows for the following configuration to be passed in d { // Optional: port that Mesa should listen on. Defaults to 4000 port: number + // Optional: path that Mesa should listen on. + path: string + // Optional: namespace for Redis events. If you have multiple Mesa instances running on a cluster, you should use this namespace: string diff --git a/dist/package.json b/dist/package.json index bd6ce2d..e77e45a 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "@cryb/mesa", - "version": "1.4.6", + "version": "1.4.7", "description": "A scalable, modern & robust WebSocket wrapper", "main": "index.js", "repository": "https://github.com/crybapp/mesa", diff --git a/dist/server/index.d.ts b/dist/server/index.d.ts index e06778a..ece49a4 100644 --- a/dist/server/index.d.ts +++ b/dist/server/index.d.ts @@ -39,6 +39,7 @@ export interface IAuthenticationConfig { } interface IServerConfig { port?: number; + path?: string; namespace?: string; redis?: RedisConfig; server?: http.Server | https.Server; @@ -59,6 +60,7 @@ declare class Server extends EventEmitter { wss: WebSocket.Server; clients: Client[]; port: number; + path: string; namespace: string; redis: Redis.Redis; publisher: Redis.Redis; diff --git a/dist/server/index.js b/dist/server/index.js index 201e7dd..8a49ac2 100644 --- a/dist/server/index.js +++ b/dist/server/index.js @@ -90,6 +90,8 @@ class Server extends events_1.EventEmitter { options.server = config.server; else options.port = config.port; + if (config.path) + options.path = config.path; this.wss = new ws_1.default.Server(options); this.wss.on('connection', (socket, req) => this.registerConnection(socket, req)); } @@ -98,6 +100,8 @@ class Server extends events_1.EventEmitter { if (!config.port) config.port = 4000; this.port = config.port; + if (config.path) + this.path = config.path; if (config.namespace) this.namespace = config.namespace; if (config.redis) diff --git a/examples/client.js b/examples/client.js index 1f6cf2d..66cb5e7 100644 --- a/examples/client.js +++ b/examples/client.js @@ -9,7 +9,7 @@ const { Client, Message } = require('../dist') const { default: uuid } = require('../dist/utils/uuid.util') -const client = new Client('ws://localhost:4000') +const client = new Client('ws://localhost:4000/ws') client.on('connected', async () => { console.log('Connected to Mesa') diff --git a/examples/server.js b/examples/server.js index dd3acca..1a887cf 100644 --- a/examples/server.js +++ b/examples/server.js @@ -7,6 +7,8 @@ const { default: Mesa, Message } = require('../dist') const mesa = new Mesa({ port: 4000, + path: '/ws', + namespace: 'example' }) diff --git a/src/README.md b/src/README.md index 1028c7d..f704549 100644 --- a/src/README.md +++ b/src/README.md @@ -510,6 +510,9 @@ Mesa's Server component allows for the following configuration to be passed in d { // Optional: port that Mesa should listen on. Defaults to 4000 port: number + // Optional: path that Mesa should listen on. + path: string + // Optional: namespace for Redis events. If you have multiple Mesa instances running on a cluster, you should use this namespace: string diff --git a/src/package.json b/src/package.json index bd6ce2d..e77e45a 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "@cryb/mesa", - "version": "1.4.6", + "version": "1.4.7", "description": "A scalable, modern & robust WebSocket wrapper", "main": "index.js", "repository": "https://github.com/crybapp/mesa", diff --git a/src/server/index.ts b/src/server/index.ts index 79405ce..b49f37c 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -58,6 +58,8 @@ export interface IAuthenticationConfig { interface IServerConfig { port?: number + path?: string + namespace?: string redis?: RedisConfig @@ -85,6 +87,8 @@ class Server extends EventEmitter { public clients: Client[] = [] public port: number + public path: string + public namespace: string public redis: Redis.Redis @@ -203,6 +207,9 @@ class Server extends EventEmitter { else options.port = config.port + if (config.path) + options.path = config.path + this.wss = new WebSocket.Server(options) this.wss.on('connection', (socket, req) => this.registerConnection(socket, req)) } @@ -215,6 +222,9 @@ class Server extends EventEmitter { this.port = config.port + if (config.path) + this.path = config.path + if (config.namespace) this.namespace = config.namespace