mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
Added changes to reflect socket.io-parser's async encoding, and use of has-binarydata to check the event type of an event. Next added browser tests for sending and receiving of binary data via arraybuffers. Then added blob tests and blob recognition. To make blobs fully work (and Files as well), had to add packet buffering to client so that slow-encoding blobs are still sent before other events. I fixed a stupid bug I had added where I used the indexof module (for old browsers) on a string somewhere instead of an array). This was causing old IE to receive all events twice. Old iphone tests were still failing so I updated tests to reflect that some browsers can receive a blob but not construct them. Finally, reduced build size by adding the "browser" field to package.json and making browserify less confused.
83 lines
1.4 KiB
JavaScript
83 lines
1.4 KiB
JavaScript
|
|
/**
|
|
* Module dependencies.
|
|
*/
|
|
|
|
var url = require('./url');
|
|
var parser = require('socket.io-parser');
|
|
var Manager = require('./manager');
|
|
var debug = require('debug')('socket.io-client');
|
|
|
|
/**
|
|
* Module exports.
|
|
*/
|
|
|
|
module.exports = exports = lookup;
|
|
|
|
/**
|
|
* Managers cache.
|
|
*/
|
|
|
|
var cache = exports.managers = {};
|
|
|
|
/**
|
|
* Looks up an existing `Manager` for multiplexing.
|
|
* If the user summons:
|
|
*
|
|
* `io('http://localhost/a');`
|
|
* `io('http://localhost/b');`
|
|
*
|
|
* We reuse the existing instance based on same scheme/port/host,
|
|
* and we initialize sockets for each namespace.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
function lookup(uri, opts){
|
|
opts = opts || {};
|
|
|
|
var parsed = url(uri);
|
|
var href = parsed.href;
|
|
var id = parsed.id;
|
|
var io;
|
|
|
|
if (opts.forceNew || false === opts.multiplex) {
|
|
debug('ignoring socket cache for %s', href);
|
|
io = Manager(href, opts);
|
|
} else {
|
|
if (!cache[id]) {
|
|
debug('new io instance for %s', href);
|
|
cache[id] = Manager(href, opts);
|
|
}
|
|
io = cache[id];
|
|
}
|
|
|
|
return io.socket(parsed.path);
|
|
}
|
|
|
|
/**
|
|
* Protocol version.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
exports.protocol = parser.protocol;
|
|
|
|
/**
|
|
* `connect`.
|
|
*
|
|
* @param {String} uri
|
|
* @api public
|
|
*/
|
|
|
|
exports.connect = lookup;
|
|
|
|
/**
|
|
* Expose constructors for standalone build.
|
|
*
|
|
* @api public
|
|
*/
|
|
|
|
exports.Manager = require('./manager');
|
|
exports.Socket = require('./socket');
|