Decrement viewer count when appropriate

pull/28/head
knotteye 2021-01-15 20:27:02 -06:00
parent f966bda4dd
commit 21a85fa26c
2 changed files with 14 additions and 2 deletions

View File

@ -602,6 +602,7 @@ async function initChat() {
}
socket.join(data);
io.to(data).emit('JOINED', {nick: socket.nick, room: data});
db.query('update user_meta set viewers = viewers + 1 where username='+db.raw.escape(data));
}
else socket.emit('ALERT', 'Room does not exist');
});
@ -622,6 +623,7 @@ async function initChat() {
});
socket.on('LEAVEROOM', (data) => {
io.to(data).emit('LEFT', {nick: socket.nick, room: data});
db.query('update user_meta set viewers = viewers - 1 where username='+db.raw.escape(data));
socket.leave(data);
});
socket.on('disconnecting', (reason) => {

View File

@ -93,8 +93,6 @@ function init () {
db.query('update user_meta,users set user_meta.live=false where users.stream_key='+db.raw.escape(key));
db.query('select username from users where stream_key='+db.raw.escape(key)+' limit 1').then(async (results) => {
if(results[0]) keystore.rm(results[0].username);
// reset viewer count when finished with stream
db.query('update user_meta set viewers = 0 where username='+db.raw.escape(results[0].username));
});
}
@ -127,6 +125,18 @@ function init () {
}
}
});
nms.on('donePlay', (id, StreamPath, args) => {
let session = nms.getSession(id);
let app: string = StreamPath.split("/")[1];
let key: string = StreamPath.split("/")[2];
if(!session.isLocal && app === config['media']['publicEndpoint']) {
if(keystore[key]){
// increment viewer count
db.query('update user_meta set viewers = viewers - 1 where username='+db.raw.escape(key));
return true;
}
}
});
}
async function transCommand(user: string, key: string): Promise<string[]>{