From 898582755cfd54c52582b95138bf4ac1d92d836f Mon Sep 17 00:00:00 2001 From: efkan Date: Mon, 27 Feb 2017 15:30:03 +0200 Subject: [PATCH 1/4] Adding namespace.engine.generateId option --- docs/API.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/API.md b/docs/API.md index e9fe058650..c07d943769 100644 --- a/docs/API.md +++ b/docs/API.md @@ -25,6 +25,7 @@ - [namespace.emit(eventName[, ...args])](#namespaceemiteventname-args) - [namespace.clients(callback)](#namespaceclientscallback) - [namespace.use(fn)](#namespaceusefn) + - [namespace.engine.generateId(fn)](#namespaceenginegenerateidfn) - [Event: 'connect'](#event-connect) - [Event: 'connection'](#event-connect) - [Flag: 'volatile'](#flag-volatile) @@ -310,6 +311,22 @@ io.use(function(socket, next){ }); ``` +#### namespace.engine.generateId(fn) + + - `fn` _(Function)_ + +Generates a custom socket id by using `generateId` option of `Engine.io` library. + +The function takes a `req` parameter whis is a node request object. + +```js +var custom_id = 0; +io.engine.generateId = function (req) { + custom_id++; + return "custom:id:" + custom_id; // custom id must be unpredictable and unique +} +``` + #### Event: 'connect' - `error` _(Object)_ error object From 9051113370e3a53434d56df91df08c98c1c669f7 Mon Sep 17 00:00:00 2001 From: efkan Date: Thu, 2 Mar 2017 10:23:32 +0200 Subject: [PATCH 2/4] Update API.md --- docs/API.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/API.md b/docs/API.md index c07d943769..ee127c7221 100644 --- a/docs/API.md +++ b/docs/API.md @@ -5,7 +5,7 @@ - [new Server(httpServer[, options])](#new-serverhttpserver-options) - [new Server(port[, options])](#new-serverport-options) - [new Server(options)](#new-serveroptions) - - [server.sockets](#serversockets) + - [server.sockets](#serversockets) - [server.serveClient([value])](#serverserveclientvalue) - [server.path([value])](#serverpathvalue) - [server.adapter([value])](#serveradaptervalue) @@ -19,13 +19,13 @@ - [server.onconnection(socket)](#serveronconnectionsocket) - [server.of(nsp)](#serverofnsp) - [server.close([callback])](#serverclosecallback) + - [server.engine.generateId(fn)](#serverenginegenerateidfn) - [Class: Namespace](#namespace) - [namespace.name](#namespacename) - [namespace.connected](#namespaceconnected) - [namespace.emit(eventName[, ...args])](#namespaceemiteventname-args) - [namespace.clients(callback)](#namespaceclientscallback) - [namespace.use(fn)](#namespaceusefn) - - [namespace.engine.generateId(fn)](#namespaceenginegenerateidfn) - [Event: 'connect'](#event-connect) - [Event: 'connection'](#event-connect) - [Flag: 'volatile'](#flag-volatile) @@ -226,6 +226,22 @@ server.listen(PORT); // PORT is free to use io = Server(server); ``` +#### server.engine.generateId(fn) + + - `fn` _(Function)_ + +Generates a custom socket id by using `generateId` option of `Engine.io` library. + +The function takes a `req` parameter which is a node request object. + +```js +var custom_id = 0; +io.engine.generateId = function (req) { + custom_id++; + return "custom:id:" + custom_id; // custom id must be unpredictable and unique +} +``` + ### Namespace Represents a pool of sockets connected under a given scope identified @@ -311,22 +327,6 @@ io.use(function(socket, next){ }); ``` -#### namespace.engine.generateId(fn) - - - `fn` _(Function)_ - -Generates a custom socket id by using `generateId` option of `Engine.io` library. - -The function takes a `req` parameter whis is a node request object. - -```js -var custom_id = 0; -io.engine.generateId = function (req) { - custom_id++; - return "custom:id:" + custom_id; // custom id must be unpredictable and unique -} -``` - #### Event: 'connect' - `error` _(Object)_ error object From f8358f1be523ea7ed4e88cd601b3c4eda71b5132 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 29 Mar 2017 13:45:32 +0200 Subject: [PATCH 3/4] minor fix --- docs/API.md | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/docs/API.md b/docs/API.md index ee127c7221..a1cfa865c4 100644 --- a/docs/API.md +++ b/docs/API.md @@ -5,7 +5,8 @@ - [new Server(httpServer[, options])](#new-serverhttpserver-options) - [new Server(port[, options])](#new-serverport-options) - [new Server(options)](#new-serveroptions) - - [server.sockets](#serversockets) + - [server.sockets](#serversockets) + - [server.engine.generateId](#serverenginegenerateidfn) - [server.serveClient([value])](#serverserveclientvalue) - [server.path([value])](#serverpathvalue) - [server.adapter([value])](#serveradaptervalue) @@ -19,7 +20,6 @@ - [server.onconnection(socket)](#serveronconnectionsocket) - [server.of(nsp)](#serverofnsp) - [server.close([callback])](#serverclosecallback) - - [server.engine.generateId(fn)](#serverenginegenerateidfn) - [Class: Namespace](#namespace) - [namespace.name](#namespacename) - [namespace.connected](#namespaceconnected) @@ -226,20 +226,16 @@ server.listen(PORT); // PORT is free to use io = Server(server); ``` -#### server.engine.generateId(fn) +#### server.engine.generateId - - `fn` _(Function)_ - -Generates a custom socket id by using `generateId` option of `Engine.io` library. +Overwrites the default method to generate your custom socket id. -The function takes a `req` parameter which is a node request object. +The function is called with a node request object (`http.IncomingMessage`) as first parameter. ```js -var custom_id = 0; -io.engine.generateId = function (req) { - custom_id++; - return "custom:id:" + custom_id; // custom id must be unpredictable and unique -} +io.engine.generateId = function (req) { + return "custom:id:" + custom_id++; // custom id must be unique +} ``` ### Namespace From e8245dd3321dda431d9675966adf7584a70b69ef Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Wed, 29 Mar 2017 13:50:29 +0200 Subject: [PATCH 4/4] fix link --- docs/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index a1cfa865c4..58795939ab 100644 --- a/docs/API.md +++ b/docs/API.md @@ -6,7 +6,7 @@ - [new Server(port[, options])](#new-serverport-options) - [new Server(options)](#new-serveroptions) - [server.sockets](#serversockets) - - [server.engine.generateId](#serverenginegenerateidfn) + - [server.engine.generateId](#serverenginegenerateid) - [server.serveClient([value])](#serverserveclientvalue) - [server.path([value])](#serverpathvalue) - [server.adapter([value])](#serveradaptervalue)