I spent a couple hours yesterday, and hit a wall. I know I am very close because I have debug set to true in my nodejs.config.js file, and it shows that the message sent from the module UI is received and being 'broadcast', but the message doesn't display on the site...

I using the latest packaged release, 7.x-1.0, of the module. The Drupal site and node are on the same server, e.g., localhost. The server is an Amazon EC2 instance running Ubuntu 12.04. Everything is up-to-date. I installed node and npm from the packages (rather than compiling from source), via apt-get. I roughly followed my own notes from a couple weeks ago at: http://drupal.arxic.com/node/30, as well as some of the new threads in the issue queue.

After getting node and npm installed, I went into the folder for one of my sites in my multi-site install, we'll call it mobonobomo.com, and created a modules folder, so that I can have nodejs for this site only. Then, I downloaded the current release via wget, and unpacked the tarball so I end up with drupal/sites/mobonobomo.com/modules/nodejs. I switch into the site-specific nodejs folder and run sudo npm install, and it appears that the node modules install correctly.

Then, I copied the nodejs.configs.js.example file to nodejs.config.js, and edited it to the following:

settings = {
  scheme: 'http',
  port: 8008,
  host: 'localhost',
  resource: '/socket.io',
  serviceKey: '',
  backend: {
    port: 80,
    host: 'mobonobomo.com',
    scheme: 'http',
    basePath: '',
    messagePath: '/nodejs/message'
  },
  debug: true,
  sslKeyPath: '',
  sslCertPath: '',
  sslCAPath: '',
  baseAuthPath: '/nodejs/',
  publishUrl: 'publish',
  kickUserUrl: 'user/kick/:uid',
  logoutUserUrl: 'user/logout/:authtoken',
  addUserToChannelUrl: 'user/channel/add/:channel/:uid',
  removeUserFromChannelUrl: 'user/channel/remove/:channel/:uid',
  addChannelUrl: 'channel/add/:channel',
  removeChannelUrl: 'channel/remove/:channel',
  setUserPresenceListUrl: 'user/presence-list/:uid/:uidList',
  addAuthTokenToChannelUrl: 'authtoken/channel/add/:channel/:uid',
  removeAuthTokenFromChannelUrl: 'authtoken/channel/remove/:channel/:uid',
  toggleDebugUrl: 'debug/toggle',
  contentTokenUrl: 'content/token',
  publishMessageToContentChannelUrl: 'content/token/message',
  extensions: [],
  clientsCanWriteToChannels: false,
  clientsCanWriteToClients: false,
  transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-polling', 'jsonp-polling'],
  jsMinification: true,
  jsEtag: true,
  logLevel: 1

All that I changed from the example file was the backend host, and the node server port (as well as setting debug to true). Still in the site-specific nodejs folder, I run node server.js. I get the following message in my terminal, which I take as a good sign:

Started http server.
   info  - socket.io started

After enabling the modules, at /admin/config/nodejs/config, I leave the protocol set to http, and specify localhost and 8008 as the host and port for the node.js server. Left enabled on all pages.

At /admin/config/nodejs/nodejs_notify/broadcast, I try to send a test notification with 'test' and 'testing'. My terminal shows:

publishMessage: message { broadcast: true,
  data: { subject: 'test', body: 'testing' },
  channel: 'nodejs_notify',
  clientSocketId: '' }
Broadcasting message

So, I know I'm connected to the running node server, but no message is displayed on the site! What could I be missing? I've gotten it to work before, and now I'm hitting my head on the wall. I've tried clearing caches, different browsers, logged in, as anonymous, etc. Is it a folder/file permissions issue? I noticed that my node_modules folder created after I run npm install is owned by the non-root logged-in user, and nodejs.config.js is owned by root - but it seems that everything is firing up. Any help would be most appreciated, and I will certainly get my process documented to help others! Thanks.

Comments

mobonobomo’s picture

Component: Code » Miscellaneous
Category: bug » support

Hmm, just ran package updates and noticed that there were new versions of nodejs and npm installed. Now, nodejs is 0.8.7 and npm is 1.1.49. I'm going to try again and I will report back.

mobonobomo’s picture

Still no luck, and I feel like I have tried everything :(. Since I'm using Amazon EC2, I went as far as setting up a micro server instance to isolate node and npm from my webserver. That met with even less luck... Back on to the webserver itself, I put the latest (today's) dev tarball back into /sites/mysite.com/modules/nodejs, re-ran npm install and tried several different configurations with my nodejs.config.js file (e.g., different host names for the node.js server). I do see the messages coming through in my SSH terminal, they are just not displayed on the site. I've tried clearing my caches, turned off Javascript aggregation, etc. All to no avail.

Is it because I'm using the site-specific modules folder for my multi-site setup? Would this affect the paths specified in nodejs.config.js? Is it whatever (localhost) that I'm using for the node.js host in nodejs.config.js?

Also, I noticed that with the node.js server running, if I navigate to mysite.com/nodejs/message, I get a {"error":"Invalid service key."} message on an otherwise blank page. This is with or without a service key set in nodejs.config.js and settings.php.

Any guidance would be most appreciated. I've been pulling my hair out with this one.

light9’s picture

I have the same issue. NodeJs version: v0.8.9-pre. I guess it because of node version, Because few hours ago I tryed to setup it on v.0.9 with no luck completely. But with v0.8.9-pre nodejs_watchdog is working. I'll try downgrade it and report back.
updated: 0.8.8 still no luck.
updated: 0.6.12 (tryed Node.js integration 7.x-1.0 and 7.x-1.x-dev) with every transports socket i.o options and still no way ...

mobonobomo’s picture

Sorry to hear that you are having trouble, but I'm glad I'm not the only one. I had got it working before, so I know it is possible...

light9’s picture

May be this regarding http://drupal.org/node/1306778? I too running win 7 64 ultimate.

mobonobomo’s picture

Really not sure, but I don't think so. I'll have another look at that thread when I can do some more testing this evening. Do you access to a non-Windows7 machine? If it is a socket.io issue, then this won't be the place to resolve it.

What are you using for the nodejs host in your nodejs.config.js? I did notice that using the full page test at Pingdom.com that when loading a page with the node.js server running (and receiving the messages from the site), that socket.io.js does not load, and the URL given is: localhost:8181/socket.io/ (where I have localhost set as the host and 8181 set as the port for the node.js server in nodejs.config.js). What I would really like to do is have an alias of my domain name to host the nodejs.server.js (like njs.mysite.com set as the node.js server host). I'd be fine with just using an IP address, but using an alias looks good, and I could not use the elastic IP address (Amazon EC2) of the instance to start the node.js server.

light9’s picture

mobonobomo, yep I tryed to access from windows xp with the same result. Also i tryed two different nodejs servers (first running on the same machine and second in the same network) and nodejs_watchdog submodule work good with both. Also my mysite.com:8080/socket.io/ loads normal from both nodejs hosts (i use nodejs ip in backend config). I really dunno what I can change else to make in work.

mobonobomo’s picture

Yeah, I am still stuck too after another hour or two yesterday. Anybody who has it working have any pointers? Anybody else working on Amazon EC2 by chance?

light9’s picture

anyone?

michaeljoser’s picture

This nodejs.config.js below works for me:

backendSettings = {
  "scheme":"http",
  "host":"mydomain.com",
  "port":3000, 
  "key":"",
  "cert":"",
  "resource":"/socket.io",
  "publishUrl":"publish",
  "serviceKey": "mykey",
  "baseAuthPath": "/nodejs/",
  "backend":{
    "port":80,
    "host":"mydomain.com",
    "messagePath":"/nodejs/message"
  },
  "clientsCanWriteToChannels":false,
  "clientsCanWriteToClients":false,
  "extensions":"",
  "debug":false,
  "transports":["xhr-polling","jsonp-polling"], // x64 bug for me // "transports":["websockets", "xhr-polling","jsonp-polling"]
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1
};

and in Drupal /admin/modules/nodejs/config I have:

Node.js server host: mydomain.com
Node.js server port: 3000

and it works nicely...

mobonobomo’s picture

Well, I didn't get too far: if I use mydomain.com for the node.js host, or a custom A record pointing to the server (like nodejs.mydomain.com), I get a "warn - error raised: Error: listen EADDRNOTAVAIL" in my console after running node server.js. From what I gather, that message is basically saying that the node.js server cannot listen on that hostname for some reason.

Also, I'm not sure where your "key" (blank) variable is coming from, I've only ever seen serviceKey.

Is "basepath" required in the backend settings?

mobonobomo’s picture

I had neglected to add my custom A record / subdomain as a virtual host on my server, so after fixing that oversight, I am now able to use my subdomain as the node.js host in nodejs.config.js.

But still no luck otherwise... I was loading node.js on admin/* pages only for testing purposes and did notice that the pages were taking a ridiculously time to load. Shutting down the node.js server removed the lagginess. Now I'm wondering if not seeing the messages is related to these long loading times...

inventlogic’s picture

just a small point as i must have spent hours looking for the broadcast on the same page i was sending the broadcast from. It occasionally flashed so i thought it was a configuration issue but....

open two windows and send broadcast in one and flip to see it in the other. worked every time. !@#??

mducharme’s picture

Status: Active » Closed (cannot reproduce)

Feel free to re-open if you're still having issues with this @mobonobomo. For others, the broadcaster does not see the message themselves. Also, turn on the debug in your settings and watch the output for potential problems (authentication, path issues, etc). I came here with the same issue and just tweaked until it worked. Here are my settings on a localhost within a multi-site installation:

backendSettings = {
  "scheme":"http",
  "host":"nodejs.d7.local",
  "port":1337,
  "key":"",
  "cert":"",
  "resource":"/socket.io",
  "publishUrl":"publish",
  "serviceKey": "mykey",
  "baseAuthPath": "/nodejs/",
  "backend":{
    "port":80,
    "host":"localhost",
    "messagePath":"/nodejs/message"
  },
  "clientsCanWriteToChannels":false,
  "clientsCanWriteToClients":false,
  "extensions":"",
  "debug":true,
  "transports":["websocket",
  "flashsocket",
  "htmlfile",
  "xhr-polling",
  "jsonp-polling"],
  "jsMinification":true,
  "jsEtag":true,
  "logLevel":1
};
sarikak’s picture

Status: Closed (cannot reproduce) » Active

I have integrated nodejs with my drupal7 website and while testing the System-wide broadcast message the notification popup box is not seen,the notification is only available in the terminal. what should I do to get the notification messages on my browser.

dynahiol’s picture

same here. I'm having the same problem as #15 and i've beed desperately searching for a solution with no result.
Drupal shows that the server is ok. But i can't broadcast messages. The javascript console shows no errors.
If someone succeded in sending broacast with this module, please do provide how. mydomain.tld:8080/nodejs/message give:
{"error":"Invalid service key."}
And when testing forever logs i get:

# tail -f /root/.forever/gKn0.log
  code: 'EPROTO',
  errno: 'EPROTO',
  syscall: 'write',
  address: undefined }
[2016/11/21 02:57:16] authenticateClientCallback: Error with authenticate client request:
{ [Error: write EPROTO]
  code: 'EPROTO',
  errno: 'EPROTO',
  syscall: 'write',
  address: undefined }
glekli’s picture

This sounds like the nodejs server is not able to communicate with drupal. This may not necessarily have something to do with broadcasting. Double check the backend settings on your nodejs server, and make sure the host/port/scheme settings are valid.

julien’s picture

Please try adding polling to the transport, after json-polling. And try using node version 4.7.