Hello,

I am trying to test how chat room works with nodejs, but I have run into a little bump in the road. See here:

    info  - socket.io started
publishMessageToChannel: The channel "chatroom_chat_305" doesn't exist.
publishMessageToChannel: The channel "chatroom_chat_305" doesn't exist.
No active sessions for uid: 1

When I proceed to write something in my newly created chat, no text will appear in my browser window until I do a manual refresh. I must be doing something wrong, do you have any ideas?

Best regards,
Ao

Comments

darklrd’s picture

Issue tags: +Chatroom GSoC 2011

Hi

Did you check the server status at admin/config/nodejs/stats? Also, which version of node.js are you using?

Aonoa’s picture

I am using version 7.x-1.0-beta1 of nodejs and the server stats page just gives me an error:

Error reading Node.js server stats.

The commandline gives me this at the same time:

TypeError: Cannot read property 'length' of undefined
    at Object.<anonymous> (/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:307:39)
    at param (/usr/local/lib64/node/connect/lib/connect/middleware/router.js:146:21)
    at pass (/usr/local/lib64/node/connect/lib/connect/middleware/router.js:162:10)
    at /usr/local/lib64/node/connect/lib/connect/middleware/router.js:152:19
    at Object.<anonymous> (/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:135:5)
    at param (/usr/local/lib64/node/connect/lib/connect/middleware/router.js:146:21)
    at pass (/usr/local/lib64/node/connect/lib/connect/middleware/router.js:162:10)
    at Object.router [as handle] (/usr/local/lib64/node/connect/lib/connect/middleware/router.js:168:6)
    at next (/usr/local/lib64/node/connect/lib/connect/index.js:218:15)
    at Object.handle (/usr/local/lib64/node/express/lib/express/server.js:65:5)

I'll look at some other versions of nodejs, then.

Best regards,
Ao

Aonoa’s picture

By switching to nodejs dev snapshot from 29th of June, I had some progress. The server stats page now gives me:

There are no authenticated clients
There are no active channels

But, I do have a chat, although at this point I can't enter text in it. I no longer get "channel doesn't exist" messages, but I do get "No active sessions for uid: 1".

EDIT: I spoke too soon, I still get "channel doesn't exist" messages.

Best regards,
Ao

darklrd’s picture

Hi

What is your node.js server version?

Aonoa’s picture

The latest from https://github.com/joyent/node

Best regards,
Ao

darklrd’s picture

Build the v0.4 branch.

Aonoa’s picture

From the server stats I still get:

There are no authenticated clients
There are no active channels

Now the node.js displays:

Started http server.
   info  - socket.io started
publishMessageToChannel: The channel "chatroom_chat_306" doesn't exist.
publishMessageToChannel: The channel "chatroom_chat_306" doesn't exist.
publishMessageToChannel: The channel "chatroom_chat_306" doesn't exist.

The "Started http server" was not there before, and the "No active sessions for uid: 1" seems to be gone.

Best regards,
Ao

Aonoa’s picture

I had used older versions, but trying latest https://github.com/senchalabs/connect and https://github.com/visionmedia/express does not help.

I'll also add my nodejs.config.js file here, just in case:

backendSettings = {
  'scheme': 'http',
  'host': '192.168.1.4',
  'port': 8080,
  'key': '/path/to/key/file',
  'cert': '/path/to/cert/file',
  'resource': '/node.js/realtime',
  'publishUrl': '/nodejs/publish',
  'serviceKey': '',
  'backend': {
    'port': 80,
    'host': '192.168.1.4',
    'authPath': '/nodejs/auth/'
   },
   'extensions': [],
   'clientsCanWriteToChannels': false,
   'clientsCanWriteToClients': false
};

Best regards,
Ao

Anonymous’s picture

subscribe.

darklrd’s picture

Hi

Are you using the latest 7.x-1.x-dev, dated 2011-Jun-29, of nodejs module?

Aonoa’s picture

Yes, I am. I stated that already in #3. :-)

