From 28c4583255a3d98bf3ffdd147f0efca8ea2fc393 Mon Sep 17 00:00:00 2001 From: Guillermo Rauch Date: Fri, 30 Apr 2010 08:34:21 -0300 Subject: [PATCH] Server events removed New build --- build.js | 1 - lib/socket.js | 2 +- lib/transports/server-events.js | 50 --------- socket.io.js | 185 +++++++++++--------------------- 4 files changed, 64 insertions(+), 174 deletions(-) delete mode 100644 lib/transports/server-events.js diff --git a/build.js b/build.js index 45edb9f57..b269667eb 100755 --- a/build.js +++ b/build.js @@ -30,7 +30,6 @@ var fs = require('fs'), 'transports/websocket.js', 'transports/flashsocket.js', 'transports/htmlfile.js', - 'transports/server-events.js', 'transports/xhr-multipart.js', 'transports/xhr-polling.js', 'socket.js', diff --git a/lib/socket.js b/lib/socket.js index de5fe3caa..0acd86d68 100644 --- a/lib/socket.js +++ b/lib/socket.js @@ -15,7 +15,7 @@ io.Socket = ioClass({ document: document, port: document.location.port || 80, resource: 'socket.io', - transports: ['websocket', 'server-events', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'], + transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'], transportOptions: {}, rememberTransport: true }, diff --git a/lib/transports/server-events.js b/lib/transports/server-events.js deleted file mode 100644 index cefc11c39..000000000 --- a/lib/transports/server-events.js +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Socket.IO client - * - * @author Guillermo Rauch - * @license The MIT license. - * @copyright Copyright (c) 2009 RosePad - */ - -// only Opera's implementation - -(function(){ - var empty = new Function, request = io.Transport.XHR.request; - - io.Transport['server-events'] = io.Transport.extend({ - - type: 'server-events', - - connect: function(){ - var self = this; - this.source = document.createElement('event-source'); - this.source.setAttribute('src', this._prepareUrl()); - this.source.addEventListener('socket.io', function(ev){ self_onData(ev.data); }, false); - }, - - send: function(data){ - this._sendXhr = request(); - this._sendXhr.open('POST', this._prepareUrl() + '/send'); - this._sendXhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8'); - this._sendXhr.send('data=' + encodeURIComponent(data)); - }, - - disconnect: function(){ - this.source.removeEventSource(this.source.getAttribute('src')); - this.source.setAttribute('src', ''); - this.source = null; - if (this._sendXhr) this._sendXhr.abort(); - this._onDisconnect(); - }, - - _onData: function(data){ - this._onMessage(data); - } - - }); - - io.Transport['server-events'].check = function(){ - return 'addEventStream' in window; - }; - -})(); \ No newline at end of file diff --git a/socket.io.js b/socket.io.js index 1742a5733..a7059d6ec 100644 --- a/socket.io.js +++ b/socket.io.js @@ -1,4 +1,4 @@ -/** Socket.IO 0.1.7 - Built with build.js */ +/** Socket.IO 0.2.0 - Built with build.js */ /** * Socket.IO client * @@ -8,14 +8,16 @@ */ this.io = { - version: '0.1.7', + version: '0.2.0', setPath: function(path){ this.path = /\/$/.test(path) ? path : path + '/'; // this is temporary until we get a fix for injecting Flash WebSocket javascript files dynamically, // as io.js shouldn't be aware of specific transports. - WebSocket.__swfLocation = path + 'lib/vendor/web-socket-js/WebSocketMain.swf'; + if ('WebSocket' in window){ + WebSocket.__swfLocation = path + 'lib/vendor/web-socket-js/WebSocketMain.swf'; + } } }; @@ -793,80 +795,74 @@ replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) { * @copyright Copyright (c) 2009 RosePad */ -(function(){ - - var json = io.util.JSON; - - // abstract - io.Transport = ioClass({ +// abstract +io.Transport = ioClass({ - include: [io.util.Events, io.util.Options], + include: [io.util.Events, io.util.Options], - init: function(base, options){ - this.base = base; - this.setOptions(options); - }, + init: function(base, options){ + this.base = base; + this.setOptions(options); + }, - send: function(){ - throw new Error('Missing send() implementation'); - }, + send: function(){ + throw new Error('Missing send() implementation'); + }, - connect: function(){ - throw new Error('Missing connect() implementation'); - }, + connect: function(){ + throw new Error('Missing connect() implementation'); + }, - disconnect: function(){ - throw new Error('Missing disconnect() implementation'); - }, + disconnect: function(){ + throw new Error('Missing disconnect() implementation'); + }, - _onData: function(data){ - try { - var msgs = JSON.parse(data); - } catch(e){} - if (msgs && msgs.messages){ - for (var i = 0, l = msgs.messages.length; i < l; i++){ - this._onMessage(msgs.messages[i]); - } + _onData: function(data){ + try { + var msgs = JSON.parse(data); + } catch(e){} + if (msgs && msgs.messages){ + for (var i = 0, l = msgs.messages.length; i < l; i++){ + this._onMessage(msgs.messages[i]); } - }, + } + }, - _onMessage: function(message){ - if (!('sessionid' in this)){ - try { - var obj = JSON.parse(message); - } catch(e){} - if (obj && obj.sessionid){ - this.sessionid = obj.sessionid; - this._onConnect(); - } - } else { - this.base._onMessage(message); - } - }, + _onMessage: function(message){ + if (!('sessionid' in this)){ + try { + var obj = JSON.parse(message); + } catch(e){} + if (obj && obj.sessionid){ + this.sessionid = obj.sessionid; + this._onConnect(); + } + } else { + this.base._onMessage(message); + } + }, - _onConnect: function(){ - this.connected = true; - this.base._onConnect(); - }, + _onConnect: function(){ + this.connected = true; + this.base._onConnect(); + }, - _onDisconnect: function(){ - if (!this.connected) return; - this.connected = false; - this.base._onDisconnect(); - }, + _onDisconnect: function(){ + if (!this.connected) return; + this.connected = false; + this.base._onDisconnect(); + }, - _prepareUrl: function(){ - return (this.base.options.secure ? 'https' : 'http') - + '://' + this.base.host - + ':' + this.base.options.port - + '/' + this.base.options.resource - + '/' + this.type - + (this.sessionid ? ('/' + this.sessionid) : ''); - } + _prepareUrl: function(){ + return (this.base.options.secure ? 'https' : 'http') + + '://' + this.base.host + + ':' + this.base.options.port + + '/' + this.base.options.resource + + '/' + this.type + + (this.sessionid ? ('/' + this.sessionid) : ''); + } - }); - -})(); +}); /** * Socket.IO client * @@ -1071,20 +1067,15 @@ io.Transport.flashsocket.check = function(){ _destroy: function(){ this._doc = null; CollectGarbage(); - }, - - _onData: function(ev){ - console.log(ev.data); } }); io.Transport['htmlfile'].check = function(){ - return false; // temporary to trigger xhr-polling in IE until testing is complete if ('ActiveXObject' in window){ try { var a = new ActiveXObject('htmlfile'); - return true; + return io.Transport.XHR.check(); } catch(e){} } return false; @@ -1099,56 +1090,6 @@ io.Transport.flashsocket.check = function(){ * @copyright Copyright (c) 2009 RosePad */ -// only Opera's implementation - -(function(){ - var empty = new Function, request = io.Transport.XHR.request; - - io.Transport['server-events'] = io.Transport.extend({ - - type: 'server-events', - - connect: function(){ - var self = this; - this.source = document.createElement('event-source'); - this.source.setAttribute('src', this._prepareUrl()); - this.source.addEventListener('socket.io', function(ev){ self_onData(ev.data); }, false); - }, - - send: function(data){ - this._sendXhr = request(); - this._sendXhr.open('POST', this._prepareUrl() + '/send'); - this._sendXhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded; charset=utf-8'); - this._sendXhr.send('data=' + encodeURIComponent(data)); - }, - - disconnect: function(){ - this.source.removeEventSource(this.source.getAttribute('src')); - this.source.setAttribute('src', ''); - this.source = null; - if (this._sendXhr) this._sendXhr.abort(); - this._onDisconnect(); - }, - - _onData: function(data){ - this._onMessage(data); - } - - }); - - io.Transport['server-events'].check = function(){ - return 'addEventStream' in window; - }; - -})(); -/** - * Socket.IO client - * - * @author Guillermo Rauch - * @license The MIT license. - * @copyright Copyright (c) 2009 RosePad - */ - io.Transport['xhr-multipart'] = io.Transport.XHR.extend({ type: 'xhr-multipart', @@ -1220,7 +1161,7 @@ io.Socket = ioClass({ document: document, port: document.location.port || 80, resource: 'socket.io', - transports: ['websocket', 'server-events', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'], + transports: ['websocket', 'flashsocket', 'htmlfile', 'xhr-multipart', 'xhr-polling'], transportOptions: {}, rememberTransport: true },