2022-02-06 19:19:12 +01:00

47 lines
1.6 KiB
JavaScript

$(function () {
const webSocket = window.socket,
queryMap = getQueryMap();
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 {
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)
}
};
socket.addFamilyHandler("overlay", handleSocketMessage);
});