Add logging class that receives room and peer events
parent
9da1afd4af
commit
a31da9359b
|
|
@ -1,5 +1,7 @@
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const userRoles = require('../userRoles');
|
const userRoles = require('../userRoles');
|
||||||
|
// const AwaitQueue = require('awaitqueue');
|
||||||
|
// const axios = require('axios');
|
||||||
|
|
||||||
module.exports =
|
module.exports =
|
||||||
{
|
{
|
||||||
|
|
@ -64,6 +66,41 @@ module.exports =
|
||||||
// listeningRedirectPort disabled
|
// listeningRedirectPort disabled
|
||||||
// use case: loadbalancer backend
|
// use case: loadbalancer backend
|
||||||
httpOnly : false,
|
httpOnly : false,
|
||||||
|
// This logger class will have the log function
|
||||||
|
// called every time there is a room created or destroyed,
|
||||||
|
// or peer created or destroyed. This would then be able
|
||||||
|
// to log to a file or external service.
|
||||||
|
/* StatusLogger : class
|
||||||
|
{
|
||||||
|
constructor()
|
||||||
|
{
|
||||||
|
this._queue = new AwaitQueue();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Array of rooms
|
||||||
|
// [
|
||||||
|
// { roomId : 'example', peers: 5 },
|
||||||
|
// { roomId : 'example2', peers: 4 }
|
||||||
|
// ]
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
async log({ rooms, peers })
|
||||||
|
{
|
||||||
|
this._queue.push(async () =>
|
||||||
|
{
|
||||||
|
// Do your logging in here, use queue to keep correct order
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Number of rooms: ', rooms);
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('Number of peers: ', peers);
|
||||||
|
})
|
||||||
|
.catch((error) =>
|
||||||
|
{
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log('error in log', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, */
|
||||||
// This function will be called on successful login through oidc.
|
// This function will be called on successful login through oidc.
|
||||||
// Use this function to map your oidc userinfo to the Peer object.
|
// Use this function to map your oidc userinfo to the Peer object.
|
||||||
// The roomId is equal to the room name.
|
// The roomId is equal to the room name.
|
||||||
|
|
@ -124,6 +161,7 @@ module.exports =
|
||||||
peer.addRole(userRoles.AUTHENTICATED);
|
peer.addRole(userRoles.AUTHENTICATED);
|
||||||
},
|
},
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
userMapping : async ({ peer, roomId, userinfo }) =>
|
userMapping : async ({ peer, roomId, userinfo }) =>
|
||||||
{
|
{
|
||||||
if (userinfo.picture != null)
|
if (userinfo.picture != null)
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,11 @@ const logger = new Logger();
|
||||||
|
|
||||||
const queue = new AwaitQueue();
|
const queue = new AwaitQueue();
|
||||||
|
|
||||||
|
let statusLogger = null;
|
||||||
|
|
||||||
|
if ('StatusLogger' in config)
|
||||||
|
statusLogger = new config.StatusLogger();
|
||||||
|
|
||||||
// mediasoup Workers.
|
// mediasoup Workers.
|
||||||
// @type {Array<mediasoup.Worker>}
|
// @type {Array<mediasoup.Worker>}
|
||||||
const mediasoupWorkers = [];
|
const mediasoupWorkers = [];
|
||||||
|
|
@ -159,6 +164,17 @@ async function run()
|
||||||
}, 10000);
|
}, 10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function statusLog()
|
||||||
|
{
|
||||||
|
if (statusLogger)
|
||||||
|
{
|
||||||
|
statusLogger.log({
|
||||||
|
rooms : rooms.size,
|
||||||
|
peers : peers.size
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function setupLTI(ltiConfig)
|
function setupLTI(ltiConfig)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -489,7 +505,12 @@ async function runWebSocketServer()
|
||||||
|
|
||||||
peers.set(peerId, peer);
|
peers.set(peerId, peer);
|
||||||
|
|
||||||
peer.on('close', () => peers.delete(peerId));
|
peer.on('close', () =>
|
||||||
|
{
|
||||||
|
peers.delete(peerId);
|
||||||
|
|
||||||
|
statusLog();
|
||||||
|
});
|
||||||
|
|
||||||
if (
|
if (
|
||||||
Boolean(socket.handshake.session.passport) &&
|
Boolean(socket.handshake.session.passport) &&
|
||||||
|
|
@ -516,6 +537,8 @@ async function runWebSocketServer()
|
||||||
}
|
}
|
||||||
|
|
||||||
room.handlePeer({ peer, returning });
|
room.handlePeer({ peer, returning });
|
||||||
|
|
||||||
|
statusLog();
|
||||||
})
|
})
|
||||||
.catch((error) =>
|
.catch((error) =>
|
||||||
{
|
{
|
||||||
|
|
@ -590,7 +613,14 @@ async function getOrCreateRoom({ roomId })
|
||||||
|
|
||||||
rooms.set(roomId, room);
|
rooms.set(roomId, room);
|
||||||
|
|
||||||
room.on('close', () => rooms.delete(roomId));
|
statusLog();
|
||||||
|
|
||||||
|
room.on('close', () =>
|
||||||
|
{
|
||||||
|
rooms.delete(roomId);
|
||||||
|
|
||||||
|
statusLog();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return room;
|
return room;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue