Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/io.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@

io.EventEmitter = process.EventEmitter;

/**
* Expose Socket namespace
*
* @api private
*/

io.SocketNamespace = require('./namespace').SocketNamespace;

/**
* Expose Transport
*
Expand All @@ -106,8 +114,9 @@
* Expose all transports
*/

require('./transports/websocket');
io.transports.forEach(function (t) {
//io.Transport[t] = require('./transports/node/' + t);
io.Transport[t] = require('./transports/' + t)[t];
});

/**
Expand Down
30 changes: 29 additions & 1 deletion lib/socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@

(function (exports, io) {

/* Stub code for a node.js context */
if ('object' === typeof module && 'function' === typeof require) {
var document = {};
var window = {location:{}};
var http = require('http'),
parseurl = require('url').parse;
var web = false;
} else {
var web = true;
}

/**
* Expose constructor.
*/
Expand Down Expand Up @@ -132,7 +143,24 @@
, '?t=' + + new Date
].join('/');

if (this.isXDomain()) {
if (!web) {
var o = {
host: options.host,
port: options.port,
path: '/' + this.options.resource + '/' + io.protocol + '/'
};
http.get(o, function(res) {
var data = '';
res.on('data', function(chunk) { data += chunk; });
res.on('end', function() {
if (res.statusCode == 200) {
complete(data);
} else {
!self.reconnecting && self.onError(xhr.responseText);
}
});
});
} else if (this.isXDomain()) {
var insertAt = document.getElementsByTagName('script')[0]
, script = document.createElement('SCRIPT');

Expand Down
11 changes: 10 additions & 1 deletion lib/transports/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

(function (exports, io) {

/**
* Add stubs for nodejs websocket-client
*/

if ('object' === typeof module && 'function' === typeof require) {
var window = require('websocket-client');
var WebSocket = window.WebSocket;
}

/**
* Expose constructor.
*/
Expand Down Expand Up @@ -41,7 +50,7 @@
*/

WS.prototype.name = 'websocket';

/**
* Initializes a new `WebSocket` connection with the Socket.IO server. We attach
* all the appropriate listeners to handle the responses from the server.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
, "url": "https://github.com/LearnBoost/Socket.IO.git"
}
, "dependencies": {
"uglify-js": "1.0.3"
"uglify-js": "1.0.3",
"websocket-client": "~1"
}
, "devDependencies": {
"expresso": "0.7.7"
, "express": "2.3.11"
, "jade": "0.12.1"
, "stylus": "0.13.3"
, "socket.io": "0.7.7"
, "socket.io-client": "0.7.4"
}
, "engines": { "node": ">= 0.4.0" }
}
2 changes: 1 addition & 1 deletion test/node/builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = {
var lines = result.split('\n');
lines.length.should().be.below(5);
lines[0].should().match(/production/gi);
Buffer.byteLength(result).should().be.below(41000);
Buffer.byteLength(result).should().be.below(42000);
});
},

Expand Down