-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage-websocket-redirect.js
More file actions
32 lines (25 loc) · 967 Bytes
/
Copy pathpage-websocket-redirect.js
File metadata and controls
32 lines (25 loc) · 967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
$(document).ready(function () {
// i also considered using document.currentScript.getAttribute()
// as described here: https://stackoverflow.com/a/32589923/38146
// but PyCharm doesn't like that the script has non data- params
// maybe non-standard?
var $currentScript = $('#websocket-redirect');
var socketUrl = $currentScript.data('socketUrl');
var isBrowserBot = $currentScript.data('isBrowserBot');
var isDebug = $currentScript.data('isDebug');
/*
One user reported that with a 588 bot session,
web socket for auto-advance adds 4s to each page load.
*/
var socket;
function initWebSocket() {
socket = makeReconnectingWebSocket(socketUrl);
socket.onmessage = function (e) {
var data = JSON.parse(e.data);
if (data.auto_advanced) {
window.location.reload();
}
};
}
initWebSocket();
});