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",
"main": "lib/index.js",
"scripts": {
"start": "DEBUG=${DEBUG:='*mediasoup* *INFO* *WARN* *ERROR*'} INTERACTIVE=${INTERACTIVE:='true'} node server.js",
"start": "node server.js",
"connect": "node connect.js",
"lint": "eslint -c .eslintrc.json --ext .js *.js lib/"
},

View File

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