Coverage

94%
213
202
11

ConnectionClient.js

100%
34
34
0
LineHitsSource
12var dnode, events, ConnectionClient, slice$ = [].slice;
22dnode = require('dnode');
32events = require('events');
42module.exports = ConnectionClient = (function(superclass){
52 var prototype = extend$((import$(ConnectionClient, superclass).displayName = 'ConnectionClient', ConnectionClient), superclass).prototype, constructor = ConnectionClient;
62 function ConnectionClient(socket){
712 var remote, callbacks, d, this$ = this instanceof ctor$ ? this : new ctor$;
812 remote = null;
912 callbacks = {
10 message: function(message){
111 return this$.emit('message', message);
12 },
13 connect: function(){
141 return this$.emit('connect');
15 },
16 init: function(){
172 return this$.emit('init');
18 }
19 };
2012 (d = dnode(callbacks)).on('remote', function(r){
214 return remote = r;
22 });
2312 socket.pipe(d).pipe(socket);
2412 ['connect', 'close', 'send'].forEach(function(func){
2536 return this$[func] = function(){
267 var args;
277 args = slice$.call(arguments);
287 if (remote == null) {
293 throw new Error('Not connected');
30 } else {
314 return remote[func].apply(remote, args);
32 }
33 };
34 });
3512 return this$;
364 } function ctor$(){} ctor$.prototype = prototype;
372 return ConnectionClient;
38}(events.EventEmitter));
392function extend$(sub, sup){
404 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
412 (sub.prototype = new fun).constructor = sub;
422 if (typeof sup.extended == 'function') sup.extended(sub);
432 return sub;
44}
452function import$(obj, src){
462 var own = {}.hasOwnProperty;
476 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
482 return obj;
49}

ConnectionServer.js

100%
77
77
0
LineHitsSource
12var dnode, events, ircc, SingletonServer, ConnectionServer, slice$ = [].slice;
22dnode = require('dnode');
32events = require('events');
42ircc = require('ircc');
52SingletonServer = require('./SingletonServer');
62module.exports = ConnectionServer = (function(superclass){
72 var prototype = extend$((import$(ConnectionServer, superclass).displayName = 'ConnectionServer', ConnectionServer), superclass).prototype, constructor = ConnectionServer;
82 function ConnectionServer(){
926 var this$ = this instanceof ctor$ ? this : new ctor$;
1026 this$._onServerClose = bind$(this$, '_onServerClose', prototype);
1126 this$._onServerError = bind$(this$, '_onServerError', prototype);
1226 this$._onSuperfluous = bind$(this$, '_onSuperfluous', prototype);
1326 this$._onListening = bind$(this$, '_onListening', prototype);
1426 this$._onClientConnection = bind$(this$, '_onClientConnection', prototype);
1526 this$.send = bind$(this$, 'send', prototype);
1626 this$.close = bind$(this$, 'close', prototype);
1726 this$.connect = bind$(this$, 'connect', prototype);
1826 this$.listen = bind$(this$, 'listen', prototype);
1926 this$.server = new SingletonServer;
2026 this$.server.on('connection', this$._onClientConnection);
2126 this$.server.on('listening', this$._onListening);
2226 this$.server.on('superfluous', this$._onSuperfluous);
2326 this$.server.on('error', this$._onServerError);
2426 this$.server.on('close', this$._onServerClose);
2526 this$.connection = null;
2626 return this$;
274 } function ctor$(){} ctor$.prototype = prototype;
282 prototype.listen = function(path){
291 return this.server.listen(path);
30 };
312 prototype.connect = function(port, host){
328 var this$ = this;
338 if (this.connection == null) {
347 this.connection = new ircc.Connection;
357 this.connection.connect(port, host);
367 this.connection.on('message', function(message){
371 return this$.emit('message', message);
38 });
397 return this.connection.on('connect', function(){
401 return this$.emit('connect');
41 });
42 }
43 };
442 prototype.close = function(){
453 if (this.connection != null) {
462 this.connection.close();
47 }
483 return this.server.close();
49 };
502 prototype.send = function(){
512 var args, ref$;
522 args = slice$.call(arguments);
532 if (this.connection != null) {
541 return (ref$ = this.connection).send.apply(ref$, args);
55 }
56 };
572 prototype._onClientConnection = function(socket){
5814 var api, d, this$ = this;
5914 api = {
60 connect: this.connect,
61 close: this.close,
62 send: this.send
63 };
6414 (d = dnode(api)).on('remote', function(remote){
656 this$.on('message', bind$(remote, 'message'));
666 if (this$.connection != null) {
672 return remote.connect();
68 } else {
694 this$.on('connect', bind$(remote, 'connect'));
704 return remote.init();
71 }
72 });
7314 return socket.pipe(d).pipe(socket);
74 };
752 prototype._onListening = function(){
762 return this.emit('listening');
77 };
782 prototype._onSuperfluous = function(){
791 return this.emit('superfluous');
80 };
812 prototype._onServerError = function(error){
821 return this.emit('error', error);
83 };
842 prototype._onServerClose = function(){
851 return this.emit('close');
86 };
872 return ConnectionServer;
88}(events.EventEmitter));
892function bind$(obj, key, target){
90280 return function(){ return (target || obj)[key].apply(obj, arguments) };
91}
922function extend$(sub, sup){
934 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
942 (sub.prototype = new fun).constructor = sub;
952 if (typeof sup.extended == 'function') sup.extended(sub);
962 return sub;
97}
982function import$(obj, src){
992 var own = {}.hasOwnProperty;
1006 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
1012 return obj;
102}

