Posted by markwk on September 10, 2011 at 10:58am
I posted this idea in the drupal-ed group: http://groups.drupal.org/node/174849 Basically, I've built an integration that allow video chat to come to groups rather easily but I'm still missing text chat. Drupal Chat Room just isn't a very good solution considering what node.js is capable of.
I'm a totally node.js noob. So my question is this: how can I integrate/embed a node.js chat app within drupal (specifically Drupal 6)?
It was really easy to get https://github.com/ry/node_chat working on no.de, and I'm wondering where to go in terms of existing code and integration for chat within groups?
Thanks...

Comments
Around not Through
The first thought that comes to my mind is why go through Drupal for the chat IO at all? The client could communicate directly with the nodejs application running beside Drupal after the initial page load if you can control your webserver routing.
Though not involving chat, I am doing something similar using Drupal 6 and nodejs using AJAX. After the page load, the client calls back to the nodejs application. Our reverse proxy appropriately routes it to nodejs running on a different port instead of Drupal but from the viewpoint of the client, it is the same server/port, just a different url. We do a few more things in the process for security, etc. but that is the basic scenario.
Kurt
Check me if I'm wrong...
Ok. I'll need to think through this a bit out loud to see if I understood correctly.
Basically, you are saying that Drupal's involvement should be fairly minimal and that there will just be an initial call by the client from the drupal-site.xyz to the nodejs app (for example, including some kind of user token, permission, check, previous url, etc.). After, everything would be handled by node.js app. Is that correct?
re: Check me if I'm wrong...
Yes, that is basically right.
For example, in my app, Drupal sends to the client settings that it will need should it use the service. That allows me to retain configuration settings within Drupal. Then if the user decides to initiate the service, the first call is back to Drupal to initiate the communications. My app uses this opportunity to check Drupal specific access permissions, store the answer in the session, etc. In my case, another page is returned by Drupal to the client that avoids popup blockers and loads a different JS (this is probably specific to my app). From the new page the client then calls Drupal one last time via AJAX. After verifying that the session contains the proper pre-approval, Drupal then makes a call to the nodejs application requesting the service in the name of the client. Nodejs returns back to Drupal via JSON a unique id for the conversation. Drupal then returns that unique id to the client via JSON as well. Then all future communications are between the client and nodejs using that unique id. All of this happens over SSL.
A lot here might be specific to my use case and it surely could be done in more than one way. The point is, though, that after getting proper checks into place, etc. the brunt of the conversation is between nodejs and the client directly which allows Drupal to do what it does best and nodejs to do what it does best.
Kurt
@kbsymanz
Thanks. I think I got the basic steps now.
Two questions:
1.) Any node.js code you know of that does multiple chat room functionality?
2.) Any thoughts on code out there that might help me figure out what to do on the Drupal <=> Node.js app communication?
Drupal to Nodejs
Here is a code snippet of what I have used to get Drupal to call my nodejs application. It uses PHP Curl and the nodejs application returns JSON.
$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($ch), True);
$info = curl_getinfo($ch);
curl_close($ch);
Right now I am just using Drupal to Nodejs, not the opposite direction. But it could be done easily enough; one way is using nodejs's http.request(). I like to use JSON between the two. There are other ways as well.
I can't speak to the chat room functionality.
Kurt
Cheers..
Cheers. This is already a nice step in the right direction.
For the chatroom stuff, it seems like there are quite a few examples out there for Node.js so hopefully I'll be able to adapt one that fits. Thanks a lot....