mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-03 21:43:21 +00:00 
			
		
		
		
	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:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							6eaa54a876
						
					
				
				
					commit
					acd2528038
				
			@@ -22,6 +22,7 @@ zrequire('people');
 | 
			
		||||
zrequire('transmit');
 | 
			
		||||
 | 
			
		||||
function test_with_mock_socket(test_params) {
 | 
			
		||||
    transmit.initialize();
 | 
			
		||||
    var socket_send_called;
 | 
			
		||||
    var send_args = {};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -68,5 +68,5 @@ $(function () {
 | 
			
		||||
            return $(this).is(sel) || $(this).closest(sel).length;
 | 
			
		||||
        };
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    transmit.initialize();
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user