2022-02-06 21:03:37 +01:00

61 lines
2.1 KiB
JavaScript

$(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));
}
socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastSub', function(response) {
console.log(response);
if(response.request_data) console.log(response.request_data)
})
}
})
});