1 var _global = (function () {
2 if (!this && typeof global !== 'undefined') {
7 var NativeWebSocket = _global.WebSocket || _global.MozWebSocket;
8 var websocket_version = require('./version');
12 * Expose a W3C WebSocket class with just one or two arguments.
14 function W3CWebSocket(uri, protocols) {
18 native_instance = new NativeWebSocket(uri, protocols);
21 native_instance = new NativeWebSocket(uri);
25 * 'native_instance' is an instance of nativeWebSocket (the browser's WebSocket
26 * class). Since it is an Object it will be returned as it is when creating an
27 * instance of W3CWebSocket via 'new W3CWebSocket()'.
29 * ECMAScript 5: http://bclary.com/2004/11/07/#a-13.2.2
31 return native_instance;
33 if (NativeWebSocket) {
34 ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'].forEach(function(prop) {
35 Object.defineProperty(W3CWebSocket, prop, {
36 get: function() { return NativeWebSocket[prop]; }
45 'w3cwebsocket' : NativeWebSocket ? W3CWebSocket : null,
46 'version' : websocket_version