SingletonServer.js

100%
62
62
0
LineHitsSource
12var fs, net, events, SingletonServer;
22fs = require('fs');
32net = require('net');
42events = require('events');
52module.exports = SingletonServer = (function(superclass){
62 var prototype = extend$((import$(SingletonServer, superclass).displayName = 'SingletonServer', SingletonServer), superclass).prototype, constructor = SingletonServer;
72 function SingletonServer(){
814 var this$ = this instanceof ctor$ ? this : new ctor$;
914 this$._onConnection = bind$(this$, '_onConnection', prototype);
1014 this$._onError = bind$(this$, '_onError', prototype);
1114 this$.server = net.createServer();
1214 this$.server.on('error', this$._onError);
1314 this$.server.on('connection', this$._onConnection);
1414 this$.server.on('listening', function(){
151 return this$.emit('listening');
16 });
1714 this$.server.on('close', function(){
181 return this$.emit('close');
19 });
2014 this$.client = null;
2114 return this$;
224 } function ctor$(){} ctor$.prototype = prototype;
232 prototype.listen = function(path){
244 this.path = path;
254 return this.server.listen(this.path);
26 };
272 prototype.close = function(){
282 if (this.client != null) {
291 this.client.end();
30 }
312 return this.server.close();
32 };
332 prototype._onError = function(error){
343 var sock, this$ = this;
353 if (error.code === 'EADDRINUSE') {
362 sock = net.createConnection(this.path);
372 sock.on('connect', function(){
381 sock.end();
391 return this$.emit('superfluous');
40 });
412 return sock.on('error', function(error){
421 if (error.code === 'ECONNREFUSED') {
431 fs.unlink(this$.path);
441 return this$.listen(this$.path);
45 }
46 });
47 } else {
481 return this.emit('error', error);
49 }
50 };
512 prototype._onConnection = function(socket){
528 var this$ = this;
538 if (this.client != null) {
542 socket.end();
552 return socket.on('error', function(){});
56 } else {
576 this.client = socket;
586 socket.on('close', function(){
591 return this$.client = null;
60 });
616 socket.on('error', function(){
621 return this$.client = null;
63 });
646 return this.emit('connection', socket);
65 }
66 };
672 return SingletonServer;
68}(events.EventEmitter));
692function bind$(obj, key, target){
7039 return function(){ return (target || obj)[key].apply(obj, arguments) };
71}
722function extend$(sub, sup){
734 function fun(){} fun.prototype = (sub.superclass = sup).prototype;
742 (sub.prototype = new fun).constructor = sub;
752 if (typeof sup.extended == 'function') sup.extended(sub);
762 return sub;
77}
782function import$(obj, src){
792 var own = {}.hasOwnProperty;
806 for (var key in src) if (own.call(src, key)) obj[key] = src[key];
812 return obj;
82}

createConnection.js

72%
40
29
11
LineHitsSource
12var net, path, events, spawn, ConnectionServer, ConnectionClient, calledDirectly, createConnection, server;
22net = require('net');
32path = require('path');
42events = require('events');
52spawn = require('child_process').spawn;
62ConnectionServer = require('./ConnectionServer');
72ConnectionClient = require('./ConnectionClient');
82calledDirectly = module === require.main;
92if (!calledDirectly) {
102 module.exports = createConnection = function(filename, callback){
1112 var ee, server;
1212 ee = new events.EventEmitter;
1312 filename = path.resolve(filename || 'ircc.sock');
1412 server = spawn('node', [module.filename, filename], {
15 detached: true
16 });
1712 server.unref();
1812 server.stdout.on('data', function(data){
196 var ready, socket, client;
206 data = data.toString();
216 ready = data === 'listening' || data === 'superfluous';
226 if (ready) {
235 socket = net.createConnection(filename);
245 client = new ConnectionClient(socket);
255 ee.emit('client', client);
265 if (typeof callback === 'function') {
271 return callback(client);
28 }
29 } else {
301 return ee.emit('error', new Error("Unexpected server output: " + data));
31 }
32 });
3312 server.stderr.on('data', function(data){
341 return ee.emit('error', new Error(data.toString()));
35 });
3612 return ee;
37 };
38} else {
390 server = new ConnectionServer;
400 server.on('listening', function(){
410 return process.stdout.write('listening');
42 });
430 server.on('superfluous', function(){
440 return process.stdout.write('superfluous');
45 });
460 server.on('error', function(e){
470 process.stderr.write('error:', e);
480 return process.exit(1);
49 });
500 server.on('close', function(){
510 return process.exit(0);
52 });
530 server.listen(process.argv[2]);
54}