EDIT: Just adding file info from my downloaded tarball to let it be known it is the right version:

36406 Jun 29 14:14 nodejs-7.x-1.x-dev.tar.gz
md5sum: ec259999db1211cfca085cfc21ccdf23

Best regards,
Ao

Aonoa’s picture

I have a "page not found" error on the following file:

sites/all/modules/nodejs/socket_io/socket.io/node_modules/socket.io-client/dist/socket.io.js

The socket.io directory contains only:

History.md Makefile Readme.md examples index.js lib package.json support test

I'll investigate further.

Best regards,
Ao

EDIT: socket.io/lib/ contains:

logger.js manager.js namespace.js parser.js socket.io.js socket.js store.js stores transport.js transports util.js

Is that the socket.io.js drupal was looking for?

Aonoa’s picture

I made a new folder structure and symlink in sites/all/modules/nodejs/socket_io/ so that it would see the proper socket.io.js in the same directory it wanted.

Now I get these messages:

Started http server.
   info  - socket.io started
publishMessageToChannel: The channel "chatroom_chat_306" doesn't exist.
   debug - client authorized
   info  - handshake authorized 1165899835602367171
   debug - setting request GET /socket.io/1/websocket/1165899835602367171
   debug - set heartbeat interval for client 1165899835602367171
   warn  - websocket connection invalid
   info  - transport end
   debug - set close timeout for client 1165899835602367171
   debug - cleared close timeout for client 1165899835602367171
   debug - cleared heartbeat interval for client 1165899835602367171
   debug - client authorized for 
   debug - setting request GET /socket.io/1/xhr-polling/1165899835602367171?t1310932599159
   debug - setting poll timeout
   debug - clearing poll timeout
   debug - xhr-polling writing 1::
   debug - set close timeout for client 1165899835602367171
   debug - xhr-polling received data packet 5:::{"name":"authenticate","args":[{"authToken":"4155687c4a2bf81f14d6a0a212614145"}]}
   debug - setting request GET /socket.io/1/xhr-polling/1165899835602367171?t1310932599163
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client 1165899835602367171
Failed to parse authentication message: SyntaxError: Unexpected token ILLEGAL
   debug - clearing poll timeout
   debug - xhr-polling writing 8::
   debug - set close timeout for client 1165899835602367171
   debug - xhr-polling closed due to exceeded duration
   debug - setting request GET /socket.io/1/xhr-polling/1165899835602367171?t1310932619175
   debug - setting poll timeout
   debug - discarding transport
   debug - cleared close timeout for client 1165899835602367171
   debug - clearing poll timeout
   info  - transport end
   debug - set close timeout for client 1165899835602367171
   debug - cleared close timeout for client 1165899835602367171
   debug - discarding transport
   debug - client authorized
   info  - handshake authorized 15712507401819981481
   debug - setting request GET /socket.io/1/websocket/15712507401819981481
   debug - set heartbeat interval for client 15712507401819981481
   warn  - websocket connection invalid
   info  - transport end
   debug - set close timeout for client 15712507401819981481
   debug - cleared close timeout for client 15712507401819981481
   debug - cleared heartbeat interval for client 15712507401819981481
   debug - client authorized for 
publishMessageToChannel: The channel "chatroom_chat_306" doesn't exist.
No active sessions for uid: 1
   debug - client authorized
   info  - handshake authorized 7153299011497229130
   debug - setting request GET /socket.io/1/websocket/7153299011497229130
   debug - set heartbeat interval for client 7153299011497229130
   warn  - websocket connection invalid
   info  - transport end
   debug - set close timeout for client 7153299011497229130
   debug - cleared close timeout for client 7153299011497229130
   debug - cleared heartbeat interval for client 7153299011497229130
   debug - client authorized for 
   debug - client authorized
   info  - handshake authorized 17740003051349445442
   debug - setting request GET /socket.io/1/websocket/17740003051349445442
   debug - set heartbeat interval for client 17740003051349445442
   warn  - websocket connection invalid
   info  - transport end
   debug - set close timeout for client 17740003051349445442
   debug - cleared close timeout for client 17740003051349445442
   debug - cleared heartbeat interval for client 17740003051349445442
   debug - client authorized for 
   debug - client authorized
   info  - handshake authorized 13520406241975761836
   debug - setting request GET /socket.io/1/websocket/13520406241975761836
   debug - set heartbeat interval for client 13520406241975761836
   warn  - websocket connection invalid
   info  - transport end
   debug - set close timeout for client 13520406241975761836
   debug - cleared close timeout for client 13520406241975761836
   debug - cleared heartbeat interval for client 13520406241975761836
   debug - client authorized for 

