rkeys
Version:
A platform for creating tablet/HTML5 virtual-keyboard apps to send keystrokes to remote X11
70 lines (69 loc) • 1.7 kB
JavaScript
// Generated by LiveScript 1.3.0
(function(){
var _, Os, Args, Wc, Ws, Xaw, AWC, servants, me, url, wc;
_ = require('lodash');
Os = require('os');
Args = require('../args');
Wc = require('./ws/client');
Ws = require('./ws/server');
Xaw = require('./x11/active-window');
AWC = 'active-window-changed';
servants = {};
module.exports = me = {
emit: function(){
notifyHttpClients();
return notifyMaster();
},
servant: {
update: function(it){
var ref$, h;
log2('servant.update', it);
if (((ref$ = it.event) != null ? ref$.id : void 8) !== AWC) {
return;
}
servants[h = it.hostname] = {
title: it.event.title
};
if (localFocusIsOnServant(h)) {
return notifyHttpClients();
}
}
}
};
Xaw.on('changed', me.emit);
if (url = Args.servantToUrl) {
wc = Wc.init(url, {
reconnectPeriod: 2000
});
if (url = Args.servantToUrl) {
wc.on('connect', notifyMaster);
}
}
function localFocusIsOnServant(it){
return _.contains(Xaw.current.title.toUpperCase(), it.toUpperCase());
}
function notifyHttpClients(){
var s, t;
s = _.find(servants, function(v, k){
return localFocusIsOnServant(k);
});
t = Xaw.current.title;
if (s != null) {
t = t + " (" + s.title + ")";
}
log2('notify-http-clients', AWC, t);
return Ws.broadcast(AWC, t);
}
function notifyMaster(){
if (!Args.servantToUrl) {
return;
}
return Wc.send('servant', {
hostname: Os.hostname(),
event: {
id: AWC,
title: Xaw.current.title
}
});
}
}).call(this);