Skip to content

Commit

Permalink
Fix for #491 [atmosphere.js] unsubscribe events should invoke onClose…
Browse files Browse the repository at this point in the history
… function
  • Loading branch information
jfarcand committed Jul 9, 2012
1 parent 3440a82 commit d2daafe
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 41 deletions.
1 change: 1 addition & 0 deletions modules/jquery/src/main/webapp/jquery/jquery.atmosphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ jQuery.atmosphere = function() {
case "re-opening" :
if (typeof(f.onReconnect) != 'undefined') f.onReconnect(_request, response);
break;
case "unsubscribe" :
case "closed" :
if (typeof(f.onClose) != 'undefined') f.onClose(response);
break;
Expand Down
4 changes: 4 additions & 0 deletions samples/chat-guice/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ $(function () {
+ 'socket or the server is down' }));
};

request.onClose = function(response) {
logged = false;
}

var subSocket = socket.subscribe(request);

input.keydown(function(e) {
Expand Down
45 changes: 4 additions & 41 deletions samples/chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,6 @@ $(function () {
var logged = false;
var socket = $.atmosphere;

<!-- The following code is just here for demonstration purpose and not required -->
<!-- Used to demonstrate the request.onTransportFailure callback. Not mandatory -->
var sseSupported = false;

var transports = new Array();
transports[0] = "websocket";
transports[1] = "sse";
transports[2] = "jsonp";
transports[3] = "long-polling";
transports[4] = "streaming";
transports[5] = "ajax";

$.each(transports, function (index, transport) {
var req = new $.atmosphere.AtmosphereRequest();

req.url = document.location.toString() + 'chat';
req.contentType = "application/json";
req.transport = transport;
req.headers = { "negotiating" : "true" };

req.onOpen = function(response) {
detect.append('<p><span style="color:blue">' + transport + ' supported: ' + '</span>' + (response.transport == transport));
}

req.onReconnect = function(request) {
request.close();
}

socket.subscribe(req)
});
<!-- Below is code that can be re-used -->

// We are now ready to cut the request
var request = { url: document.location.toString() + 'chat',
contentType : "application/json",
Expand All @@ -57,15 +25,6 @@ $(function () {
status.text('Choose name:');
};

<!-- For demonstration of how you can customize the fallbackTransport based on the browser -->
request.onTransportFailure = function(errorMsg, request) {
jQuery.atmosphere.info(errorMsg);
if ( window.EventSource ) {
request.fallbackTransport = "sse";
}
header.html($('<h3>', { text: 'Atmosphere Chat. Default transport is WebSocket, fallback is ' + request.fallbackTransport }));
};

request.onReconnect = function (request, response) {
socket.info("Reconnecting")
};
Expand All @@ -92,6 +51,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/jaxrs2-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/meteor-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ $(function () {
+ 'socket or the server is down' }));
};

request.onClose = function(response) {
logged = false;
}

var subSocket = socket.subscribe(request);

input.keydown(function(e) {
Expand Down
4 changes: 4 additions & 0 deletions samples/rest-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/scala-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/sse-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/sse-rest-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down
4 changes: 4 additions & 0 deletions samples/websocket-chat/src/main/webapp/jquery/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ $(function () {
}
};

request.onClose = function(response) {
logged = false;
}

request.onError = function(response) {
content.html($('<p>', { text: 'Sorry, but there\'s some problem with your '
+ 'socket or the server is down' }));
Expand Down

0 comments on commit d2daafe

Please sign in to comment.