Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Style fixes + don't init on each check & clear the flashsocket tasks …

…on close
  • Loading branch information...
commit e8e92268c5dad93ceb63ee3e8cf4c77906492bdd 1 parent 9da035d
@3rd-Eden 3rd-Eden authored
View
10 lib/socket.js
@@ -91,7 +91,7 @@
* @api private
*/
- Socket.prototype.publish = function(){
+ Socket.prototype.publish = function () {
this.emit.apply(this, arguments);
var nsp;
@@ -219,7 +219,7 @@
if (self.options.connectTimeout) {
self.connectTimeoutTimer = setTimeout(function () {
if (!self.connected) {
- if (self.options['try multiple transports']){
+ if (self.options['try multiple transports']) {
if (!self.remainingTransports) {
self.remainingTransports = self.transports.slice(0);
}
@@ -343,7 +343,7 @@
* @api private
*/
- Socket.prototype.onConnect = function(){
+ Socket.prototype.onConnect = function () {
this.connected = true;
this.connecting = false;
if (!this.doBuffer) {
@@ -390,8 +390,8 @@
*/
Socket.prototype.onError = function (err) {
- if (err && err.advice){
- if (err.advice === 'reconnect'){
+ if (err && err.advice) {
+ if (err.advice === 'reconnect') {
this.disconnect();
this.reconnect();
}
View
4 lib/transport.js
@@ -40,7 +40,7 @@
* @api private
*/
- Transport.prototype.onData = function(data){
+ Transport.prototype.onData = function (data) {
this.clearCloseTimeout();
this.setCloseTimeout();
@@ -69,7 +69,7 @@
return this.onHeartbeat();
}
- if (packet.type == 'connect' && packet.endpoint == ''){
+ if (packet.type == 'connect' && packet.endpoint == '') {
this.onConnect();
}
View
32 lib/transports/flashsocket.js
@@ -52,9 +52,9 @@
* @api public
*/
- Flashsocket.prototype.open = function(){
+ Flashsocket.prototype.open = function () {
var self = this, args = arguments;
- WebSocket.__addTask(function(){
+ WebSocket.__addTask(function () {
io.Transport.websocket.prototype.open.apply(self, args);
});
return this;
@@ -69,15 +69,28 @@
* @api public
*/
- Flashsocket.prototype.send = function(){
+ Flashsocket.prototype.send = function () {
var self = this, args = arguments;
- WebSocket.__addTask(function(){
+ WebSocket.__addTask(function () {
io.Transport.websocket.prototype.send.apply(self, args);
});
return this;
};
/**
+ * Disconnects the established `Flashsocket` connection.
+ *
+ * @returns {Transport}
+ * @api public
+ */
+
+ Flashsocket.prototype.close = function () {
+ WebSocket.__tasks.length = 0;
+ io.Transport.websocket.prototype.close.call(this);
+ return this;
+ };
+
+ /**
* Check if the Flashsocket transport is supported as it requires that the Adobe
* Flash Player plugin version `10.0.0` or greater is installed. And also check if
* the polyfill is correctly loaded.
@@ -86,7 +99,7 @@
* @api public
*/
- Flashsocket.check = function(socket){
+ Flashsocket.check = function (socket) {
if (
typeof WebSocket == 'undefined'
|| !('__initialize' in WebSocket) || !swfobject
@@ -104,13 +117,14 @@
// Only start downloading the swf file when the checked that this browser
// actually supports it
- if (supported){
- if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined'){
+ if (supported && !Flashsocket.loaded) {
+ if (typeof WEB_SOCKET_SWF_LOCATION === 'undefined') {
// Set the correct file based on the XDomain settings
WEB_SOCKET_SWF_LOCATION = path.join('/');
}
WebSocket.__initialize();
+ Flashsocket.loaded = true;
}
return supported;
@@ -125,7 +139,7 @@
* @api public
*/
- Flashsocket.xdomainCheck = function(){
+ Flashsocket.xdomainCheck = function () {
return true;
};
@@ -133,7 +147,7 @@
* Disable AUTO_INITIALIZATION
*/
- if (typeof window != 'undefined'){
+ if (typeof window != 'undefined') {
WEB_SOCKET_DISABLE_AUTO_INITIALIZATION = true;
}
View
2  lib/transports/jsonp-polling.js
@@ -146,7 +146,7 @@
script.async = true;
script.src = this.prepareUrl() + '/?t=' + (+new Date) + '&i=' + this.index;
- script.onerror = function(){
+ script.onerror = function () {
self.onClose();
};
View
25 lib/transports/websocket.js
@@ -14,9 +14,10 @@
exports.websocket = WS;
/**
- * The WebSocket transport uses the HTML5 WebSocket API to establish an persistent
- * connection with the Socket.IO server. This transport will also be inherited by the
- * FlashSocket fallback as it provides a API compatible polyfill for the WebSockets.
+ * The WebSocket transport uses the HTML5 WebSocket API to establish an
+ * persistent connection with the Socket.IO server. This transport will also
+ * be inherited by the FlashSocket fallback as it provides a API compatible
+ * polyfill for the WebSockets.
*
* @constructor
* @extends {io.Transport}
@@ -49,7 +50,7 @@
* @api public
*/
- WS.prototype.open = function(){
+ WS.prototype.open = function () {
this.websocket = new WebSocket(this.prepareUrl());
var self = this;
@@ -72,8 +73,8 @@
};
/**
- * Send a message to the Socket.IO server. The message will automatically be encoded
- * in the correct message format.
+ * Send a message to the Socket.IO server. The message will automatically be
+ * encoded in the correct message format.
*
* @returns {Transport}
* @api public
@@ -104,7 +105,7 @@
* @api public
*/
- WS.prototype.close = function(){
+ WS.prototype.close = function () {
this.websocket.close();
return this;
};
@@ -117,7 +118,7 @@
* @api private
*/
- WS.prototype.onError = function(e){
+ WS.prototype.onError = function (e) {
this.socket.onError(e);
};
@@ -126,8 +127,8 @@
*
* @api private
*/
- WS.prototype.scheme = function(){
- return (this.socket.options.secure ? 'wss' : 'ws');
+ WS.prototype.scheme = function () {
+ return this.socket.options.secure ? 'wss' : 'ws';
};
/**
@@ -138,7 +139,7 @@
* @api public
*/
- WS.check = function(){
+ WS.check = function () {
return 'WebSocket' in window && !('__addTask' in WebSocket);
};
@@ -149,7 +150,7 @@
* @api public
*/
- WS.xdomainCheck = function(){
+ WS.xdomainCheck = function () {
return true;
};
View
2  lib/transports/xhr.js
@@ -200,7 +200,7 @@
* @api public
*/
- XHR.xdomainCheck = function(){
+ XHR.xdomainCheck = function () {
return XHR.check(null, true);
};
View
8 lib/util.js
@@ -168,14 +168,14 @@
* @api public
*/
- util.merge = function merge(target, additional, deep, lastseen){
+ util.merge = function merge (target, additional, deep, lastseen) {
var seen = lastseen || []
, depth = typeof deep == 'undefined' ? 2 : deep
, prop;
- for (prop in additional){
- if (additional.hasOwnProperty(prop) && util.indexOf(seen, prop) < 0){
- if (typeof target[prop] !== 'object' || !depth){
+ for (prop in additional) {
+ if (additional.hasOwnProperty(prop) && util.indexOf(seen, prop) < 0) {
+ if (typeof target[prop] !== 'object' || !depth) {
target[prop] = additional[prop];
seen.push(additional[prop]);
} else {
Please sign in to comment.
Something went wrong with that request. Please try again.