Fix bugs with updating viewer count

pull/28/head
knotteye 2021-01-15 21:28:38 -06:00
parent bcba160146
commit dd940ff46f
2 changed files with 3 additions and 7 deletions

View File

@ -630,6 +630,7 @@ async function initChat() {
let rooms = Object.keys(socket.rooms); let rooms = Object.keys(socket.rooms);
for(let i=1;i<rooms.length;i++){ for(let i=1;i<rooms.length;i++){
io.to(rooms[i]).emit('ALERT', socket.nick+' disconnected'); io.to(rooms[i]).emit('ALERT', socket.nick+' disconnected');
db.query('update user_meta set viewers = viewers - 1 where username='+db.raw.escape(rooms[i]));
} }
if(Array.isArray(store.get(socket.nick))) { if(Array.isArray(store.get(socket.nick))) {
store.set(socket.nick, store.get(socket.nick).filter(item => item !== socket.id)) store.set(socket.nick, store.get(socket.nick).filter(item => item !== socket.id))

View File

@ -129,13 +129,8 @@ function init () {
let session = nms.getSession(id); let session = nms.getSession(id);
let app: string = StreamPath.split("/")[1]; let app: string = StreamPath.split("/")[1];
let key: string = StreamPath.split("/")[2]; let key: string = StreamPath.split("/")[2];
if(!session.isLocal && app === config['media']['publicEndpoint']) { // decrement viewer count
if(keystore[key]){ db.query('update user_meta,users set user_meta.viewers = user_meta.viewers - 1 where users.stream_key='+db.raw.escape(key));
// increment viewer count
db.query('update user_meta set viewers = viewers - 1 where username='+db.raw.escape(key));
return true;
}
}
}); });
} }