Skip to content

Commit

Permalink
refactor: add debug logging to mpegts stream endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbenincasa committed Oct 24, 2024
1 parent 7e99511 commit 59aa8bb
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions server/src/api/streamApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,30 @@ export const streamApi: RouterPluginAsyncCallback = async (fastify) => {
session.removeConnection(token);
});

session.on('end', () => piped.end());
session.on('cleanup', () => piped.end());
session.on('end', () => {
logger.debug(
{ token, ip: req.ip, channel: req.params.id },
'Session end - closing response stream',
);
piped.end();
});

session.on('cleanup', () => {
logger.debug(
{ token, ip: req.ip, channel: req.params.id },
'Session cleanup - closing response stream',
);
piped.end();
});

// Close the request on error.
session.on('error', () => piped.end());
session.on('error', (error) => {
logger.error(
{ token, ip: req.ip, channel: req.params.id, error },
'Session error - closing response stream',
);
piped.end();
});

return res.header('Content-Type', 'video/mp2t').send(piped);
},
Expand Down

0 comments on commit 59aa8bb

Please sign in to comment.