-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c19890c
commit 9481cc6
Showing
1 changed file
with
35 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,43 @@ | ||
/* | ||
* The skeleton of this file is gotten from socket.io source code. | ||
* | ||
* If you are looking for a original code then you are on wrong way. | ||
* All this staff is intended to be for study porpuse. | ||
*/ | ||
var Manager = require('./manager'); | ||
var Socket = require('./socket'); | ||
var Emitter = require('./eventemitter'); | ||
|
||
module.exports = io; | ||
var util = require('./util'); | ||
var url = require('url'); | ||
|
||
function io(url, opts) { | ||
module.exports = lookup; | ||
|
||
var cache = exports.managers = {}; | ||
|
||
function lookup(url, opts) { | ||
if(! util.isString(url)) throw new Error('url is expected to be string'); | ||
|
||
//I do not check if opts is object or not. The programmer is in charge with this moment | ||
opts = opts || {}; | ||
|
||
var urlInfo = url.parse(url); | ||
var id = urlInfo.protocol + '//' + urlInfo.host; //protocol + hostname + port | ||
var io; | ||
|
||
if(opts.forceNew || opts['force new connection'] || opts.multiplex === false){ | ||
io = new Manager(url, opts); | ||
} else { | ||
if( ! cache[id]) { | ||
cache[id] = new Manager(url, opts); | ||
} | ||
|
||
io = cache[id]; | ||
} | ||
|
||
return io.socket(urlInfo.pathname); | ||
} | ||
|
||
io.Manager = Manager; | ||
io.Socket = Socket; | ||
io.Emitter = Emitter; | ||
lookup.Manager = Manager; | ||
lookup.Socket = Socket; | ||
lookup.Emitter = Emitter; |