Skip to content

Commit

Permalink
Merge pull request #105 from strophe/amd-merge
Browse files Browse the repository at this point in the history
Add support for the Asynchronous Module Definition (AMD) and require.js
  • Loading branch information
Gordin committed Feb 21, 2015
2 parents 4db5946 + b057402 commit 6fca47a
Show file tree
Hide file tree
Showing 25 changed files with 512 additions and 166 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
# Strophe.js Change Log

## Version 1.1.4 - Unreleased
## Version 1.2.0 - 2015-02-21
* Add bower package manager support.
* Add commandline testing support via qunit-phantomjs-runner
* Add integrated testing via TravisCI.
* Fix Websocket connections now use the current XMPP-over-WebSockets RFC
* #25 Item-not-found-error caused by long term request.
* #29 Add support for the Asynchronous Module Definition (AMD) and require.js
* #30 Base64 encoding problem in some older browsers.
* #45 Move xhlr plugin to strophejs-plugins repo.
* #60 Fixed deletion of handlers in websocket connections
* #62 Add `xmlunescape` method.
* #67 Use correct Content-Type in BOSH
* #70 `_onDisconnectTimeout` never tiggers because maxRetries is undefined.
* #71 switched to case sensitive handling of XML elements
* #73 `getElementsByTagName` problem with namespaced elements.
* #76 respect "Invalid SID" message
* #79 connect.pause work correctly again
* #90 The queue data was not reset in .reset() method.
* #104 Websocket connections with MongooseIM work now

## Version 1.1.3 - 2014-01-20
* Fix SCRAM-SHA1 auth now works for multiple connections at the same time
Expand Down
17 changes: 17 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = function(grunt){
}
}
},

