Have a global try-catch in the server

auto_join_3.3
Håvar Aambø Fosstveit 2020-05-07 12:20:24 +02:00
parent 457d679382
commit 7e91609276
2 changed files with 46 additions and 57 deletions

View File

@ -7,7 +7,7 @@
"license": "MIT", "license": "MIT",
"main": "lib/index.js", "main": "lib/index.js",
"scripts": { "scripts": {
"start": "DEBUG=${DEBUG:='*mediasoup* *INFO* *WARN* *ERROR*'} INTERACTIVE=${INTERACTIVE:='true'} node server.js", "start": "node server.js",
"connect": "node connect.js", "connect": "node connect.js",
"lint": "eslint -c .eslintrc.json --ext .js *.js lib/" "lint": "eslint -c .eslintrc.json --ext .js *.js lib/"
}, },

View File

@ -126,6 +126,8 @@ let oidcClient;
let oidcStrategy; let oidcStrategy;
async function run() async function run()
{
try
{ {
// Open the interactive server. // Open the interactive server.
await interactiveServer(rooms, peers); await interactiveServer(rooms, peers);
@ -154,8 +156,7 @@ async function run()
// Run WebSocketServer. // Run WebSocketServer.
await runWebSocketServer(); await runWebSocketServer();
// eslint-disable-next-line no-unused-vars const errorHandler = (err, req, res, next) =>
function errorHandler(err, req, res, next)
{ {
const trackingId = uuidv4(); const trackingId = uuidv4();
@ -169,27 +170,15 @@ async function run()
logger.error( logger.error(
'Express error handler dump with tracking ID: %s, error dump: %o', 'Express error handler dump with tracking ID: %s, error dump: %o',
trackingId, err); trackingId, err);
} };
// eslint-disable-next-line no-unused-vars
app.use(errorHandler); app.use(errorHandler);
// Log rooms status every 30 seconds.
setInterval(() =>
{
for (const room of rooms.values())
{
room.logStatus();
} }
}, 120000); catch (error)
// check for deserted rooms
setInterval(() =>
{ {
for (const room of rooms.values()) logger.error('run() [error:"%o"]', error);
{
room.checkEmpty();
} }
}, 10000);
} }
function statusLog() function statusLog()