Using context.module or panels.module I would like to have multiple chat windows on a single page.

Members fund testing for the Drupal project. Drupal Association Learn more


langworthy’s picture

Title: Allow multiple chat windows » Allow multiple chat fields
1.91 KB

Patch attached. I wouldn't be surprised if there is a more efficient way of doing this.

langworthy’s picture

Status: Active » Needs review
beejeebus’s picture

thanks, will review tonight/tomorrow.

beejeebus’s picture

Status: Needs review » Needs work

the intention of this line in chatroom.module is to key each chat by it's cid, so we can have multiple on the page by allowing multiple to be sent down in Drupal.settings.chatroom.chats:

  drupal_add_js(array('chatroom' => array('chats' => array($chatroom->get('cid') => $chatroom_settings))), 'setting');

and this snippet in chatroom.js is meant to process them:

 * We depend on the Nodejs module successfully create a socket for us.
Drupal.Nodejs.connectionSetupHandlers.chatroom = {
  connect: function () {
    for (var cid in Drupal.settings.chatroom.chats) {
    Drupal.chatroom.initialised = true;

so, the current code at least intends to handle the multi-chat window case.

what errors where you seeing that led to this patch?

langworthy’s picture

When there is a single chat window on the page Drupal.settings.chatroom.chats is an object. When there are more than one it is an array of objects. The patch checks if it is an object or an array, and if it is an array it finds the proper object to work with.

langworthy’s picture

The patch doesn't change anything in Drupal.Nodejs.connectionSetupHandlers.chatroom. The only problems I ran into was in Drupal.chatroom.initialiseChat(Drupal.settings.chatroom.chats[^edit-chatroom-message-entry-box-/, '')]; is undefined)

beejeebus’s picture

ok, cool.

so the bug seems to me that it should always be an object, keyed by the cid of the chat. does that make sense? i'd rather make php send down js that can always be addressed the same way rather than adding a special case check to the js.

langworthy’s picture

It makes some sense but I'm not sure how to make it work as desired. I've played around with the drupal_add_js() code from #4 but no luck.

langworthy’s picture

So I'm starting to understand this better.

Right now:

drupal_add_js(array('chatroom' => array('chats' => array($chatroom->get('cid') => $chatroom_settings))), 'setting');

Results in Drupal.settings.chatroom.chats being:

[Object, Object]

When there are two chat windows on the page.

We want it to be:


And each chat object will be a property of this Object keyed by cid (as described in #7).

There seems to be something getting messed up in the PHP->JS as:

drupal_add_js(array('chatroom' => array('chats' => array('x' . $chatroom->get('cid') => $chatroom_settings))), 'setting');

Will end up with the correct format, only it has 'x' appended to each key.


drupal_add_js(array('chatroom' => array('chats' => array((String) $chatroom->get('cid') => $chatroom_settings))), 'setting');

Doesn't work.

langworthy’s picture

Status: Needs work » Needs review
975 bytes

I think we need to fix this once on the JS side.

beejeebus’s picture

i think i agree with this. we can even ditch the attempt to index by cid in php, and just add chats to the array.

i'm holding off committing this, however, because now that i'm really playing with multiple chats on the same page, i'm uncovering lower lever bugs in contentTokenChannel handling which i want to fix first.