Skip to content

Commit

Permalink
shim out for FXOS
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Desaulniers committed Sep 24, 2013
1 parent ed2ef9f commit c728189
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
_build/
*.swp

This comment has been minimized.

Copy link
@mcepl

mcepl Nov 6, 2013

This doesn't belong to the shared .gitignore, but to your own .git/info/exclude. Nobody is interested in you using vim (or whatever editor is leaving .swp files behind).

This comment has been minimized.

Copy link
@nickdesaulniers

nickdesaulniers Nov 6, 2013

Owner

Thanks for the tip!

2 changes: 1 addition & 1 deletion lib/codes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = { // {{{
window.codes = { // {{{
"001" : {
"name" : "rpl_welcome",
"type" : "reply"
Expand Down
77 changes: 63 additions & 14 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,43 @@
along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

exports.Client = Client;
var net = require('net');
var tls = require('tls');
var util = require('util');

var colors = require('./colors');
exports.colors = colors;
window.Client = Client;
var net = {
createConnection: function (port, server) {
return {
_conn: navigator.mozTCPSocket.open(server, port),
addListener: function (evt, cb) {
if (evt === 'connect') {
evt = 'open';
} else if (evt === 'end') {
evt = 'close';
}
//console.log('trying to set on' + evt + ' on the connection');
this._conn['on' + evt] = function (msg) {
//console.log('connection got an on' + evt + ' event');
if(msg && 'data' in msg) {
cb(msg.data);
} else {
cb();
}
};
},
setTimeout: function () {},
setEncoding: function () {},
write: function (data) {
console.log('sending: ' + data);
this._conn.send(data);
},
};
},
};
var tls = {};
var util = {
log: console.log.bind(console),
inspect: console.log.bind(console),
};

var replyFor = require('./codes');
var replyFor = window.codes;

function Client(server, nick, opt) {
var self = this;
Expand Down Expand Up @@ -94,6 +122,7 @@ function Client(server, nick, opt) {
}

self.addListener("raw", function (message) { // {{{
//console.log('in raw event, got: ' + JSON.stringify(message));
switch ( message.command ) {
case "rpl_welcome":
// Set nick to whatever the server decided it really is
Expand Down Expand Up @@ -557,12 +586,8 @@ function Client(server, nick, opt) {
self.send.apply(self, ['JOIN'].concat(channel.split(' ')));
});
});

process.EventEmitter.call(this);
}

util.inherits(Client, process.EventEmitter);

Client.prototype.conn = null;
Client.prototype.prefixForMode = {};
Client.prototype.modeForPrefix = {};
Expand Down Expand Up @@ -649,6 +674,7 @@ Client.prototype.connect = function ( retryCount, callback ) { // {{{
});
var buffer = '';
self.conn.addListener("data", function (chunk) {
console.log(chunk);
buffer += chunk;
var lines = buffer.split("\r\n");
buffer = lines.pop();
Expand Down Expand Up @@ -782,7 +808,7 @@ Client.prototype.part = function(channel, message, callback) { // {{{
if (this.opt.channels.indexOf(channel) != -1) {
this.opt.channels.splice(this.opt.channels.indexOf(channel), 1);
}

if (message) {
this.send('PART', channel, message);
} else {
Expand Down Expand Up @@ -861,6 +887,29 @@ Client.prototype._handleCTCP = function(from, to, text, type, message) {
Client.prototype.ctcp = function(to, type, text) {
return this[type === 'privmsg' ? 'say' : 'notice'](to, '\1'+text+'\1');
}
Client.prototype.addListener = function (evt, cb) {
//console.log('Listening for a ' + evt + ' event');
document.addEventListener(evt, function (data) {
//console.log('heard a ' + evt + ' event');
//console.log(JSON.stringify(data.detail));
cb(data.detail.message);
});
};
Client.prototype.emit = function (evt, a, b, c, d, e) {
if (evt === 'connect') {
evt = 'open';
}
//console.log('trying to emit ' + evt);
var e = new CustomEvent(evt, { detail: { message: a }});
document.dispatchEvent(e);
};
Client.prototype.once = function (evt, cb) {
//console.log('Listening once for a ' + evt + ' evt');
var e = document.addEventListener(evt, function (data) {
document.removeEventListener(evt, e);
cb(data);
});
};

/*
* parseMessage(line, stripColors)
Expand Down Expand Up @@ -924,4 +973,4 @@ function parseMessage(line, stripColors) { // {{{
return message;
} // }}}

exports.parseMessage = parseMessage;
window.parseMessage = parseMessage;

0 comments on commit c728189

Please sign in to comment.