UNPKG

rkeys

Version:

A platform for creating tablet/HTML5 virtual-keyboard apps to send keystrokes to remote X11

43 lines (42 loc) 1.17 kB
// Generated by LiveScript 1.3.0 (function(){ var Em, _, Ws, ws, me; Em = require('events').EventEmitter; _ = require('lodash'); Ws = require('faye-websocket'); module.exports = me = import$(clone$(new Em()), { init: function(url, opts){ function connect(){ log2("try connect " + url); ws = new Ws.Client(url); ws.on('error', function(it){ return log0(it.message); }); ws.on('open', function(){ log0("opened " + url); return me.emit('connect'); }); return ws.on('close', function(){ log0("closed " + url); me.emit('disconnect'); return setTimeout(connect, opts.reconnectPeriod); }); } connect(); return me; }, send: function(id, data){ var ref$; return ws.send(JSON.stringify((ref$ = {}, ref$[id + ""] = data, ref$))); } }); function import$(obj, src){ var own = {}.hasOwnProperty; for (var key in src) if (own.call(src, key)) obj[key] = src[key]; return obj; } function clone$(it){ function fun(){} fun.prototype = it; return new fun; } }).call(this);