diff options
author | Devaev Maxim <[email protected]> | 2018-11-07 05:28:10 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2018-11-07 05:28:10 +0300 |
commit | a319320152b5a6e9fcf95867b9030e101497857a (patch) | |
tree | c42cdd4b4bb63a86a174bd4de99799c9cfad626a /web | |
parent | e9dad49ec4e538eddcd61232465854476d555e2d (diff) |
using key cookie to determine client_id
Diffstat (limited to 'web')
-rw-r--r-- | web/js/stream.js | 12 | ||||
-rw-r--r-- | web/js/tools.js | 9 |
2 files changed, 17 insertions, 4 deletions
diff --git a/web/js/stream.js b/web/js/stream.js index f48dabff..041176c3 100644 --- a/web/js/stream.js +++ b/web/js/stream.js @@ -6,6 +6,7 @@ function Stream() { var __prev_state = false; var __resolution = {width: 640, height: 480}; var __size_factor = 1; + var __key = tools.makeId(); var __client_id = ""; var __fps = -1; @@ -60,6 +61,8 @@ function Stream() { $("stream-screenshot-button").disabled = true; __setStreamerControlsDisabled(true); __updateStreamHeader(false); + __key = tools.makeId(); + __client_id = ""; __fps = -1; __prev_state = false; } @@ -90,9 +93,10 @@ function Stream() { } } - var client_id = tools.getCookie("stream_client_id"); - if (client_id) { - __client_id = client_id; + var stream_client = tools.getCookie("stream_client"); + if (!__client_id && stream_client && stream_client.startsWith(__key + "/")) { + tools.info("Stream: found acceptable stream_client cookie:", stream_client); + __client_id = stream_client.slice(stream_client.indexOf("/") + 1); } if (response.stream.clients_stat.hasOwnProperty(__client_id)) { @@ -104,7 +108,7 @@ function Stream() { __updateStreamHeader(true); if (!__prev_state) { - var path = "/streamer/stream?t=" + new Date().getTime(); + var path = "/streamer/stream?key=" + __key; if (tools.browser.is_chrome || tools.browser.is_blink) { // uStreamer fix for Blink https://bugs.chromium.org/p/chromium/issues/detail?id=527446 tools.info("Stream: using advance_headers=1 to fix Blink MJPG bugs"); diff --git a/web/js/tools.js b/web/js/tools.js index 22ef0a28..bb8310be 100644 --- a/web/js/tools.js +++ b/web/js/tools.js @@ -10,6 +10,15 @@ var tools = new function() { return http; }; + this.makeId = function() { + var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + var id = ""; + for (var count = 0; count < 16; ++count) { + id += chars.charAt(Math.floor(Math.random() * chars.length)); + } + return id; + }; + this.getCookie = function(name) { var matches = document.cookie.match(new RegExp( "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, "\\$1") + "=([^;]*)" // eslint-disable-line no-useless-escape |