changeset 1:617063bc96f7

Fix some sync issues.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 22 Feb 2012 20:40:29 +0100
parents 156c2fd7c626
children 88eb49491a1e
files isshouni.js
diffstat 1 files changed, 17 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/isshouni.js
+++ b/isshouni.js
@@ -28,6 +28,7 @@ var spawn = require('child_process').spa
 
 var cl = new xmpp.Client(config);
 var mplayer = spawn('mplayer', args);
+var paused = false;
 
 var connect = function() {
   cl.send(new xmpp.Element('presence', {to: config.muc + '/' + config.nick})
@@ -81,9 +82,10 @@ cl.on('stanza', function(stanza) {
 
   //send_command('osd_show_text "' + from.resource + ' did ' + payload.name + '"');
 
-  if (payload.name === 'pause')
+  if (payload.name === 'pause') {
     send_command('pause');
-  else if (payload.name === 'seek')
+    paused = !paused;
+  } else if (payload.name === 'seek')
     send_command('seek ' + payload.getText());
   else if (payload.name === 'synchro')
     send_command('seek ' + payload.getText() + ' 2');
@@ -99,7 +101,10 @@ var commands = {
   'm': 'mute',
   ' ': function() {
     send_message('pause');
-    send_command('get_time_pos');
+    paused = !paused;
+    console.log(paused);
+    if (paused)
+      send_command('get_time_pos');
     return 'pause';
   },
   'q': function() {
@@ -109,18 +114,23 @@ var commands = {
   },
 };
 
+var seek = function(time) {
+  send_message('seek', time);
+  send_command('seek ' + time);
+};
+
 process.stdin.resume();
 tty.setRawMode(true);
 process.stdin.on('keypress', function(char, key) {
   if (!char) {
     if (key.name == 'right')
-      send_command('seek 10');
+      seek(10);
     else if (key.name == 'left')
-      send_command('seek -10');
+      seek(-10);
     else if (key.name == 'up')
-      send_command('seek 60');
+      seek(60);
     else if (key.name == 'down')
-      send_command('seek -60');
+      seek(-60);
   } else if (char in commands) {
     var command = commands[char];
     if (typeof command === 'function')