Increment and reset viewer count when appropriate

pull/28/head
knotteye 2021-01-15 10:56:32 -06:00
parent d79eac6b57
commit 1b551a5b8f
2 changed files with 6 additions and 1 deletions

View File

@ -28,6 +28,7 @@ async function init() {
//it causes problems //it causes problems
//Live flags in the database stay live //Live flags in the database stay live
await db.query('update user_meta set live=false'); await db.query('update user_meta set live=false');
await db.query('update user_meta set viewers=0');
} }
async function bringUpToDate(): Promise<void>{ async function bringUpToDate(): Promise<void>{

View File

@ -93,6 +93,8 @@ function init () {
db.query('update user_meta,users set user_meta.live=false where users.stream_key='+db.raw.escape(key)); 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) => { 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); 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));
}); });
} }
@ -119,6 +121,8 @@ function init () {
if(app === config['media']['publicEndpoint']) { if(app === config['media']['publicEndpoint']) {
if(keystore[key]){ if(keystore[key]){
session.playStreamPath = '/'+config['media']['privateEndpoint']+'/'+keystore[key]; session.playStreamPath = '/'+config['media']['privateEndpoint']+'/'+keystore[key];
// increment viewer count
db.query('update user_meta set viewers = viewers + 1 where username='+db.raw.escape(key));
return true; return true;
} }
} }