This commit is contained in:
choelzl 2022-02-06 21:53:03 +01:00
parent 5565124bd5
commit 6faf3293ad
Signed by: sora
GPG Key ID: A362EA0491E2EEA0
4 changed files with 2388 additions and 27 deletions

View File

@ -9,10 +9,6 @@
})); }));
} }
// $.inidb.get('streamInfo', 'lastSub', subscriber);
// $.inidb.get('streamInfo', 'lastFollow', follower);
// $.inidb.get('streamInfo', 'lastDonator', donationUsername);
$.bind('command', function(event) { $.bind('command', function(event) {
const sender = "" + event.getSender().toLowerCase(), const sender = "" + event.getSender().toLowerCase(),

View File

@ -14,6 +14,13 @@
<!-- Main body --> <!-- Main body -->
<body> <body>
<div class="main"> <div class="main">
<div id="all" class="col-12 row m-auto ">
<div class="col-1"></div>
<div class="col-3 m-2 card"><div class="position-absolute">Last Follow:</div><div id="follow" class="text-center fs-1 fw-bolder">-</div></div>
<div class="col-3 m-2 card"><div class="position-absolute">Last Sub:</div><div id="subscribe" class="text-center fs-1 fw-bolder">-</div></div>
<div class="col-3 m-2 card"><div class="position-absolute">Last Dono:</div><div id="dono" class="text-center fs-1 fw-bolder">-</div></div>
</div>
<div id="single"></div>
</div> </div>
<!-- jQuery --> <!-- jQuery -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

View File

@ -1,4 +1,9 @@
$(function () { $(function () {
const webSocket = window.socket;
var lastFollow = '-',
lastSub = '-',
lastDonator = '-',
timer = '-';
const getQueryMap = () => { const getQueryMap = () => {
let queryString = window.location.search, let queryString = window.location.search,
@ -12,37 +17,43 @@ $(function () {
} }
return queryMap; return queryMap;
} }
const queryMap = getQueryMap();
const getOrElse = (option, def) => queryMap.has(option) ? queryMap.get(option): def; const getOrElse = (option, def) => queryMap.has(option) ? queryMap.get(option): def;
const refreshUI = () => {
if(queryMap.single){ $("all").hide(); $("single").show(); }
else{ $("all").show(); $("single").hide(); }
$('follow').text(lastFollow);
$('subscribe').text(lastSub);
$('donate').text(lastDonator);
}
const handleSocketMessage = (e)=>{ const handleSocketMessage = (e)=>{
try { try {
console.log(e.data)
let rawMessage = e.data, let rawMessage = e.data,
message = JSON.parse(rawMessage); message = JSON.parse(rawMessage);
if(!message.hasOwnProperty('eventFamily') || message['eventFamily'] != 'overlay' || if(!message.hasOwnProperty('eventFamily') || message.eventFamily != 'overlay' ||
!message.hasOwnProperty('eventType') || !message.hasOwnProperty['data']) !message.hasOwnProperty('eventType') || !message.hasOwnProperty('data'))
return; return;
if(message['eventType'] == 'follow') { console.log(message.eventType, message.data)
console.log("New Follow !! ", message['data']) if(message.eventType == 'follow') {
} else if(message['eventType'] == 'subscribe') { lastFollow = message.data || lastFollow;
console.log("New Sub !! ", message['data']) } else if(message.eventType == 'subscribe') {
} else if(message['eventType'] == 'donation') { lastSub = message.data || lastSub;
console.log("New dono !! ", message['data']) } else if(message.eventType == 'donation') {
} else if(message['eventType'] == 'timer') { lastDonator = message.data || lastDonator;
console.log("New timer !! ", message['data']) } else if(message.eventType == 'timer') {
console.log("New timer !! ", message.data)
} }
refreshUI();
} catch (ex) { } catch (ex) {
console.log(ex) console.log(ex)
} }
}; };
const webSocket = window.socket,
queryMap = getQueryMap();
socket.addFamilyHandler("overlay", handleSocketMessage); socket.addFamilyHandler("overlay", handleSocketMessage);
$(document).ready(async ()=>{ $(document).ready(async ()=>{
@ -50,13 +61,17 @@ $(function () {
while(socket.getReadyState() === 0){ while(socket.getReadyState() === 0){
await new Promise(r => setTimeout(r, 500)); await new Promise(r => setTimeout(r, 500));
} }
// $.inidb.get('streamInfo', 'lastSub', subscriber); socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastFollow', (response)=>{
// $.inidb.get('streamInfo', 'lastFollow', follower); if(response.streamInfo) lastFollow = response.streamInfo || lastFollow;
// $.inidb.get('streamInfo', 'lastDonator', donationUsername); refreshUI();
socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastFollow', function(response) { })
console.log(response); socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastSub', (response)=>{
if(response.streamInfo) lastSub = response.streamInfo || lastSub;
if(response.request_data) console.log(response.request_data) refreshUI();
})
socket.getDBValue("get_current_stream_info", 'streamInfo', 'lastDonator', (response)=>{
if(response.streamInfo) lastDonator = response.streamInfo || lastDonator;
refreshUI();
}) })
} }
}) })

File diff suppressed because it is too large Load Diff