2022-02-05 17:45:49 +01:00
|
|
|
$(function () {
|
2022-02-06 21:53:03 +01:00
|
|
|
const webSocket = window.socket;
|
|
|
|
var lastFollow = '-',
|
|
|
|
lastSub = '-',
|
|
|
|
lastDonator = '-',
|
|
|
|
timer = '-';
|
2022-02-05 17:45:49 +01:00
|
|
|
|
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 21:53:03 +01:00
|
|
|
const queryMap = getQueryMap();
|
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 21:53:03 +01:00
|
|
|
const refreshUI = () => {
|
|
|
|
if(queryMap.single){ $("all").hide(); $("single").show(); }
|
|
|
|
else{ $("all").show(); $("single").hide(); }
|
|
|
|
|
|
|
|
$('follow').text(lastFollow);
|
|
|
|
$('subscribe').text(lastSub);
|
|
|
|
$('donate').text(lastDonator);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2022-02-06 21:53:03 +01:00
|
|
|
if(!message.hasOwnProperty('eventFamily') || message.eventFamily != 'overlay' ||
|
|
|
|
!message.hasOwnProperty('eventType') || !message.hasOwnProperty('data'))
|
2022-02-06 19:14:55 +01:00
|
|
|
return;
|
|
|
|
|
2022-02-06 21:53:03 +01:00
|
|
|
console.log(message.eventType, message.data)
|
|
|
|
if(message.eventType == 'follow') {
|
|
|
|
lastFollow = message.data || lastFollow;
|
|
|
|
} else if(message.eventType == 'subscribe') {
|
|
|
|
lastSub = message.data || lastSub;
|
|
|
|
} else if(message.eventType == 'donation') {
|
|
|
|
lastDonator = message.data || lastDonator;
|
|
|
|
} else if(message.eventType == 'timer') {
|
|
|
|
console.log("New timer !! ", message.data)
|
2022-02-05 17:45:49 +01:00
|
|
|
}
|
2022-02-06 21:53:03 +01:00
|
|
|
refreshUI();
|
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-06 21:03:37 +01:00
|
|
|
$(document).ready(async ()=>{
|
|
|
|
if(socket){
|
|
|
|
while(socket.getReadyState() === 0){
|
|
|
|
await new Promise(r => setTimeout(r, 500));
|
|
|
|
}
|
2022-02-06 21:54:13 +01:00
|
|
|
socket.getDBValue("get_current_stream_info_lastFollow", 'streamInfo', 'lastFollow', (response)=>{
|
2022-02-06 21:53:03 +01:00
|
|
|
if(response.streamInfo) lastFollow = response.streamInfo || lastFollow;
|
|
|
|
refreshUI();
|
|
|
|
})
|
2022-02-06 21:54:13 +01:00
|
|
|
socket.getDBValue("get_current_stream_info_lastSub", 'streamInfo', 'lastSub', (response)=>{
|
2022-02-06 21:53:03 +01:00
|
|
|
if(response.streamInfo) lastSub = response.streamInfo || lastSub;
|
|
|
|
refreshUI();
|
|
|
|
})
|
2022-02-06 21:54:13 +01:00
|
|
|
socket.getDBValue("get_current_stream_info_lastDonator", 'streamInfo', 'lastDonator', (response)=>{
|
2022-02-06 21:53:03 +01:00
|
|
|
if(response.streamInfo) lastDonator = response.streamInfo || lastDonator;
|
|
|
|
refreshUI();
|
2022-02-06 21:03:37 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-02-05 17:45:49 +01:00
|
|
|
});
|