From 697e6f62dc3c8a131dc6db564f913b4ca0a43d6d Mon Sep 17 00:00:00 2001 From: Sean Williams Date: Wed, 3 Jan 2018 13:21:25 +1100 Subject: [PATCH 1/6] Added new subscriber callback. Updated basic example and readme. --- README.md | 6 ++++++ examples/basic/server.js | 5 ++++- index.js | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10cd4dc..6633d48 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ var app = express(); var longpoll = require("express-longpoll")(app) // You can also enable debug flag for debug messages var longpollWithDebug = require("express-longpoll")(app, { DEBUG: true }); +// You can also specify a function that is called when a new longpoll request is made +var longpollWithDebugAndCallback = require("express-longpoll")(app, { DEBUG: true, + subscriberCallback: function (id){ + console.log (`New subscriber with id: ${id}`); + } + }); ``` **Quick-start code** diff --git a/examples/basic/server.js b/examples/basic/server.js index c26b8da..7974960 100644 --- a/examples/basic/server.js +++ b/examples/basic/server.js @@ -1,7 +1,10 @@ var express = require('express'); var app = express(); const longpoll = require("../../index.js")(app, { - DEBUG: true + DEBUG: true, + subscriberCallback: function (id) { + console.log(`Subscriber Callback with id: ${id}`); + } }); app.use((req, res, next) => { diff --git a/index.js b/index.js index 463e58e..6ef0cc6 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var longpoll = function(app, opts) { // Default Config var config = { DEBUG: false, + subscriberCallback: null, events: { maxListeners: 0 // unlimited } @@ -140,6 +141,11 @@ var longpoll = function(app, opts) { // Create it sub(res); + + // New subscriber callback + if (config.subscriberCallback){ + config.subscriberCallback(req.id || null); + }; }); resolve(); }); From 25cdabcac3848c72c3007054d2c94324553ec311 Mon Sep 17 00:00:00 2001 From: Sean Williams Date: Fri, 4 May 2018 10:35:21 +1000 Subject: [PATCH 2/6] Updated subscriber callback parameters. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 6ef0cc6..71097ec 100644 --- a/index.js +++ b/index.js @@ -144,7 +144,7 @@ var longpoll = function(app, opts) { // New subscriber callback if (config.subscriberCallback){ - config.subscriberCallback(req.id || null); + config.subscriberCallback(req); }; }); resolve(); From 0e52a683887dbeef3dacf96bf6e7b8197a0725ce Mon Sep 17 00:00:00 2001 From: Yehya Awad Date: Fri, 25 Jan 2019 15:05:59 -0500 Subject: [PATCH 3/6] Update package.json update lodash --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ab661c..cdb0998 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "bluebird": "^3.5.0", "eventemitter2": "3.0.0", - "lodash": "4.17.4" + "lodash": ">=4.17.5" }, "devDependencies": { "chai": "^3.5.0", From d771fa88610f8aededfed40850b4be02ddbfa616 Mon Sep 17 00:00:00 2001 From: Nimrod Astrahan Date: Thu, 31 Jan 2019 01:34:03 +0200 Subject: [PATCH 4/6] fix listener leak --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 463e58e..86368d3 100644 --- a/index.js +++ b/index.js @@ -125,7 +125,7 @@ var longpoll = function(app, opts) { eventId = eventId + "." + req.id; // Clear all previous events for the ID, we only need one log("Old Events cleared: ", url, eventId); - dispatcher.removeAllListeners([eventId]); + dispatcher.removeAllListeners(eventId); } // Method that Creates event listener From 6e8de53c991388a3fe36f6b626ddffabdd494e0e Mon Sep 17 00:00:00 2001 From: Sean Williams Date: Wed, 3 Jan 2018 13:21:25 +1100 Subject: [PATCH 5/6] Added new subscriber callback. Updated basic example and readme. --- README.md | 6 ++++++ examples/basic/server.js | 5 ++++- index.js | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 10cd4dc..6633d48 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ var app = express(); var longpoll = require("express-longpoll")(app) // You can also enable debug flag for debug messages var longpollWithDebug = require("express-longpoll")(app, { DEBUG: true }); +// You can also specify a function that is called when a new longpoll request is made +var longpollWithDebugAndCallback = require("express-longpoll")(app, { DEBUG: true, + subscriberCallback: function (id){ + console.log (`New subscriber with id: ${id}`); + } + }); ``` **Quick-start code** diff --git a/examples/basic/server.js b/examples/basic/server.js index c26b8da..7974960 100644 --- a/examples/basic/server.js +++ b/examples/basic/server.js @@ -1,7 +1,10 @@ var express = require('express'); var app = express(); const longpoll = require("../../index.js")(app, { - DEBUG: true + DEBUG: true, + subscriberCallback: function (id) { + console.log(`Subscriber Callback with id: ${id}`); + } }); app.use((req, res, next) => { diff --git a/index.js b/index.js index 86368d3..75a27ea 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,7 @@ var longpoll = function(app, opts) { // Default Config var config = { DEBUG: false, + subscriberCallback: null, events: { maxListeners: 0 // unlimited } @@ -140,6 +141,11 @@ var longpoll = function(app, opts) { // Create it sub(res); + + // New subscriber callback + if (config.subscriberCallback){ + config.subscriberCallback(req.id || null); + }; }); resolve(); }); From 76db9763f335b141228b92a8cf32d8fc2aea07ec Mon Sep 17 00:00:00 2001 From: Sean Williams Date: Fri, 4 May 2018 10:35:21 +1000 Subject: [PATCH 6/6] Updated subscriber callback parameters. --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 75a27ea..6d20c21 100644 --- a/index.js +++ b/index.js @@ -144,7 +144,7 @@ var longpoll = function(app, opts) { // New subscriber callback if (config.subscriberCallback){ - config.subscriberCallback(req.id || null); + config.subscriberCallback(req); }; }); resolve();