Any ideas?

Best regards,
Ao

EDIT: I can add that server stats still shows:

There are no authenticated clients
There are no active channels
Aonoa’s picture

Changing the backendSettings host IP from the servers actual IP to 'localhost' made all the info/debug messages shown in #13 disappear. However, I still do not have a working nodejs integration with chatroom.

It's still claiming there are no authenticated clients and no active channels. I have to manually refresh my chat page after every input to see the written message, and every time I write a message I get: No active sessions for uid: 1 in the console running node server.js.

Best regards,
Ao

pavlosdan’s picture

Hi Ao,

I had similar issues with what you are describing here and I had 'localhost' in my config as well.

After changing all my 'localhost' instances both in the 'nodejs.config.js' and in 'admin/config/nodejs/config' to the actual server name my site was on (in my case I had defined the server name to be my site's domain in my Virtual Host) everything started working.

Also, (maybe this is not required but I still did it) I changed the ports for nodejs from 8080 to 9080 just to make sure that nothing was interfering with it.

So in 'admin/config/nodejs/config' I have:
Node.js server host: 'example.com'
Node.js server port: 9080

and in my nodejs.config.js I have:
backendSettings = {
"scheme":"http",
"host":"example.com",
"port":"9080",
"key":"/path/to/key/file",
"cert":"/path/to/cert/file",
"resource":"/node.js/realtime",
"publishUrl":"/nodejs/publish",
"serviceKey":"",
"backend":{
"port":"8080",
"host":"example.com",
"authPath":"/nodejs/auth/"},
"clientsCanWriteToChannels":true,
"clientsCanWriteToClients":true,
"extensions":[["nodejs.server.extension.js"]],
"debug":true
}

Hope this is of some help.

Pavlos

Aonoa’s picture

Hello!

Thank you for your input, but so far it's not helping I'm afraid. Same as always. :-(

Started http server.
   info  - socket.io started
publishMessage: message --> [object Object]
publishMessageToChannel: The channel "chatroom_chat_309" doesn't exist.
publishMessage: message --> [object Object]
publishMessageToChannel: The channel "chatroom_chat_309" doesn't exist.
No active sessions for uid: 129
publishMessage: message --> [object Object]
Sent message to 0 clients in channel "chatroom_chat_309"
publishMessage: message --> [object Object]
Sent message to 0 clients in channel "chatroom_chat_309"
No active sessions for uid: 1
publishMessage: message --> [object Object]
Sent message to 0 clients in channel "chatroom_chat_309"

EDIT: It's weird, because I can definitely see on the console that the port 8080 or 9090 (if I change it) is being used and connections are established locally.

Best regards,
Ao

pavlosdan’s picture

Hmmm it is indeed weird.

I have just gotten Chat Room from git and switched to the branch with the nodejs integration, enabled and configured its settings and ran some tests and it seems to be working fine for me.

Do the other submodules from nodejs work for you?

Aonoa’s picture

I haven't tried the other submodules from nodejs.

I have tried the latest chatroom dev snapshot, and tried gsoc2011 as well as the 7.x-1.x branches from git. Similar results.

Maybe there's something wrong with my node/express/connect/socket.io setup.. It took a lot of searching around git repo's to find all the various parts and put them together..

Basically I put everything in /usr/local/lib/node and exported NODE_PATH to that directory. The symlinking of socket.io.js was a bit confusing, but after reading drupal error logs it appeared to want the following structure:

sites/all/modules/nodejs/socket_io/socket.io/node_modules/socket.io-client/dist/socket.io.js

How is yours?

Best regards,
Ao

Aonoa’s picture

I am writing to provide a little more information after some more testing.

I have been using node 0.4, connect 0.5.10, express 1.0.7, and then I add modules for qs, mime, ugly-js and redis. I get an error when trying to run node server.js while using the 0.6 branch of socket.io as suggested in the readme in nodejs module. Latest git versions of socket.io and socket.io-client satisfies node, but as usual I am still not getting chatroom to work properly with nodejs.

My drupal is version 7.4 and I also tried to setup all of this from scratch, but still no success. Latest chatroom and nodejs modules.

Best regards,
Ao

pavlosdan’s picture

Hi Ao.

Any luck with this?

I have my socket.io installed under my nodejs module folder so my symlink looks like this:
socket.io -> /path/to/site/sites/all/modules/contrib/nodejs/node_modules/socket.io/

(ran the command from the nodejs directory as explained in the nodejs installation guide)

Pavlos

Aonoa’s picture

Really?

In my nodejs directory (/path/to/site/sites/all/modules/nodejs), I have a subdirectory called socket_io with a README.txt that says this:

Socket.IO Setup
================

Nodejs.module requires Socket.IO to function.

Two options for installation:

1. Install npm (Node Package Manager) 
curl http://npmjs.org/install.sh | sudo sh

2. Use npm to install Socket.IO and Express, and symlink into this folder.

> npm install socket.io express
> ln -s /path/to/socket/io/install/socket.io /path/to/your/nodejs/module/socket_io/socket.io

OR

3. Download from Socket.IO from http://socket.io into this folder.

That does not seem to match up with what you have done?

I have to have this structure and file: sites/all/modules/nodejs/socket_io/socket.io/node_modules/socket.io-client/dist/socket.io.js, because if I don't, my drupal gives me page not found errors on that file. Maybe my nodejs module is different from yours?

Another question, which versions of socket.io and socket.io-client are you using?

Best regards,
Ao

pavlosdan’s picture

Im using the dev version of nodejs.

from its readme file:
4. Create a symlink to the socket.io client in the `socket_io` folder (run from within the module's root directory)

ln -s `pwd`/node_modules/socket.io/ socket_io/socket.io

My socket.io version is 0.7.7 and my socket.io-client is version 0.7.4

Aonoa’s picture

Now I got a bit further, after correcting the symlink and node_modules folder and setting the proper hostname instead of localhost. However, it crashed. I'll provide the log:

Started http server.
   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 922476580809971399
   debug - setting request GET /socket.io/1/websocket/922476580809971399
   debug - set heartbeat interval for client 922476580809971399
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"2ff65210d4c293859e1e3e3664285039"}]}
Authenticating client with key "2ff65210d4c293859e1e3e3664285039"
Valid login for uid: 1
adding channels for uid 1: nodejs_user_1
{ '1': [] }
   info  - transport end
   debug - set close timeout for client 922476580809971399
   debug - cleared close timeout for client 922476580809971399
   debug - cleared heartbeat interval for client 922476580809971399
