47 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-02-05 17:45:49 +01:00
$(function () {
2022-02-06 19:14:55 +01:00
const getQueryMap = () => {
let queryString = window.location.search,
queryParts = queryString.substring(1).split('&'),
queryMap = new Map();
2022-02-05 17:45:49 +01:00
2022-02-06 19:14:55 +01:00
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);
2022-02-05 17:45:49 +01:00
}
return queryMap;
}
2022-02-06 19:14:55 +01:00
const getOrElse = (option, def) => queryMap.has(option) ? queryMap.get(option): def;
2022-02-05 17:45:49 +01:00
2022-02-06 19:14:55 +01:00
const handleSocketMessage = (e)=>{
2022-02-05 17:45:49 +01:00
try {
let rawMessage = e.data,
2022-02-06 19:14:55 +01:00
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'])
2022-02-05 17:45:49 +01:00
}
2022-02-06 19:18:26 +01:00
2022-02-05 17:45:49 +01:00
} catch (ex) {
2022-02-06 19:14:55 +01:00
console.log(ex)
2022-02-05 17:45:49 +01:00
}
};
2022-02-06 19:19:44 +01:00
const webSocket = window.socket,
queryMap = getQueryMap();
2022-02-06 19:14:55 +01:00
socket.addFamilyHandler("overlay", handleSocketMessage);
2022-02-05 17:45:49 +01:00
});