Permalink
Browse files

Get things working directly in node

  • Loading branch information...
1 parent b6fd9b1 commit 30c31da722683282482f5551f7ffd91a791042e9 @legastero committed Mar 3, 2014
Showing with 88 additions and 37 deletions.
  1. +1 −1 Gruntfile.js
  2. +1 −30 index.js
  3. +4 −2 lib/client.js
  4. +33 −0 lib/plugins/index-browser.js
  5. +35 −0 lib/plugins/index.js
  6. +6 −1 lib/websocket.js
  7. +8 −3 package.json
View
@@ -24,7 +24,7 @@ module.exports = function (grunt) {
}
},
jshint: {
- files: ['Gruntfile.js', 'index.js', 'lib/**.js', 'test/**.js'],
+ files: ['Gruntfile.js', 'index.js', 'lib/**.js', 'lib/stanza/**.js', 'lib/plugins/**.js', 'test/**.js'],
options: grunt.file.readJSON('.jshintrc')
}
});
View
@@ -18,36 +18,7 @@ exports.jxt = require('jxt');
exports.createClient = function (opts) {
var client = new exports.Client(opts);
-
- client.use(require('./lib/plugins/roster'));
- client.use(require('./lib/plugins/disco'));
- client.use(require('./lib/plugins/chatstates'));
- client.use(require('./lib/plugins/delayed'));
- client.use(require('./lib/plugins/forwarding'));
- client.use(require('./lib/plugins/carbons'));
- client.use(require('./lib/plugins/time'));
- client.use(require('./lib/plugins/mam'));
- client.use(require('./lib/plugins/receipts'));
- client.use(require('./lib/plugins/idle'));
- client.use(require('./lib/plugins/correction'));
- client.use(require('./lib/plugins/attention'));
- client.use(require('./lib/plugins/version'));
- client.use(require('./lib/plugins/invisible'));
- client.use(require('./lib/plugins/muc'));
- client.use(require('./lib/plugins/pubsub'));
- client.use(require('./lib/plugins/avatar'));
- client.use(require('./lib/plugins/private'));
- client.use(require('./lib/plugins/bookmarks'));
- client.use(require('./lib/plugins/jingle'));
- client.use(require('./lib/plugins/json'));
- client.use(require('./lib/plugins/hashes'));
- client.use(require('./lib/plugins/extdisco'));
- client.use(require('./lib/plugins/geoloc'));
- client.use(require('./lib/plugins/vcard'));
- client.use(require('./lib/plugins/oob'));
- client.use(require('./lib/plugins/ping'));
- client.use(require('./lib/plugins/keepalive'));
- client.use(require('./lib/plugins/command'));
+ client.use(require('./lib/plugins'));
return client;
};
View
@@ -6,6 +6,8 @@ var util = require('util');
var Promise = require('bluebird');
var async = require('async');
var uuid = require('node-uuid');
+var b64decode = require('atob');
+var b64encode = require('btoa');
var SASL = require('./stanza/sasl');
var Message = require('./stanza/message');
var Presence = require('./stanza/presence');
@@ -125,7 +127,7 @@ function Client(opts) {
if (mech.cache) {
_.each(mech.cache, function (val, key) {
- self.config.credentials[key] = btoa(val);
+ self.config.credentials[key] = b64encode(val);
});
self.emit('credentials:update', self.config.credentials);
}
@@ -378,7 +380,7 @@ Client.prototype.getCredentials = function () {
var cachedBinary = ['saltedPassword', 'clientKey', 'serverKey'];
cachedBinary.forEach(function (key) {
if (result[key]) {
- result[key] = atob(result[key]);
+ result[key] = b64decode(result[key]);
}
});
@@ -0,0 +1,33 @@
+"use strict";
+
+module.exports = function (client) {
+ client.use(require('./roster'));
+ client.use(require('./disco'));
+ client.use(require('./chatstates'));
+ client.use(require('./delayed'));
+ client.use(require('./forwarding'));
+ client.use(require('./carbons'));
+ client.use(require('./time'));
+ client.use(require('./mam'));
+ client.use(require('./receipts'));
+ client.use(require('./idle'));
+ client.use(require('./correction'));
+ client.use(require('./attention'));
+ client.use(require('./version'));
+ client.use(require('./invisible'));
+ client.use(require('./muc'));
+ client.use(require('./pubsub'));
+ client.use(require('./avatar'));
+ client.use(require('./private'));
+ client.use(require('./bookmarks'));
+ client.use(require('./json'));
+ client.use(require('./hashes'));
+ client.use(require('./extdisco'));
+ client.use(require('./geoloc'));
+ client.use(require('./vcard'));
+ client.use(require('./oob'));
+ client.use(require('./ping'));
+ client.use(require('./keepalive'));
+ client.use(require('./command'));
+ client.use(require('./jingle'));
+};
View
@@ -0,0 +1,35 @@
+"use strict";
+
+module.exports = function (client) {
+ client.use(require('./roster'));
+ client.use(require('./disco'));
+ client.use(require('./chatstates'));
+ client.use(require('./delayed'));
+ client.use(require('./forwarding'));
+ client.use(require('./carbons'));
+ client.use(require('./time'));
+ client.use(require('./mam'));
+ client.use(require('./receipts'));
+ client.use(require('./idle'));
+ client.use(require('./correction'));
+ client.use(require('./attention'));
+ client.use(require('./version'));
+ client.use(require('./invisible'));
+ client.use(require('./muc'));
+ client.use(require('./pubsub'));
+ client.use(require('./avatar'));
+ client.use(require('./private'));
+ client.use(require('./bookmarks'));
+ client.use(require('./json'));
+ client.use(require('./hashes'));
+ client.use(require('./extdisco'));
+ client.use(require('./geoloc'));
+ client.use(require('./vcard'));
+ client.use(require('./oob'));
+ client.use(require('./ping'));
+ client.use(require('./keepalive'));
+ client.use(require('./command'));
+
+ // For now, we can't import jingle stuff in node
+ //client.use(require('./jingle'));
+};
View
@@ -11,6 +11,11 @@ var Message = require('./stanza/message');
var Presence = require('./stanza/presence');
var Iq = require('./stanza/iq');
+var WS = (require('faye-websocket') && require('faye-websocket').Client) ?
+ require('faye-websocket').Client :
+ window.WebSocket;
+
+
function WSConnection(sm) {
var self = this;
@@ -136,7 +141,7 @@ WSConnection.prototype.connect = function (opts) {
self.streamStart = '<stream:stream xmlns:stream="http://etherx.jabber.org/streams">';
self.streamEnd = '</stream:stream>';
- self.conn = new WebSocket(opts.wsURL, 'xmpp');
+ self.conn = new WS(opts.wsURL, 'xmpp');
self.conn.onerror = function (e) {
e.preventDefault();
self.emit('disconnected', self);
View
@@ -5,22 +5,27 @@
"author": "Lance Stout <lance@andyet.net>",
"browser": {
"request": "browser-request",
- "crypto": "crypto-browserify"
+ "crypto": "crypto-browserify",
+ "faye-websocket": "",
+ "./lib/plugins/index.js": "./lib/plugins/index-browser.js"
},
"bugs": "https://github.com/legastero/stanza.io/issues",
"contributors": [
"Steven Lloyd Watkin <lloyd@evilprofessor.co.uk>"
],
"dependencies": {
"async": "0.2.9",
+ "atob": "1.1.0",
"bluebird": "1.0.0",
+ "browser-request": "0.3.1",
+ "btoa": "1.1.1",
"crypto-browserify": "1.0.3",
+ "faye-websocket": "0.7.2",
"hostmeta": "0.3.5",
"jingle": "0.3.6",
"jxt": "0.7.0",
"node-uuid": "1.4.0",
"request": "2.27.0",
- "browser-request": "0.3.1",
"sasl-anonymous": "0.1.0",
"sasl-digest-md5": "0.1.0",
"sasl-external": "0.1.0",
@@ -52,4 +57,4 @@
"type": "git",
"url": "https://github.com/legastero/stanza.io.git"
}
-}
+}

0 comments on commit 30c31da

Please sign in to comment.