Permalink
Browse files

Merge pull request #428 from jdahlq/master

Enhance the dist files to work with CommonJS loaders
  • Loading branch information...
2 parents 6062a06 + 96e69a4 commit b6aa5c0553fe1550442009d52e2de16be6bfecd5 @rauchg rauchg committed Jun 20, 2012
Showing with 52 additions and 7 deletions.
  1. +17 −1 bin/builder.js
  2. +34 −5 dist/socket.io.js
  3. +1 −1 dist/socket.io.min.js
View
@@ -84,6 +84,15 @@ var baseTransports = {
};
/**
+ * Wrappers for client-side usage.
+ * This enables usage in both top-level browser window and client-side CommonJS systems.
+ * If doing a node build for server-side client, this wrapper is NOT included.
+ * @api private
+ */
+var wrapperPre = "\nvar io = ('undefined' === typeof module ? {} : module.exports);\n(function() {\n";
+var wrapperPost = "\n})();";
+
+/**
* Builds a custom Socket.IO distribution based on the transports that you
* need. You can configure the build to create development build or production
* build (minified).
@@ -168,10 +177,14 @@ var builder = module.exports = function () {
// we are done, did we error?
if (error) return callback(error);
- // concatinate the file contents in order
+ // start with the license header
var code = development
, ignore = 0;
+ // pre-wrapper for non-server-side builds
+ if (!settings.node) code += wrapperPre;
+
+ // concatenate the file contents in order
files.forEach(function (file) {
code += results[file];
});
@@ -183,6 +196,9 @@ var builder = module.exports = function () {
});
}
+ // post-wrapper for non-server-side builds
+ if (!settings.node)code += wrapperPost;
+
code = activeXObfuscator(code);
// Search for conditional code blocks that need to be removed as they
View
@@ -1,5 +1,8 @@
/*! Socket.IO.js build:0.9.6, development. Copyright(c) 2011 LearnBoost <dev@learnboost.com> MIT Licensed */
+var io = ('undefined' === typeof module ? {} : module.exports);
+(function() {
+
/**
* socket.io
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -453,6 +456,15 @@
util.ua.webkit = 'undefined' != typeof navigator
&& /webkit/i.test(navigator.userAgent);
+ /**
+ * Detect iPad/iPhone/iPod.
+ *
+ * @api public
+ */
+
+ util.ua.iDevice = 'undefined' != typeof navigator
+ && /iPad|iPhone|iPod/i.test(navigator.userAgent);
+
})('undefined' != typeof io ? io : module.exports, this);
/**
@@ -1588,6 +1600,7 @@
function complete (data) {
if (data instanceof Error) {
+ self.connecting = false;
self.onError(data.message);
} else {
fn.apply(null, data.split(':'));
@@ -1625,6 +1638,7 @@
if (xhr.status == 200) {
complete(xhr.responseText);
} else {
+ self.connecting = false;
!self.reconnecting && self.onError(xhr.responseText);
}
}
@@ -1668,7 +1682,7 @@
var self = this;
self.connecting = true;
-
+
this.handshake(function (sid, heartbeat, close, transports) {
self.sessionid = sid;
self.closeTimeout = close * 1000;
@@ -2348,10 +2362,23 @@
* @api public
*/
- WS.prototype.send = function (data) {
- this.websocket.send(data);
- return this;
- };
+ // Do to a bug in the current IDevices browser, we need to wrap the send in a
+ // setTimeout, when they resume from sleeping the browser will crash if
+ // we don't allow the browser time to detect the socket has been closed
+ if (io.util.ua.iDevice) {
+ WS.prototype.send = function (data) {
+ var self = this;
+ setTimeout(function() {
+ self.websocket.send(data);
+ },0);
+ return this;
+ };
+ } else {
+ WS.prototype.send = function (data) {
+ this.websocket.send(data);
+ return this;
+ };
+ }
/**
* Payload
@@ -3787,3 +3814,5 @@ var swfobject=function(){var D="undefined",r="object",S="Shockwave Flash",W="Sho
, 'undefined' != typeof io ? io : module.parent.exports
, this
);
+
+})();
View

Large diffs are not rendered by default.

Oops, something went wrong.

1 comment on commit b6aa5c0

@ghost

ghost commented on b6aa5c0 Jun 20, 2012

Awesome news!

Please sign in to comment.