First, I apologize for yet another "notifications don't work" issue. I've read all the issues related to this, but all of them either don't provide a solution or assume ancient versions of nodejs - both module and server.

So, first off, here's what I did on my Ubuntu 14.04 running Drupal 7.38. The site on which I'm trying this out is in a subdirectory of my webroot called /var/www/html/devel. The hostname of this machine is kandrpualocal, so I access this Drupal installation at http://kandrupalocal/devel.

Now this is what I did in the hope of getting nodejs to work and show me some notifications:

1) Installed nodejs server v 4.2.6 (as required by the latest drupal-node.js app at the time of writing this)

2) Installed the drupal-node.js app via npm install drupal-node.js app

3) Installed the latest nodejs Drupal module (7.x-1.13)

4) Wrote the following in the app's nodejs.config.js file:

settings = {
  scheme: 'http',
  port: 8080,
  host: 'kandrupalocal',
  resource: '/socket.io',
  serviceKey: 'kandrupalocal',
  backend: {
    port: 80,
    host: 'kandrupalocal',
    scheme: 'http',
    basePath: '/devel',
    messagePath: '/nodejs/message/'
  },
  debug: true,
  sslKeyPath: '',
  sslCertPath: '',
  sslCAPath: '',
  baseAuthPath: '/nodejs/',
  extensions: [],
  clientsCanWriteToChannels: true,
  clientsCanWriteToClients: true,
  transports: ['websocket', 'polling'],
  jsMinification: true,
  jsEtag: true,
  logLevel: 1
};

5) Wrote the following in the nodejs.config.js file in Drupal's nodejs module directory (Is this even required? Drupal can reach nodejs even without it and I don't see any difference with or without this file, but I still have it):

backendSettings = {
  "scheme":"http",
  "host":"kandrupalocal",
  "port":8080,
  "key":"/path/to/key/file",
  "cert":"/path/to/cert/file",
  "resource":"/socket.io",
  "publishUrl":"publish",
  "serviceKey":"kandrupalocal",
  "backend":{
    "port":80,
    "host":"kandrupalocal",
    "messagePath":"/devel/nodejs/message/"
  },
  "clientsCanWriteToChannels":true,
  "clientsCanWriteToClients":true,
  "extensions":"",
  "debug":true,
  "transports":["websocket",
  "polling"],
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1
};

Yes, I generated this from the form at /admin/config/nodejs/js.