concat: {
dist: {
src: ['src/wrap_header.js', 'src/base64.js', 'src/sha1.js', 'src/md5.js', 'src/polyfills.js', 'src/core.js', 'src/bosh.js', 'src/websocket.js', 'src/wrap_footer.js'],
Expand Down Expand Up @@ -138,4 +139,20 @@ module.exports = function(grunt){
grunt.registerTask("release", ["default", "doc", "copy:prepare-release", "shell:tar", "shell:zip"]);
grunt.registerTask("all", ["release", "clean"]);
grunt.registerTask("test", ["connect", "qunit"]);

grunt.registerTask('almond', 'Create an almond build with r.js', function () {
var done = this.async();
require('child_process').exec(
'./node_modules/requirejs/bin/r.js -o build.js optimize=none out=strophe.almond.js',
function (err, stdout, stderr) {
if (err) {
grunt.log.write('build failed with error code '+err.code);
grunt.log.write(stderr);
}
grunt.log.write(stdout);
done();
}
);
grunt.task.run('uglify');
});
};
13 changes: 4 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,16 @@ release:
@@echo "Release created."
@@echo

check:: stamp-bower
check::
make stamp-bower
$(PHANTOMJS) node_modules/qunit-phantomjs-runner/runner-list.js tests/strophe.html

clean:
rm -f stamp-npm stamp-bower
rm -rf node_modules bower_components
@@echo "Cleaning" node_modules "..."
@@rm -rf node_modules
@@echo "Cleaning" $(STROPHE) "..."
@@rm -f stamp-npm stamp-bower
@@rm -rf node_modules bower_components
@@rm -f $(STROPHE)
@@echo "Cleaning" $(STROPHE_MIN) "..."
@@rm -f $(STROPHE_MIN)
@@echo "Cleaning minified plugins..."
@@rm -f $(PLUGIN_FILES_MIN)
@@echo "Cleaning documentation..."
@@rm -rf $(NDPROJ_DIR) $(DOC_DIR) $(DOC_TEMP)
@@echo "Done."
@@echo
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Strophe.js
# Strophe.js

[![Build Status](https://travis-ci.org/strophe/strophejs.png?branch=master)](https://travis-ci.org/strophe/strophejs)

Strophe.js is a JavaScript library for speaking XMPP via BOSH
([XEP 124](http://xmpp.org/extensions/xep-0124.html)
and [XEP 206](http://xmpp.org/extensions/xep-0206.html)) and WebSockets
(draft-ietf-xmpp-websocket-00).
([RFC 7395](http://tools.ietf.org/html/rfc7395)).

Its primary purpose is to enable web-based, real-time XMPP applications that
run in any browser.
Expand Down
5 changes: 2 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,17 @@
"release_checklist.txt",
"Makefile",
"Gruntfile.js",
"component.json",
"contrib",
"examples",
"tests",
"plugins",
"src"
],
"dependencies": {
"sinon": "http://sinonjs.org/releases/sinon-1.12.2.js",
"sinon-qunit": "~2.0.0",
"qunit": "~1.16.0",
"jquery": "1.11.0",
"requirejs": "~2.1.15"
"requirejs": "~2.1.15",
"almond": "~0.3.0"
}
}
7 changes: 7 additions & 0 deletions build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
({
baseUrl: ".",
name: "bower_components/almond/almond.js",
out: "strophe.js",
include: ['main'],
mainConfigFile: 'main.js'
})
21 changes: 21 additions & 0 deletions examples/amd.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<head>
<title>Strophe.js AMD Example</title>
<script src="../main.js"></script>
<script src="../bower_components/requirejs/require.js" data-main="main.js"></script>
</head>
<body>
<div id='login' style='text-align: center'>
<form name='cred'>
<label for='jid'>JID:</label>
<input type='text' id='jid'>
<label for='pass'>Password:</label>
<input type='password' id='pass'>
<input type='button' id='connect' value='connect'>
</form>
</div>
<hr>
<div id='log'></div>
</body>
</html>
4 changes: 2 additions & 2 deletions examples/basic.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var BOSH_SERVICE = 'http://bosh.metajack.im:5280/xmpp-httpbind'
var BOSH_SERVICE = 'http://bosh.metajack.im:5280/xmpp-httpbind';
var connection = null;

function log(msg)
Expand Down Expand Up @@ -52,4 +52,4 @@ $(document).ready(function () {
connection.disconnect();
}
});
});
});
59 changes: 59 additions & 0 deletions examples/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
config.baseUrl = '../';
require.config(config);
if (typeof(require) === 'function') {
require(["jquery", "strophe", ], function($, wrapper) {
Strophe = wrapper.Strophe;

var BOSH_SERVICE = 'http://bosh.metajack.im:5280/xmpp-httpbind';
var connection = null;

function log(msg) {
$('#log').append('<div></div>').append(document.createTextNode(msg));
}

function rawInput(data) {
log('RECV: ' + data);
}

function rawOutput(data) {
log('SENT: ' + data);
}

function onConnect(status) {
if (status == Strophe.Status.CONNECTING) {
log('Strophe is connecting.');
} else if (status == Strophe.Status.CONNFAIL) {
log('Strophe failed to connect.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.DISCONNECTING) {
log('Strophe is disconnecting.');
} else if (status == Strophe.Status.DISCONNECTED) {
log('Strophe is disconnected.');
$('#connect').get(0).value = 'connect';
} else if (status == Strophe.Status.CONNECTED) {
log('Strophe is connected.');
connection.disconnect();
}
}

$(document).ready(function () {
connection = new Strophe.Connection(BOSH_SERVICE);
connection.rawInput = rawInput;
connection.rawOutput = rawOutput;
$('#connect').bind('click', function () {
var button = $('#connect').get(0);
if (button.value == 'connect') {
button.value = 'disconnect';
connection.connect(
$('#jid').get(0).value,
$('#pass').get(0).value,
onConnect
);
} else {
button.value = 'connect';
connection.disconnect();
}
});
});
});
}
42 changes: 42 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
var config;
if (typeof(require) === 'undefined') {
/* XXX: Hack to work around r.js's stupid parsing.
* We want to save the configuration in a variable so that we can reuse it in
* tests/main.js.
*/
require = {
config: function (c) {
config = c;
}
};
}

require.config({
baseUrl: '.',
paths: {
// Strophe.js src files
"strophe-base64": "src/base64",
"strophe-bosh": "src/bosh",
"strophe-core": "src/core",
"strophe": "src/wrapper",
"strophe-md5": "src/md5",
"strophe-sha1": "src/sha1",
"strophe-websocket": "src/websocket",
"strophe-polyfill": "src/polyfills",

// Examples
"basic": "examples/basic",

// Tests
"jquery": "bower_components/jquery/dist/jquery",
"sinon": "bower_components/sinon/index",
"sinon-qunit": "bower_components/sinon-qunit/lib/sinon-qunit",
"tests": "tests/tests"
}
});

if (typeof(require) === 'function') {
require(["strophe"], function(Strophe) {
window.Strophe = Strophe;
});
}
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "strophe.js",
"description": "Strophe.js is an XMPP library for JavaScript",
"version": "1.1.4dev1",
"version": "1.2.0",
"homepage": "http://strophe.im/strophejs",
"repository": {
"type": "git",
Expand Down Expand Up @@ -30,7 +30,8 @@
"dodo",
"Lee Boynton (lboynton)",
"Theo Cushion (theozaurus)",
"Brendon Crawford (brendoncrawford)"
"Brendon Crawford (brendoncrawford)",
"JC Brand (jcbrand)"
],
"licenses": [
"MIT"
Expand Down Expand Up @@ -62,12 +63,14 @@
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-connect": "^0.9.0",
"grunt-contrib-copy": "~0.5.0",
"grunt-contrib-jshint": "~0.8.0",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-qunit": "^0.5.2",
"grunt-contrib-requirejs": "^0.4.4",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-watch": "~0.5.3",
"grunt-mkdir": "~0.1.1",
"grunt-natural-docs": "~0.1.1",
"grunt-shell": "~0.6.1"
"grunt-shell": "~0.6.1",
"requirejs": "~2.1.15"
}
}
15 changes: 12 additions & 3 deletions src/base64.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com

var Base64 = (function () {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(function () {
return factory();
});
} else {
// Browser globals
root.Base64 = factory();
}
}(this, function () {
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";

var obj = {
Expand Down Expand Up @@ -76,6 +86,5 @@ var Base64 = (function () {
return output;
}
};

return obj;
})();
}));
22 changes: 18 additions & 4 deletions src/bosh.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@
*/

/* jshint undef: true, unused: true:, noarg: true, latedef: true */
/*global window, setTimeout, clearTimeout,
XMLHttpRequest, ActiveXObject,
Strophe, $build */

/* global define, window, setTimeout, clearTimeout, XMLHttpRequest, ActiveXObject, Strophe, $build */

(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['strophe-core'], function (core) {
return factory(
core.Strophe,
core.$build
);
});
} else {
// Browser globals
return factory(Strophe, $build);
}
}(this, function (Strophe, $build) {

/** PrivateClass: Strophe.Request
* _Private_ helper class that provides a cross implementation abstraction
Expand Down Expand Up @@ -853,3 +865,5 @@ Strophe.Bosh.prototype = {
}
}
};
return Strophe;
}));
Loading

0 comments on commit 6fca47a

Please sign in to comment.