bigbluebutton-Github/bigbluebutton-html5/server/server.js

172 lines
5.2 KiB
JavaScript
Raw Normal View History

import { clearCollections } from '/server/helpers';
2016-04-29 05:10:43 +08:00
import { WhiteboardCleanStatus } from '/collections/collections';
const indexOf = [].indexOf || function (item) {
for (let i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1;
};
2016-01-13 04:15:16 +08:00
2016-05-02 22:48:20 +08:00
export var myQueue = new PowerQueue({
// autoStart:true
// isPaused: true
});
2016-01-15 13:46:41 +08:00
2016-04-29 05:37:15 +08:00
const log = {};
if (process != null && process.env != null && process.env.NODE_ENV == 'production') {
log.path = '/var/log/bigbluebutton/bbbnode.log';
} else {
log.path = `${process.env.PWD}/log/development.log`;
}
// Setting up a logger in Meteor.log
export let logger = new Winston.Logger({
transports: [
new Winston.transports.Console(), new Winston.transports.File({
filename: log.path,
}),
],
});
Meteor.startup(() => {
logger.info('server start');
2016-01-15 13:46:41 +08:00
//remove all data
2016-04-29 05:10:43 +08:00
WhiteboardCleanStatus.remove({});
clearCollections();
2016-01-15 13:46:41 +08:00
const eventEmitter = new (Npm.require('events').EventEmitter);
2016-04-19 05:58:36 +08:00
registerHandlers(eventEmitter);
const handledMessageTypes = [
'get_users_reply',
'meeting_created_message',
'get_all_meetings_reply',
'user_left_voice_message',
'user_joined_voice_message',
'user_voice_talking_message',
'user_voice_muted_message',
'user_listening_only',
'user_left_message',
'validate_auth_token_reply',
'user_joined_message',
'presenter_assigned_message',
'user_emoji_status_message',
'user_locked_message',
'user_unlocked_message',
'meeting_ended_message',
'meeting_destroyed_event',
'end_and_kick_all_message',
'disconnect_all_users_message',
'get_chat_history_reply',
'send_public_chat_message',
'send_private_chat_message',
'presentation_shared_message',
'get_presentation_info_reply',
'presentation_page_changed_message',
'presentation_removed_message',
'get_whiteboard_shapes_reply',
'send_whiteboard_shape_message',
'presentation_cursor_updated_message',
'whiteboard_cleared_message',
'undo_whiteboard_request',
'user_eject_from_meeting',
'disconnect_user_message',
'presentation_page_resized_message',
'recording_status_changed_message',
'new_permission_settings',
'poll_show_result_message',
'poll_started_message',
'poll_stopped_message',
'user_voted_poll_message',
];
2016-04-19 05:58:36 +08:00
2016-01-15 13:46:41 +08:00
// create create a PubSub connection, start listening
Meteor.redisPubSub = new Meteor.RedisPubSub(function () {
2016-04-29 05:37:15 +08:00
return logger.info('created pubsub');
2016-01-13 04:15:16 +08:00
});
2016-05-02 22:48:20 +08:00
myQueue.taskHandler = function (data, next, failures) {
2016-04-19 05:58:36 +08:00
let eventName, parsedMsg, length, lengthString;
2016-01-30 09:33:40 +08:00
parsedMsg = JSON.parse(data.jsonMsg);
2016-04-19 06:47:11 +08:00
if (parsedMsg != null) {
2016-01-30 09:33:40 +08:00
eventName = parsedMsg.header.name;
2016-05-02 22:48:20 +08:00
length = myQueue.length();
lengthString = function () {
if (length > 0) {
return `In the queue we have ${length} event(s) to process.`;
} else return "";
}() || "";
2016-04-29 05:37:15 +08:00
logger.info(`in callback after handleRedisMessage ${eventName}. ${lengthString}`);
2016-01-30 09:33:40 +08:00
}
2016-04-19 05:58:36 +08:00
console.log("in taskHandler:" + eventName);
if (failures > 0) {
next();
2016-04-29 05:37:15 +08:00
return logger.error(`got a failure on taskHandler ${eventName} ${failures}`);
2016-04-19 05:58:36 +08:00
// TODO should we stop or instead return next?
2016-01-13 04:15:16 +08:00
} else {
2016-04-19 23:07:57 +08:00
logRedisMessage(eventName, data.jsonMsg);
2016-04-19 05:58:36 +08:00
// note!! we first check if we handle the event type. The handled event types are listed in an array
// if NOT in the array, call arg.callback()
if (handledMessageTypes.indexOf(eventName) > -1) {
return eventEmitter.emit(eventName, {
payload: parsedMsg.payload,
header: parsedMsg.header,
callback: () => {
console.log("ready for next message");
return next();
},
});
} else {
2016-04-29 05:37:15 +08:00
logger.error("NOT HANDLING:" + eventName);
return next();
}
2016-01-13 04:15:16 +08:00
}
};
2016-04-19 06:47:11 +08:00
const logRedisMessage = function (eventName, json) {
2016-01-15 13:46:41 +08:00
// Avoid cluttering the log with json messages carrying little or repetitive
// information. Comment out a message type in the array to be able to see it
// in the log upon restarting of the Meteor process.
notLoggedEventTypes = [
'keep_alive_reply',
'page_resized_message',
'presentation_page_resized_message',
'presentation_cursor_updated_message',
'get_presentation_info_reply',
2016-01-15 13:46:41 +08:00
//"get_users_reply"
'get_chat_history_reply',
2016-01-15 13:46:41 +08:00
//"get_all_meetings_reply"
'get_whiteboard_shapes_reply',
'presentation_shared_message',
'presentation_conversion_done_message',
'presentation_conversion_progress_message',
'presentation_page_generated_message',
2016-01-15 13:46:41 +08:00
//"presentation_page_changed_message"
'BbbPubSubPongMessage',
'bbb_apps_is_alive_message',
'user_voice_talking_message',
'meeting_state_message',
2016-04-19 05:58:36 +08:00
'get_recording_status_reply',];
2016-04-19 05:58:36 +08:00
// LOG in the meteor console
if (eventName, indexOf.call(notLoggedEventTypes, eventName) < 0) {
// For DEVELOPMENT purposes only
// Dynamic shapes' updates will slow down significantly
if(Meteor.settings.public.mode == 'development') {
2016-04-29 05:37:15 +08:00
logger.info(`redis incoming message ${eventName} `, {
message: json,
});
}
2016-01-13 04:15:16 +08:00
}
};
2016-04-19 06:47:11 +08:00
2016-01-13 04:15:16 +08:00
});