transmit: Refactor logic for deferring the socket initialization.

This makes sure that CSRF token is available while initializing
Socket, irrespective of the order of execution of deferred callbacks
after document becomes ready.

This is part of #9416.
This commit is contained in:
Shubham Dhama
2018-06-14 21:46:02 +05:30
committed by Tim Abbott
parent 6eaa54a876
commit acd2528038
3 changed files with 4 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ zrequire('people');
zrequire('transmit');
function test_with_mock_socket(test_params) {
transmit.initialize();
var socket_send_called;
var send_args = {};

View File

@@ -68,5 +68,5 @@ $(function () {
return $(this).is(sel) || $(this).closest(sel).length;
};
}
transmit.initialize();
});

View File

@@ -3,7 +3,7 @@ var transmit = (function () {
var exports = {};
var socket;
$(function () {
exports.initialize = function () {
// We initialize the socket inside a function so that this code
// runs after `csrf_token` is initialized in setup.js.
if (page_params.use_websockets) {
@@ -11,7 +11,7 @@ $(function () {
}
// For debugging. The socket will eventually move out of this file anyway.
exports._socket = socket;
});
};
function send_message_socket(request, success, error) {
request.socket_user_agent = navigator.userAgent;