Broadcast an event right before and after doing the WebSocket handshake

(imported from commit 29b80c3b72a2f98c25b59dca3d1597cc5e5f2605)
This commit is contained in:
Leo Franchi
2013-11-19 18:05:16 -05:00
parent 657a750550
commit 2452a5c0b2
2 changed files with 10 additions and 0 deletions

View File

@@ -144,6 +144,9 @@ Socket.prototype = {
blueslip.info("Socket connected.");
that._is_open = true;
// Notify listeners that we've finished the websocket handshake
$(document).trigger($.Event('websocket_postopen.zulip', {}));
// We can only authenticate after the DOM has loaded because we need
// the CSRF token
$(function () {
@@ -197,6 +200,9 @@ Socket.prototype = {
if (that._is_unloading) {
return;
}
// We've failed to handshake, but notify that the attempt finished
$(document).trigger($.Event('websocket_postopen.zulip', {}));
blueslip.info("SockJS connection lost. Attempting to reconnect soon.");
that._connection_failures++;
that._is_reconnecting = false;

View File

@@ -1211,6 +1211,10 @@ var WebSocketTransport = SockJS.websocket = function(ri, trans_url) {
that.url = url;
var Constructor = _window.WebSocket || _window.MozWebSocket;
// Zulip Addition: Notify that we're about to start the
// WebSocket handshake
$(document).trigger($.Event('websocket_preopen.zulip', {}));
that.ws = new Constructor(that.url);
that.ws.onmessage = function(e) {
that.ri._didMessage(e.data);