changeset 3:0082e861cf16

Fix text message handling and new participant.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 23 Feb 2012 20:44:12 +0100
parents 88eb49491a1e
children e6f5077c2ea9
files isshouni.js
diffstat 1 files changed, 12 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/isshouni.js
+++ b/isshouni.js
@@ -83,10 +83,10 @@ cl.on('stanza', function(stanza) {
     return;
 
   if (stanza.is('presence') && type !== 'unavailable')
-    return on_presence(stanza);
+    return on_presence(from, stanza);
 
   if (stanza.is('message'))
-    return on_message(stanza);
+    return on_message(from, stanza);
 });
 
 var on_message = function(from, stanza) {
@@ -95,7 +95,9 @@ var on_message = function(from, stanza) 
 
   var message = stanza.getChild('body');
   if (message)
-    send_command('osd_show_text "' + from.resource + ': ' + message.getText() + '"');
+    message = message.getText();
+  if (message)
+    send_command('osd_show_text "' + from.resource + ': ' + message + '"');
 
   var payload = stanza.getChild(null, 'urn:linkmauve:player');
   if (!payload)
@@ -117,6 +119,13 @@ var on_presence = function(from, stanza)
     connected = true;
     return;
   }
+  if (!connected)
+    return;
+
+  console.log('New participant: ' + from.resource);
+
+  if (paused)
+    send_message('paused', undefined, 'chat');
 };
 
 cl.on('error', function(e) {