Mercurial > isshouni
comparison isshouni.js @ 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 |
comparison
equal
deleted
inserted
replaced
0:156c2fd7c626 | 1:617063bc96f7 |
---|---|
26 var JID = require('./jid'); | 26 var JID = require('./jid'); |
27 var spawn = require('child_process').spawn; | 27 var spawn = require('child_process').spawn; |
28 | 28 |
29 var cl = new xmpp.Client(config); | 29 var cl = new xmpp.Client(config); |
30 var mplayer = spawn('mplayer', args); | 30 var mplayer = spawn('mplayer', args); |
31 var paused = false; | |
31 | 32 |
32 var connect = function() { | 33 var connect = function() { |
33 cl.send(new xmpp.Element('presence', {to: config.muc + '/' + config.nick}) | 34 cl.send(new xmpp.Element('presence', {to: config.muc + '/' + config.nick}) |
34 .c('x', {xmlns: 'http://jabber.org/protocol/muc'}) | 35 .c('x', {xmlns: 'http://jabber.org/protocol/muc'}) |
35 .c('history', {maxchars: '0'}) | 36 .c('history', {maxchars: '0'}) |
79 if (!payload) | 80 if (!payload) |
80 return; | 81 return; |
81 | 82 |
82 //send_command('osd_show_text "' + from.resource + ' did ' + payload.name + '"'); | 83 //send_command('osd_show_text "' + from.resource + ' did ' + payload.name + '"'); |
83 | 84 |
84 if (payload.name === 'pause') | 85 if (payload.name === 'pause') { |
85 send_command('pause'); | 86 send_command('pause'); |
86 else if (payload.name === 'seek') | 87 paused = !paused; |
88 } else if (payload.name === 'seek') | |
87 send_command('seek ' + payload.getText()); | 89 send_command('seek ' + payload.getText()); |
88 else if (payload.name === 'synchro') | 90 else if (payload.name === 'synchro') |
89 send_command('seek ' + payload.getText() + ' 2'); | 91 send_command('seek ' + payload.getText() + ' 2'); |
90 }); | 92 }); |
91 | 93 |
97 '+': 'volume 1', | 99 '+': 'volume 1', |
98 '-': 'volume -1', | 100 '-': 'volume -1', |
99 'm': 'mute', | 101 'm': 'mute', |
100 ' ': function() { | 102 ' ': function() { |
101 send_message('pause'); | 103 send_message('pause'); |
102 send_command('get_time_pos'); | 104 paused = !paused; |
105 console.log(paused); | |
106 if (paused) | |
107 send_command('get_time_pos'); | |
103 return 'pause'; | 108 return 'pause'; |
104 }, | 109 }, |
105 'q': function() { | 110 'q': function() { |
106 tty.setRawMode(false); | 111 tty.setRawMode(false); |
107 disconnect(); | 112 disconnect(); |
108 return 'quit'; | 113 return 'quit'; |
109 }, | 114 }, |
110 }; | 115 }; |
111 | 116 |
117 var seek = function(time) { | |
118 send_message('seek', time); | |
119 send_command('seek ' + time); | |
120 }; | |
121 | |
112 process.stdin.resume(); | 122 process.stdin.resume(); |
113 tty.setRawMode(true); | 123 tty.setRawMode(true); |
114 process.stdin.on('keypress', function(char, key) { | 124 process.stdin.on('keypress', function(char, key) { |
115 if (!char) { | 125 if (!char) { |
116 if (key.name == 'right') | 126 if (key.name == 'right') |
117 send_command('seek 10'); | 127 seek(10); |
118 else if (key.name == 'left') | 128 else if (key.name == 'left') |
119 send_command('seek -10'); | 129 seek(-10); |
120 else if (key.name == 'up') | 130 else if (key.name == 'up') |
121 send_command('seek 60'); | 131 seek(60); |
122 else if (key.name == 'down') | 132 else if (key.name == 'down') |
123 send_command('seek -60'); | 133 seek(-60); |
124 } else if (char in commands) { | 134 } else if (char in commands) { |
125 var command = commands[char]; | 135 var command = commands[char]; |
126 if (typeof command === 'function') | 136 if (typeof command === 'function') |
127 command = command(); | 137 command = command(); |
128 send_command(command); | 138 send_command(command); |