$(function () { const getQueryMap = () => { let queryString = window.location.search, queryParts = queryString.substring(1).split('&'), queryMap = new Map(); for (let part in queryParts) { let key = part.substring(0, part.indexOf('=')), value = part.substring(part.indexOf('=') + 1, part.length); if (key.length > 0 && value.length > 0) queryMap.set(key, value); } return queryMap; } const getOrElse = (option, def) => queryMap.has(option) ? queryMap.get(option): def; const handleSocketMessage = (e)=>{ try { console.log(e.data) let rawMessage = e.data, message = JSON.parse(rawMessage); if(!message.hasOwnProperty('eventFamily') || message['eventFamily'] != 'overlay' || !message.hasOwnProperty('eventType') || !message.hasOwnProperty['data']) return; if(message['eventType'] == 'follow') { console.log("New Follow !! ", message['data']) } else if(message['eventType'] == 'subscribe') { console.log("New Sub !! ", message['data']) } else if(message['eventType'] == 'donation') { console.log("New dono !! ", message['data']) } else if(message['eventType'] == 'timer') { console.log("New timer !! ", message['data']) } } catch (ex) { console.log(ex) } }; const webSocket = window.socket, queryMap = getQueryMap(); socket.addFamilyHandler("overlay", handleSocketMessage); $(document).ready(async ()=>{ if(socket){ while(socket.getReadyState() === 0){ await new Promise(r => setTimeout(r, 500)); } // $.inidb.get('streamInfo', 'lastSub', subscriber); // $.inidb.get('streamInfo', 'lastFollow', follower); // $.inidb.get('streamInfo', 'lastDonator', donationUsername); socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastFollow', function(response) { console.log(response); if(response.request_data) console.log(response.request_data) }) } }) });