Permalink
Browse files

initial

  • Loading branch information...
1 parent df4f763 commit c526331a85600ff0ca709b1c3a20c0c097020554 @ericz committed Jul 13, 2011
Showing with 30 additions and 29 deletions.
  1. +7 −3 lib/io.js
  2. +1 −1 lib/namespace.js
  3. +19 −24 lib/socket.js
  4. +3 −1 lib/transports/websocket.js
View
@@ -37,7 +37,7 @@
* @api public
*/
- io.transports = [];
+ io.transports = ['websocket'];
/**
* Keep track of jsonp callbacks.
@@ -107,9 +107,9 @@
*/
io.transports.forEach(function (t) {
- //io.Transport[t] = require('./transports/node/' + t);
+ io.Transport[t] = require('./transports/' + t)[t];
});
-
+
/**
* Expose Socket
*
@@ -147,6 +147,7 @@
*/
io.connect = function (host, details) {
+
var uri = io.util.parseUri(host)
, uuri
, socket;
@@ -176,8 +177,11 @@
socket = socket || io.sockets[uuri];
+ var namespace = require('./namespace.js');
+
// if path is different from '' or /
return socket.of(uri.path.length > 1 ? uri.path : '');
};
+
})('object' === typeof module ? module.exports : (window.io = {}));
View
@@ -10,7 +10,7 @@
* Expose constructor.
*/
- exports.SocketNamespace = SocketNamespace;
+ io.SocketNamespace = SocketNamespace;
/**
* Socket namespace constructor.
View
@@ -24,7 +24,7 @@
this.options = {
port: 80
, secure: false
- , document: document
+ , document: undefined
, resource: 'socket.io'
, transports: io.transports
, 'connect timeout': 10000
@@ -51,9 +51,6 @@
(!this.isXDomain() || io.util.ua.hasCORS)) {
var self = this;
- io.util.on(window, 'beforeunload', function () {
- self.disconnectSync();
- }, false);
}
if (this.options['auto connect']) {
@@ -144,21 +141,23 @@
script.parentNode.removeChild(script);
});
} else {
- var xhr = io.util.request();
-
- xhr.open('GET', url);
- xhr.onreadystatechange = function () {
- if (xhr.readyState == 4) {
- xhr.onreadystatechange = empty;
-
- if (xhr.status == 200) {
- complete(xhr.responseText);
- } else {
- !self.reconnecting && self.onError(xhr.responseText);
- }
- }
+ var options = {
+ host: options.host,
+ port: options.port,
+ path: ['', this.options.resource
+ , io.protocol
+ , '?t=' + + new Date].join('/')
};
- xhr.send(null);
+ require('http').get(options, function(res) {
+ var body = "";
+ res.on('data', function (chunk) {
+ body += chunk;
+ });
+ res.on('end', function(){
+ complete(body);
+ });
+ });
+
}
};
@@ -170,7 +169,6 @@
Socket.prototype.getTransport = function (override) {
var transports = override || this.transports, match;
-
for (var i = 0, transport; transport = transports[i]; i++) {
if (io.Transport[transport]
&& io.Transport[transport].check(this)
@@ -209,11 +207,9 @@
function connect (transports){
self.transport = self.getTransport(transports);
if (!self.transport) return self.publish('connect_failed');
-
self.connecting = true;
self.publish('connecting', self.transport.name);
self.transport.open();
-
if (self.options['connect timeout']) {
self.connectTimeoutTimer = setTimeout(function () {
if (!self.connected) {
@@ -331,8 +327,7 @@
*/
Socket.prototype.isXDomain = function () {
- var locPort = window.location.port || 80;
- return this.options.host !== document.domain || this.options.port != locPort;
+ return false;
};
/**
@@ -394,7 +389,7 @@
this.reconnect();
}
}
-
+
this.publish('error', err && err.reason ? err.reason : err);
};
@@ -1,4 +1,6 @@
+var WebSocket = require('websocket-client').WebSocket;
+
/**
* socket.io
* Copyright(c) 2011 LearnBoost <dev@learnboost.com>
@@ -140,7 +142,7 @@
*/
WS.check = function () {
- return 'WebSocket' in window && !('__addTask' in WebSocket);
+ return true;
};
/**

0 comments on commit c526331

Please sign in to comment.