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

65 lines
2.4 KiB
JavaScript
Raw Normal View History

2016-05-13 01:43:59 +08:00
import { clearUsersCollection } from '/imports/api/users/server/modifiers/clearUsersCollection';
import { clearChatCollection} from '/imports/api/chat/server/modifiers/clearChatCollection';
import { clearMeetingsCollection} from '/imports/api/meetings/server/modifiers/clearMeetingsCollection';
import { clearShapesCollection } from '/imports/api/shapes/server/modifiers/clearShapesCollection';
import { clearSlidesCollection } from '/imports/api/slides/server/modifiers/clearSlidesCollection';
import { clearPresentationsCollection } from '/imports/api/presentations/server/modifiers/clearPresentationsCollection';
import { clearPollCollection } from '/imports/api/polls/server/modifiers/clearPollCollection';
import { clearCursorCollection } from '/imports/api/cursor/server/modifiers/clearCursorCollection';
import { logger } from '/imports/startup/server/logger';
2016-05-17 03:12:49 +08:00
import { redisPubSub } from '/imports/startup/server';
2016-05-13 01:43:59 +08:00
export function appendMessageHeader(eventName, messageObj) {
2016-04-20 05:16:32 +08:00
let header;
header = {
timestamp: new Date().getTime(),
name: eventName,
};
messageObj.header = header;
return messageObj;
};
export function clearCollections() {
console.log('in function clearCollections');
clearUsersCollection();
clearChatCollection();
clearMeetingsCollection();
clearShapesCollection();
clearSlidesCollection();
clearPresentationsCollection();
2016-05-11 04:25:24 +08:00
clearPollCollection();
clearCursorCollection();
}
export 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;
};
export function publish(channel, message) {
logger.info(`redis outgoing message ${message.header.name}`, {
channel: channel,
message: message,
});
if (redisPubSub != null) {
return redisPubSub.pubClient.publish(channel, JSON.stringify(message), (err, res) => {
if (err) {
return logger.info('error', {
error: err,
});
}
});
} else {
return logger.info('ERROR!! redisPubSub was undefined');
}
};
2016-05-13 01:43:59 +08:00
// translate '\n' newline character and '\r' carriage
// returns to '<br/>' breakline character for Flash
2016-05-17 03:12:49 +08:00
export const translateHTML5ToFlash = function (message) {
let result = message;
2016-05-13 01:43:59 +08:00
result = result.replace(new RegExp(CARRIAGE_RETURN, 'g'), BREAK_LINE);
result = result.replace(new RegExp(NEW_LINE, 'g'), BREAK_LINE);
return result;
};