2017-10-13 21:50:17 +08:00
|
|
|
/*
|
|
|
|
* Lucas Fialho Zawacki
|
|
|
|
* Paulo Renato Lanzarin
|
|
|
|
* (C) Copyright 2017 Bigbluebutton
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
const ConnectionManager = require('./lib/connection-manager/ConnectionManager');
|
|
|
|
const HttpServer = require('./lib/connection-manager/HttpServer');
|
2017-11-25 02:59:40 +08:00
|
|
|
const server = new HttpServer();
|
|
|
|
const WebsocketConnectionManager = require('./lib/connection-manager/WebsocketConnectionManager');
|
2017-10-13 21:50:17 +08:00
|
|
|
const cp = require('child_process');
|
2018-01-26 12:33:40 +08:00
|
|
|
const Logger = require('./lib/utils/Logger');
|
2017-10-13 21:50:17 +08:00
|
|
|
|
|
|
|
let screenshareProc = cp.fork('./lib/screenshare/ScreenshareProcess', {
|
|
|
|
// Pass over all of the environment.
|
|
|
|
env: process.ENV,
|
|
|
|
// Share stdout/stderr, so we can hear the inevitable errors.
|
|
|
|
silent: false
|
|
|
|
});
|
|
|
|
|
|
|
|
let videoProc = cp.fork('./lib/video/VideoProcess.js', {
|
|
|
|
// Pass over all of the environment.
|
|
|
|
env: process.ENV,
|
|
|
|
// Share stdout/stderr, so we can hear the inevitable errors.
|
|
|
|
silent: false
|
|
|
|
});
|
|
|
|
|
|
|
|
let onMessage = function (message) {
|
2018-01-26 12:33:40 +08:00
|
|
|
Logger.info('event','child message',this.pid,message);
|
2017-10-13 21:50:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
let onError = function(e) {
|
2018-01-26 12:33:40 +08:00
|
|
|
Logger.error('event','child error',this.pid,e);
|
2017-10-13 21:50:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
let onDisconnect = function(e) {
|
2018-01-26 12:33:40 +08:00
|
|
|
Logger.info(e);
|
|
|
|
Logger.info('event','child disconnect',this.pid,'killing...');
|
2017-10-13 21:50:17 +08:00
|
|
|
this.kill();
|
|
|
|
};
|
|
|
|
|
|
|
|
screenshareProc.on('message',onMessage);
|
|
|
|
screenshareProc.on('error',onError);
|
|
|
|
screenshareProc.on('disconnect',onDisconnect);
|
|
|
|
|
|
|
|
videoProc.on('message',onMessage);
|
|
|
|
videoProc.on('error',onError);
|
|
|
|
videoProc.on('disconnect',onDisconnect);
|
|
|
|
|
|
|
|
process.on('SIGTERM', process.exit)
|
|
|
|
process.on('SIGINT', process.exit)
|
2018-01-26 12:33:40 +08:00
|
|
|
|
|
|
|
process.on('uncaughtException', (error) => {
|
|
|
|
Logger.error('[MainProcess] Uncaught exception', error.stack);
|
2017-11-11 05:05:51 +08:00
|
|
|
process.exit('1');
|
2017-10-13 21:50:17 +08:00
|
|
|
});
|
|
|
|
|
2018-01-26 12:33:40 +08:00
|
|
|
// Added this listener to identify unhandled promises, but we should start making
|
|
|
|
// sense of those as we find them
|
|
|
|
process.on('unhandledRejection', (reason, p) => {
|
|
|
|
Logger.error('[MainProcess] Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
|
|
});
|
|
|
|
|
|
|
|
const CM = new ConnectionManager(screenshareProc, videoProc);
|
|
|
|
|
|
|
|
let websocketManager = new WebsocketConnectionManager(server.getServerObject(), '/bbb-webrtc-sfu');
|
2017-10-13 21:50:17 +08:00
|
|
|
|
2017-11-25 02:59:40 +08:00
|
|
|
CM.setHttpServer(server);
|
|
|
|
CM.addAdapter(websocketManager);
|
|
|
|
|
|
|
|
CM.listen(() => {
|
2018-01-26 12:33:40 +08:00
|
|
|
Logger.info("[MainProcess] Server started");
|
2017-11-25 02:59:40 +08:00
|
|
|
});
|