2022-02-05 17:45:49 +01:00
|
|
|
$(function () {
|
|
|
|
var webSocket = getWebSocket(),
|
|
|
|
queryMap = getQueryMap(),
|
2022-02-06 19:14:55 +01:00
|
|
|
isDebug = localStorage.getItem('phantombot_overlay_debug') === 'true' || false;
|
2022-02-05 17:45:49 +01:00
|
|
|
queue = [];
|
|
|
|
|
2022-02-06 19:14:55 +01:00
|
|
|
const getWebSocket = () => {
|
|
|
|
let socketUri = ((window.location.protocol === 'https:' ? 'wss://' : 'ws://') + window.location.host + '/ws/overlay'), // URI of the socket.
|
2022-02-05 17:45:49 +01:00
|
|
|
reconnectInterval = 5000; // How often in milliseconds we should try reconnecting.
|
|
|
|
|
|
|
|
return new ReconnectingWebSocket(socketUri, null, {
|
|
|
|
reconnectInterval: reconnectInterval
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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 printDebug = (message, force) => {
|
|
|
|
if (isDebug || force) console.log('%c[PhantomBot Log]', 'color: #6441a5; font-weight: 900;', message);
|
2022-02-05 17:45:49 +01:00
|
|
|
}
|
2022-02-06 19:14:55 +01:00
|
|
|
window.toggleDebug = (toggle) => {
|
|
|
|
localStorage.setItem('phantombot_overlay_debug', toggle.toString());
|
2022-02-05 17:45:49 +01:00
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
|
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:14:55 +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:14:55 +01:00
|
|
|
socket.addFamilyHandler("overlay", handleSocketMessage);
|
|
|
|
|
|
|
|
|
2022-02-05 17:45:49 +01:00
|
|
|
});
|