Cleaning up after socket 922476580809971399
   debug - discarding transport
returnServerStats: returning server stats --> [object Object]
   debug - client authorized
   info  - handshake authorized 1035181599871997464
   debug - setting request GET /socket.io/1/websocket/1035181599871997464
   debug - set heartbeat interval for client 1035181599871997464
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"2ff65210d4c293859e1e3e3664285039"}]}
Authenticating client with key "2ff65210d4c293859e1e3e3664285039"
Reusing existing authentication data for key: 2ff65210d4c293859e1e3e3664285039 , client id: 1035181599871997464
adding channels for uid 1: nodejs_user_1
{ '1': [] }
   info  - transport end
   debug - set close timeout for client 1035181599871997464
   debug - cleared close timeout for client 1035181599871997464
   debug - cleared heartbeat interval for client 1035181599871997464
Cleaning up after socket 1035181599871997464
   debug - discarding transport
   debug - client authorized
   info  - handshake authorized 10865772311961867564
   debug - setting request GET /socket.io/1/websocket/10865772311961867564
   debug - set heartbeat interval for client 10865772311961867564
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"2ff65210d4c293859e1e3e3664285039"}]}
Authenticating client with key "2ff65210d4c293859e1e3e3664285039"
Reusing existing authentication data for key: 2ff65210d4c293859e1e3e3664285039 , client id: 10865772311961867564
adding channels for uid 1: nodejs_user_1
{ '1': [] }
   info  - transport end
   debug - set close timeout for client 10865772311961867564
   debug - cleared close timeout for client 10865772311961867564
   debug - cleared heartbeat interval for client 10865772311961867564
