2016-05-11 02:53:05 +08:00
|
|
|
import { clearUsersCollection, setUserLockedStatus, markUserOffline, updateVoiceUser } from '/imports/api/users/server/users';
|
|
|
|
import { clearChatCollection, addChatToCollection } from '/imports/api/chat/server/chat';
|
|
|
|
import { clearMeetingsCollection, removeMeetingFromCollection } from '/imports/api/meetings/server/meetings';
|
|
|
|
import { clearShapesCollection } from '/imports/api/shapes/server/shapes';
|
|
|
|
import { clearSlidesCollection } from '/imports/api/slides/server/slides';
|
|
|
|
import { clearPresentationsCollection } from '/imports/api/presentations/server/presentations';
|
2016-05-05 04:25:34 +08:00
|
|
|
import { clearPollCollection } from '/imports/startup/server/collectionManagers/poll';
|
2016-05-11 02:53:05 +08:00
|
|
|
import { clearCursorCollection } from '/imports/api/cursor/server/cursor';
|
2016-05-05 04:25:34 +08:00
|
|
|
|
|
|
|
import { logger } from '/imports/startup/server/logger';
|
|
|
|
import { redisPubSub } from '/imports/startup/server/index';
|
|
|
|
|
2016-04-28 05:04:15 +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;
|
|
|
|
};
|
2016-04-28 05:04:15 +08:00
|
|
|
|
|
|
|
export function clearCollections() {
|
|
|
|
console.log('in function clearCollections');
|
|
|
|
clearUsersCollection();
|
|
|
|
clearChatCollection();
|
|
|
|
clearMeetingsCollection();
|
|
|
|
clearShapesCollection();
|
|
|
|
clearSlidesCollection();
|
|
|
|
clearPresentationsCollection();
|
2016-05-10 23:23:22 +08:00
|
|
|
// clearPollCollection();
|
2016-04-28 05:04:15 +08:00
|
|
|
clearCursorCollection();
|
|
|
|
}
|
2016-05-05 01:00:57 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
2016-05-05 04:25:34 +08:00
|
|
|
|
|
|
|
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-05 05:49:01 +08:00
|
|
|
export const handleVoiceEvent = function (arg) {
|
2016-05-05 04:25:34 +08:00
|
|
|
let _voiceUser, meetingId;
|
|
|
|
meetingId = arg.payload.meeting_id;
|
|
|
|
_voiceUser = payload.user.voiceUser;
|
|
|
|
voiceUserObj = {
|
|
|
|
web_userid: _voiceUser.web_userid,
|
|
|
|
listen_only: arg.payload.listen_only,
|
|
|
|
talking: _voiceUser.talking,
|
|
|
|
joined: _voiceUser.joined,
|
|
|
|
locked: _voiceUser.locked,
|
|
|
|
muted: _voiceUser.muted,
|
|
|
|
};
|
|
|
|
return updateVoiceUser(meetingId, voiceUserObj, arg.callback);
|
|
|
|
};
|
|
|
|
|
2016-05-05 05:49:01 +08:00
|
|
|
export const handleLockEvent = function (arg) {
|
2016-05-05 04:25:34 +08:00
|
|
|
let userId, isLocked;
|
|
|
|
userId = arg.payload.userid;
|
|
|
|
isLocked = arg.payload.locked;
|
|
|
|
setUserLockedStatus(meetingId, userId, isLocked);
|
|
|
|
return arg.callback();
|
|
|
|
};
|
|
|
|
|
2016-05-05 05:49:01 +08:00
|
|
|
export const handleEndOfMeeting = function (arg) {
|
2016-05-05 04:25:34 +08:00
|
|
|
let meetingId;
|
|
|
|
meetingId = arg.payload.meeting_id;
|
|
|
|
logger.info(`DESTROYING MEETING ${meetingId}`);
|
|
|
|
return removeMeetingFromCollection(meetingId, arg.callback);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const handleChatEvent = function (arg) {
|
|
|
|
let messageObject, meetingId;
|
|
|
|
messageObject = arg.payload.message;
|
|
|
|
meetingId = arg.payload.meeting_id;
|
|
|
|
|
|
|
|
// use current_time instead of message.from_time so that the chats from Flash and HTML5 have uniform times
|
|
|
|
messageObject.from_time = arg.header.current_time;
|
|
|
|
addChatToCollection(meetingId, messageObject);
|
|
|
|
return arg.callback();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const handleRemoveUserEvent = function (arg) {
|
|
|
|
if (arg.payload.user != null && arg.payload.user.userid != null && arg.payload.meeting_id != null) {
|
|
|
|
let userId, meetingId;
|
|
|
|
meetingId = arg.payload.meeting_id;
|
|
|
|
userId = arg.payload.user.userid;
|
|
|
|
return markUserOffline(meetingId, userId, arg.callback);
|
|
|
|
} else {
|
|
|
|
logger.info('could not perform handleRemoveUserEvent');
|
|
|
|
return arg.callback();
|
|
|
|
}
|
|
|
|
};
|