bigbluebutton-Github/bigbluebutton-html5/imports/startup/server/EventQueue.js

153 lines
4.8 KiB
JavaScript
Raw Normal View History

2016-05-05 02:29:43 +08:00
import { logger } from '/imports/startup/server/logger';
2016-05-17 03:12:49 +08:00
import { eventEmitter } from '/imports/startup/server';
2016-06-02 01:18:13 +08:00
import { indexOf } from '/imports/api/common/server/helpers';
export class EventQueue {
constructor() {
2016-05-05 05:49:01 +08:00
console.log('in EventQueue constructor');
let queue = new PowerQueue({
// autoStart:true
// isPaused: true
});
2016-05-05 05:49:01 +08:00
queue.taskHandler = function (data, next, failures) {
2016-05-17 03:12:49 +08:00
const parsedMsg = JSON.parse(data.jsonMsg);
let eventName = null;
if (parsedMsg != null) {
eventName = parsedMsg.header.name;
2016-05-17 03:12:49 +08:00
const length = queue.length();
const lengthString = (function () {
if (length > 0) {
return `In the queue we have ${length} event(s) to process.`;
2016-05-05 05:49:01 +08:00
} else return '';
}()) || '';
//uncomment for development purposes only
//otherwise significantly slows down the whiteboard (displaying drawing process)
//logger.info(`in callback after handleRedisMessage ${eventName}. ${lengthString}`);
}
2016-05-05 05:49:01 +08:00
//uncomment for development purposes only
//otherwise significantly slows down the whiteboard (displaying drawing process)
//console.log('in taskHandler:' + eventName);
if (failures > 0) {
next();
return logger.error(`got a failure on taskHandler ${eventName} ${failures}`);
} else {
logRedisMessage(eventName, data.jsonMsg);
2016-05-05 05:49:01 +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,
2016-05-17 03:12:49 +08:00
header: parsedMsg.header, //TODO extract meetingId here
2016-06-28 02:24:37 +08:00
callback: () =>// {
//uncomment for development purposes only
//otherwise significantly slows down the whiteboard (displaying drawing process)
//console.log('ready for next message');
2016-06-28 02:24:37 +08:00
next(),
//},
});
} else {
2016-06-02 01:18:13 +08:00
logger.info('not handling messages of type:' + eventName);
return next();
}
}
};
2016-05-05 05:49:01 +08:00
return queue;
}
}
const logRedisMessage = function (eventName, json) {
// 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.
2016-06-14 05:35:01 +08:00
let notLoggedEventTypes = [
'keep_alive_reply',
'page_resized_message',
'presentation_page_resized_message',
'presentation_cursor_updated_message',
'get_presentation_info_reply',
2016-05-05 05:49:01 +08:00
//'get_users_reply'
'get_chat_history_reply',
2016-05-05 05:49:01 +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-05-05 05:49:01 +08:00
//'presentation_page_changed_message'
'BbbPubSubPongMessage',
'bbb_apps_is_alive_message',
'user_voice_talking_message',
'meeting_state_message',
2016-05-05 05:49:01 +08:00
'get_recording_status_reply',
];
// LOG in the meteor console
if (eventName, indexOf.call(notLoggedEventTypes, eventName) < 0) {
// For DEVELOPMENT purposes only
// Dynamic shapes' updates will slow down significantly
2016-05-05 05:49:01 +08:00
if (Meteor.settings.public.mode == 'development') {
logger.info(`redis incoming message ${eventName} `, {
message: json,
});
}
}
};
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',
2016-05-26 02:21:42 +08:00
'get_presentation_info_reply',
'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-06-14 05:35:01 +08:00
'get_all_meetings_reply_message',
];