Cleaning up after socket 10865772311961867564
   debug - discarding transport
publishMessage: message --> [object Object]
publishMessageToChannel: The channel "chatroom_chat_309" doesn't exist.
   debug - client authorized
   info  - handshake authorized 4382681721802732259
   debug - setting request GET /socket.io/1/websocket/4382681721802732259
   debug - set heartbeat interval for client 4382681721802732259
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"2ff65210d4c293859e1e3e3664285039"}]}
Authenticating client with key "2ff65210d4c293859e1e3e3664285039"
Reusing existing authentication data for key: 2ff65210d4c293859e1e3e3664285039 , client id: 4382681721802732259
adding channels for uid 1: nodejs_user_1
{ '1': [] }
publishMessage: message --> [object Object]
publishMessageToChannel: The channel "chatroom_chat_309" doesn't exist.
Added channel 'chatroom_chat_309' to sessionIds 4382681721802732259
Found uid '1' in authenticatedClients, channels nodejs_user_1
Added channel 'chatroom_chat_309' authenticatedClients
   debug - emitting heartbeat for client 4382681721802732259
   debug - websocket writing 2::
   debug - set heartbeat timeout for client 4382681721802732259
   debug - websocket received data packet 2::
   debug - got heartbeat packet
   debug - cleared heartbeat timeout for client 4382681721802732259
   debug - set heartbeat interval for client 4382681721802732259
   info  - transport end
   debug - set close timeout for client 4382681721802732259
   debug - cleared close timeout for client 4382681721802732259
   debug - cleared heartbeat interval for client 4382681721802732259
Cleaning up after socket 4382681721802732259
   debug - discarding transport
publishMessage: message --> [object Object]
Sent message to 0 clients in channel "chatroom_chat_309"
Sending offline notification for 1

/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:828
    sendPresenceChangeNotification(authData.uid, 'offline');
    ^
ReferenceError: authData is not defined
    at Object.<anonymous> (/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:828:5)
    at Object._onTimeout (timers.js:173:16)
    at Timer.callback (timers.js:83:39)

Best regards,
Ao

Aonoa’s picture

Strange, after that previous crash drupal is giving me page not found errors on this file location: sites/all/modules/nodejs/socket_io/socket.io/node_modules/socket.io-client/dist/socket.io.js.

It's kind of frustrating that it almost worked once, and now nothing again. I didn't even change anything between the attempts.

I can add that after the crash, all javascripts stopped working. It turns out that the cause behind the javascript not working is actually related to the missing page error for socket.io.js, if I do a workaround by creating a directory called node_modules inside socket.io and copy socket.io-client into that, then things are almost working..

Authenticated clients
User_01 (UID: 1)

There are no active channels

Now I at least have an authenticated client! Even though the realtime chatting still isn't quite there, I must figure out how to activate the channel I guess.

Best regards,
Ao

Aonoa’s picture

A little more log data:

