Skip to content

Commit

Permalink
feat: stop stream 5 seconds after the room is clear
Browse files Browse the repository at this point in the history
otherwise, stream could be stopped when user is refreshing the browser
  • Loading branch information
amoshydra committed Dec 22, 2024
1 parent 7776fa0 commit 8bfd97c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/server/class/wrdxr-obs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,23 @@ export class WrdxrObs {
constructor(server) {
// Setup rooms
const room = new Room();

/**
* @type {NodeJS.Timeout}
*/
let stopStreamRequestTimeout;

room.on("start", async () => {
clearTimeout(stopStreamRequestTimeout);
});

// Automatically stop streaming when all clients have left
room.on("end", async () => {
try {
await obsWebSocket.request("StopStream");
// Stop streaming after 5 seconds
stopStreamRequestTimeout = setTimeout(async () => {
await obsWebSocket.request("StopStream");
}, 5000);
} catch (error) {
console.error(error);
}
Expand Down

0 comments on commit 8bfd97c

Please sign in to comment.