6) I ran the app by doing to the app's directory and saying DEBUG=* node app.js. It's all green in Drupal's Status Report. "The Drupal-Node.js server (version 1.0.10) was successfully reached." This is what the app dumps in the terminal:

  express:application set "x-powered-by" to true +0ms
  express:application set "etag" to 'weak' +6ms
  express:application set "etag fn" to [Function: wetag] +2ms
  express:application set "env" to 'development' +0ms
  express:application set "query parser" to 'extended' +0ms
  express:application set "query parser fn" to [Function: parseExtendedQueryString] +1ms
  express:application set "subdomain offset" to 2 +0ms
  express:application set "trust proxy" to false +0ms
  express:application set "trust proxy fn" to [Function: trustNone] +1ms
  express:application booting in development mode +0ms
  express:application set "view" to [Function: View] +0ms
  express:application set "views" to '/var/www/html/devel/drupal-nodejs/node_modules/drupal-node.js/views' +0ms
  express:application set "jsonp callback name" to 'callback' +1ms
  express:router use / query +33ms
  express:router:layer new / +0ms
  express:router use / expressInit +1ms
  express:router:layer new / +0ms
  express:router use / jsonParser +1ms
  express:router:layer new / +0ms
  express:router use / <anonymous> +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/* +0ms
  express:router:layer new /nodejs/* +1ms
  express:router:route checkout /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route connect /nodejs/* +0ms
  express:router:layer new / +1ms
  express:router:route copy /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route delete /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route get /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route head /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route lock /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route m-search /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route merge /nodejs/* +1ms
  express:router:layer new / +0ms
  express:router:route mkactivity /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route mkcalendar /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route mkcol /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route move /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route notify /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route options /nodejs/* +0ms
  express:router:layer new / +1ms
  express:router:route patch /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route post /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route propfind /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route proppatch /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route purge /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route put /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route report /nodejs/* +1ms
  express:router:layer new / +0ms
  express:router:route search /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route subscribe /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route trace /nodejs/* +1ms
  express:router:layer new / +0ms
  express:router:route unlock /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route unsubscribe /nodejs/* +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/publish +1ms
  express:router:layer new /nodejs/publish +0ms
  express:router:route post /nodejs/publish +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/user/kick/:uid +0ms
  express:router:layer new /nodejs/user/kick/:uid +0ms
  express:router:route post /nodejs/user/kick/:uid +1ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/user/logout/:authtoken +0ms
  express:router:layer new /nodejs/user/logout/:authtoken +0ms
  express:router:route post /nodejs/user/logout/:authtoken +1ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/user/channel/add/:channel/:uid +0ms
  express:router:layer new /nodejs/user/channel/add/:channel/:uid +0ms
  express:router:route post /nodejs/user/channel/add/:channel/:uid +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/user/channel/remove/:channel/:uid +0ms
  express:router:layer new /nodejs/user/channel/remove/:channel/:uid +0ms
  express:router:route post /nodejs/user/channel/remove/:channel/:uid +0ms
  express:router:layer new / +1ms
  express:router:route new /nodejs/channel/add/:channel +0ms
  express:router:layer new /nodejs/channel/add/:channel +0ms
  express:router:route post /nodejs/channel/add/:channel +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/health/check +0ms
  express:router:layer new /nodejs/health/check +0ms
  express:router:route get /nodejs/health/check +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/channel/check/:channel +0ms
  express:router:layer new /nodejs/channel/check/:channel +0ms
  express:router:route get /nodejs/channel/check/:channel +1ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/channel/remove/:channel +0ms
  express:router:layer new /nodejs/channel/remove/:channel +0ms
  express:router:route post /nodejs/channel/remove/:channel +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/user/presence-list/:uid/:uidList +0ms
  express:router:layer new /nodejs/user/presence-list/:uid/:uidList +0ms
  express:router:route get /nodejs/user/presence-list/:uid/:uidList +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/debug/toggle +0ms
  express:router:layer new /nodejs/debug/toggle +0ms
  express:router:route post /nodejs/debug/toggle +1ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/content/token/users +0ms
  express:router:layer new /nodejs/content/token/users +0ms
  express:router:route post /nodejs/content/token/users +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/content/token +0ms
  express:router:layer new /nodejs/content/token +0ms
  express:router:route post /nodejs/content/token +0ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/content/token/message +0ms
  express:router:layer new /nodejs/content/token/message +0ms
  express:router:route post /nodejs/content/token/message +1ms
  express:router:layer new / +3ms
  express:router:route new /nodejs/authtoken/channel/add/:channel/:authToken +0ms
  express:router:layer new /nodejs/authtoken/channel/add/:channel/:authToken +0ms
  express:router:route post /nodejs/authtoken/channel/add/:channel/:authToken +1ms
  express:router:layer new / +0ms
  express:router:route new /nodejs/authtoken/channel/remove/:channel/:authToken +0ms
  express:router:layer new /nodejs/authtoken/channel/remove/:channel/:authToken +0ms
  express:router:route post /nodejs/authtoken/channel/remove/:channel/:authToken +0ms
  express:router:layer new / +0ms
  express:router:route new * +0ms
  express:router:layer new * +0ms
  express:router:route get * +1ms
  express:router:layer new / +0ms
Started http server.
  socket.io:server initializing namespace / +0ms
  socket.io:server creating engine.io instance with opts {"transports":["websocket","polling"],"log level":1,"port":8080,"browser client etag":true,"browser client minification":true,"path":"/socket.io"} +2ms
  socket.io:server attaching client serving req handler +33ms
  express:router dispatching GET /nodejs/health/check +30s
  express:router query  : /nodejs/health/check +2ms
  express:router expressInit  : /nodejs/health/check +1ms
  express:router jsonParser  : /nodejs/health/check +0ms
  body-parser:json skip empty body +0ms
  express:router <anonymous>  : /nodejs/health/check +2ms
[2016/10/11 17:33:21] Route callback: checkServiceKey
[2016/10/11 17:33:21] Route callback: healthCheck
  express:router dispatching GET /nodejs/health/check +17ms
  express:router query  : /nodejs/health/check +1ms
  express:router expressInit  : /nodejs/health/check +0ms
  express:router jsonParser  : /nodejs/health/check +0ms
  body-parser:json skip empty body +20ms
  express:router <anonymous>  : /nodejs/health/check +1ms
[2016/10/11 17:33:21] Route callback: checkServiceKey
[2016/10/11 17:33:21] Route callback: healthCheck
  express:router dispatching GET /nodejs/health/check +2m
  express:router query  : /nodejs/health/check +0ms
  express:router expressInit  : /nodejs/health/check +0ms
  express:router jsonParser  : /nodejs/health/check +0ms
  body-parser:json skip empty body +2m
  express:router <anonymous>  : /nodejs/health/check +0ms
[2016/10/11 17:35:22] Route callback: checkServiceKey
[2016/10/11 17:35:22] Route callback: healthCheck
  express:router dispatching GET /nodejs/health/check +3ms
  express:router query  : /nodejs/health/check +0ms
  express:router expressInit  : /nodejs/health/check +0ms
  express:router jsonParser  : /nodejs/health/check +0ms
  body-parser:json skip empty body +3ms
  express:router <anonymous>  : /nodejs/health/check +0ms
[2016/10/11 17:35:22] Route callback: checkServiceKey
[2016/10/11 17:35:22] Route callback: healthCheck

7) Since Nodejs Notifcations module (nodejs_notify) is enabled, I tried to broadcast a message. What do I get? Total silence. No notifications anywhere. This is what the terminal shows:

[2016/10/11 17:44:38] Body
{ broadcast: true,
  data: { subject: 'test', body: 'test' },
  channel: 'nodejs_notify',
  clientSocketId: '' }
[2016/10/11 17:44:38] broadcastMessage
{ broadcast: true,
  data: { subject: 'test', body: 'test' },
  channel: 'nodejs_notify',
  clientSocketId: '' }

8) That's it. So looks like node is registering the message. But is it broadcasting it? If yes, why isn't the message showing in the many browser windows which I have open?

This is driving me crazy from 24 hours, please help me! How can I get the notifications to work?

Comments

kandrupaler created an issue. See original summary.

kandrupaler’s picture

Issue summary: View changes
kandrupaler’s picture

Okay, very stupid of me. I hadn't tried opening up a browser on the server. When I tried and sent a broadcast notification from the server, I could indeed see it on the server (on multiple browser windows).

But I can't receive notifications on my desktop which is on the same LAN. I can still send notifications from the desktop and they show on the server.

Can someone tell me what's going on here? I think I'm very close to solving this. I did see http://stackoverflow.com/questions/11916999/socket-io-only-works-locally, but I'm not sure how to use that answer...

glekli’s picture

The value in settings.host is the hostname that the nodejs app listens on (as opposed to settings.backend.host, which is the hostname of the Drupal site). This will limit what ip addresses the app will accept connections on. Does your hostname (kandrupalocal) resolve to the same ip on both the server and the desktop? Do you have ipv6 configured on the server? That may complicate things. Try changing settings.host to an empty string, which will enable connections via all hostnames.

If this does not help, fire up the developer tools in the browser, and check if a websocket connection is open at all. Also check the console for js errors. If those look ok, check if any data comes in on the websocket when you broadcast something.

Regarding item 5, there is not supposed to be a nodejs.config.js file in the Drupal module, so perhaps double check that you have the latest version.

giteshdang’s picture

Hi @kandrupaler - I am facing the same issue. Can you please help me a bit regarding this? I am also getting total silence but in node terminal, messages are getting broadcasting.

loze’s picture

Same here. The messages are broadcasting in the terminal, but the js callbacks on the page are not getting executed. No errors anywhere that I can see.

There has to be something simple I'm overlooking.