Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
var _global = (function() { return this; })();
2
var nativeWebSocket = _global.WebSocket || _global.MozWebSocket;
3
var websocket_version = require('./version');
4
 
5
 
6
/**
7
 * Expose a W3C WebSocket class with just one or two arguments.
8
 */
9
function W3CWebSocket(uri, protocols) {
10
	var native_instance;
11
 
12
	if (protocols) {
13
		native_instance = new nativeWebSocket(uri, protocols);
14
	}
15
	else {
16
		native_instance = new nativeWebSocket(uri);
17
	}
18
 
19
	/**
20
	 * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
21
	 * class). Since it is an Object it will be returned as it is when creating an
22
	 * instance of W3CWebSocket via 'new W3CWebSocket()'.
23
	 *
24
	 * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
25
	 */
26
	return native_instance;
27
}
28
 
29
 
30
/**
31
 * Module exports.
32
 */
33
module.exports = {
34
    'w3cwebsocket' : nativeWebSocket ? W3CWebSocket : null,
35
    'version'      : websocket_version
36
};