var socketConnectRequested = 0; var totalDevicesOnline = 0; var yptSocketResponse; var socketResourceId; var socketConnectTimeout; var users_id_online = undefined; var socketConnectRetryTimeout = 15000; var connWS; function processSocketJson(json) { if (json && typeof json.autoUpdateOnHTML !== 'undefined') { socketAutoUpdateOnHTML(json.autoUpdateOnHTML); } if (json.type == webSocketTypes.UNDEFINED) { console.log("processSocketJson UNDEFINED", json); if (typeof json.msg === 'object' && typeof json.msg.callback === 'string') { console.log("Socket onmessage UNDEFINED process subobject", json.msg); return processSocketJson(json.msg) } } if (json.type == webSocketTypes.ON_VIDEO_MSG) { console.log("processSocketJson ON_VIDEO_MSG", json); $('.videoUsersOnline, .videoUsersOnline_' + json.videos_id).text(json.total); } if (json.type == webSocketTypes.ON_LIVE_MSG && typeof json.is_live !== 'undefined') { console.log("processSocketJson ON_LIVE_MSG", json); var selector = '#liveViewStatusID_' + json.live_key.key + '_' + json.live_key.live_servers_id; if (json.is_live) { onlineLabelOnline(selector); } else { onlineLabelOffline(selector); } } if (json.type == webSocketTypes.NEW_CONNECTION) { //console.log("processSocketJson NEW_CONNECTION", json); if (typeof onUserSocketConnect === 'function') { onUserSocketConnect(json); } } else if (json.type == webSocketTypes.NEW_DISCONNECTION) { //console.log("processSocketJson NEW_DISCONNECTION", json); if (typeof onUserSocketDisconnect === 'function') { onUserSocketDisconnect(json); } } else { var myfunc; var _details = json; if (typeof json.msg != 'undefined') { _details = json.msg; } if (typeof _details === 'string') { try { const parsed = JSON.parse(_details); // If parsing succeeds, use the parsed object _details = parsed; console.log('processSocketJson: Parsed JSON:', _details); } catch (e) { // If parsing fails, keep the original string console.log('processSocketJson: Not a JSON string, keeping as is:', _details); } } if (json.callback) { // Check if a function exists with the name in json.callback var code = "if (typeof " + json.callback + " == 'function') { myfunc = " + json.callback + "; } else { myfunc = defaultCallback; }"; console.log('processSocketJson: code=' + code, _details); eval(code); // Trigger the event with the same name as json.callback and pass the JSON object const event = new CustomEvent(json.callback, { detail: _details }); // Pass the JSON as `detail` document.dispatchEvent(event); } else { console.log("processSocketJson: callback not found", json); myfunc = defaultCallback; } // Call the function and pass the JSON object myfunc(_details); } } function socketConnect() { if (useSocketIO) { return socketConnectIO(); } else { return socketConnectOld(); } } function socketConnectOld() { if (socketConnectRequested) { console.log('socketConnect: already requested'); return false; } clearTimeout(socketConnectTimeout); if (!isOnline()) { console.log('socketConnect: Not Online'); socketConnectRequested = 0; socketConnectTimeout = setTimeout(function () { socketConnect(); }, 1000); return false; } socketConnectRequested = 1; var url = addGetParam(webSocketURL, 'page_title', $('