Started http server.
   info  - socket.io started
   debug - client authorized
   info  - handshake authorized 54919793822268244
   debug - setting request GET /socket.io/1/websocket/54919793822268244
   debug - set heartbeat interval for client 54919793822268244
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"07dc33a550041e1c13cd8f1454461608"}]}
{ '1': [] }
   info  - transport end
   debug - set close timeout for client 54919793822268244
   debug - cleared close timeout for client 54919793822268244
   debug - cleared heartbeat interval for client 54919793822268244
   debug - discarding transport
   debug - client authorized
   info  - handshake authorized 6528661931256419181
   debug - setting request GET /socket.io/1/websocket/6528661931256419181
   debug - set heartbeat interval for client 6528661931256419181
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"07dc33a550041e1c13cd8f1454461608"}]}
{ '1': [] }
   info  - transport end
   debug - set close timeout for client 6528661931256419181
   debug - cleared close timeout for client 6528661931256419181
   debug - cleared heartbeat interval for client 6528661931256419181
   debug - discarding transport
publishMessageToChannel: The channel "chatroom_chat_309" doesn't exist.
   debug - client authorized
   info  - handshake authorized 19437381451038019141
   debug - setting request GET /socket.io/1/websocket/19437381451038019141
   debug - set heartbeat interval for client 19437381451038019141
   debug - client authorized for 
   debug - websocket writing 1::
   debug - websocket received data packet 5:::{"name":"authenticate","args":[{"authToken":"07dc33a550041e1c13cd8f1454461608"}]}
{ '1': [] }

Best regards,
Ao

Aonoa’s picture

I think I have discovered my problem. It seems to break apart because I have multiple sites open with nodejs enabled in my browser at once. I used to have a duplicate test site open in a different tab, and now I do not. Now I have just one nodejs site open in my browser, and it suddenly works without me having changed anything. I'll continue to investigate and test.

Best regards,
Ao

EDIT: It is crashing rather often, with this kind of output:

   debug - websocket received data packet 2::
   debug - got heartbeat packet
   debug - cleared heartbeat timeout for client 21019983661191106982
   debug - set heartbeat interval for client 21019983661191106982
   debug - clearing poll timeout
   info  - transport end
   debug - set close timeout for client 13461773341324886356
   debug - cleared close timeout for client 13461773341324886356
   debug - discarding transport
   debug - websocket writing 4:::{"channel":"chatroom_chat_309","broadcast":false,"type":"userSeen","callback":"chatroomNodejsMessageHandler","data":"<div id=\"chatroom-user-list-wrapper\"><ul id=\"chatroom-user-list\"><li id=\"chatroom_user_72\" class=\"chatroom-user chatroom-current-user\"><a href=\"/user/72\" title=\"View user profile.\" class=\"username\" xml:lang=\"\" about=\"/user/72\" typeof=\"sioc:UserAccount\" property=\"foaf:name\">Test_User</a> </li></ul></div>"}
   debug - websocket writing 4:::{"channel":"chatroom_chat_309","broadcast":false,"type":"userSeen","callback":"chatroomNodejsMessageHandler","data":"<div id=\"chatroom-user-list-wrapper\"><ul id=\"chatroom-user-list\"><li id=\"chatroom_user_72\" class=\"chatroom-user chatroom-current-user\"><a href=\"/user/72\" title=\"View user profile.\" class=\"username\" xml:lang=\"\" about=\"/user/72\" typeof=\"sioc:UserAccount\" property=\"foaf:name\">Test_User</a> </li></ul></div>"}

/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:828
    sendPresenceChangeNotification(authData.uid, 'offline');
    ^
ReferenceError: authData is not defined
    at Object.<anonymous> (/var/www/example.com/drupal-7.4/sites/all/modules/nodejs/server.js:828:5)
    at Object._onTimeout (timers.js:173:16)
    at Timer.callback (timers.js:83:39)
Aonoa’s picture

Status: Active » Closed (fixed)

My initial support request problem here has been solved. Thank you for all assistance.

Closing issue. :-)

Best regards,
Ao