obtain meetingId outside handler

This commit is contained in:
Anton Georgiev 2017-06-28 16:04:41 -04:00
parent 5ca466c448
commit 3ab794cbdb
13 changed files with 77 additions and 95 deletions

View File

@ -1,13 +1,11 @@
import { check } from 'meteor/check';
import updateCursor from '../modifiers/updateCursor';
export default function handleCursorUpdate({ header, body }) {
const meetingId = header.meetingId;
export default function handleCursorUpdate(meetingId, { header, body }) {
const userId = header.userId;
const x = body.xPercent;
const y = body.yPercent;
check(meetingId, String);
check(userId, String);
check(x, Number);
check(y, Number);

View File

@ -1,13 +1,10 @@
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import clearShapesWhiteboard from '../modifiers/clearShapesWhiteboard';
export default function handleWhiteboardCleared({ header, body }) {
const meetingId = header.meetingId;
export default function handleWhiteboardCleared(meetingId, { body }) {
const whiteboardId = body.whiteboardId;
check(meetingId, String);
check(whiteboardId, String);
return clearShapesWhiteboard(meetingId, whiteboardId);

View File

@ -1,14 +1,11 @@
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import addShape from '../modifiers/addShape';
export default function handleWhiteboardSend({ header, body }) {
const meetingId = header.meetingId;
export default function handleWhiteboardSend(meetingId, { header, body }) {
const userId = header.userId;
const shape = body.annotation;
check(meetingId, String);
check(userId, String);
check(shape, Object);

View File

@ -1,14 +1,11 @@
import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import removeShape from '../modifiers/removeShape';
export default function handleWhiteboardUndo({ header, body }) {
const meetingId = header.meetingId;
export default function handleWhiteboardUndo(meetingId, { body }) {
const whiteboardId = body.whiteboardId;
const shapeId = body.annotationId;
check(meetingId, String);
check(whiteboardId, String);
check(shapeId, String);

View File

@ -2,11 +2,9 @@ import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import Users from '/imports/api/2.0/users';
export default function handleEmojiStatus({ body , header }) {
const { meetingId } = header;
export default function handleEmojiStatus(meetingId, { body }) {
const { userId, status } = body;
check(meetingId, String);
check(userId, String);
check(status, String);

View File

@ -2,12 +2,10 @@ import { check } from 'meteor/check';
import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/2.0/users';
export default function handleListeningOnly({ payload }) {
const meetingId = payload.meeting_id;
export default function handleListeningOnly(meetingId, { payload }) {
const userId = payload.userid;
const listenOnly = payload.listen_only;
check(meetingId, String);
check(userId, String);
check(listenOnly, Boolean);

View File

@ -2,38 +2,6 @@ import Logger from '/imports/startup/server/logger';
import { check } from 'meteor/check';
import Users from '/imports/api/2.0/users';
export default function handlePresenterAssigned({ body, header }) {
const { meetingId } = header;
const { presenterId } = body;
check(meetingId, String);
check(presenterId, String);
const selector = {
meetingId,
userId: presenterId,
};
const modifier = {
$set: {
'user.presenter': true,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Assigning user as presenter: ${err}`);
}
if (numChanged) {
unassignCurrentPresenter(meetingId, presenterId);
return Logger.info(`Assigned user as presenter id=${presenterId} meeting=${meetingId}`);
}
};
return Users.update(selector, modifier, cb);
}
const unassignCurrentPresenter = (meetingId, presenterId) => {
const selector = {
meetingId,
@ -59,3 +27,33 @@ const unassignCurrentPresenter = (meetingId, presenterId) => {
return Users.update(selector, modifier, cb);
};
export default function handlePresenterAssigned(meetingId, { body }) {
const { presenterId } = body;
check(presenterId, String);
const selector = {
meetingId,
userId: presenterId,
};
const modifier = {
$set: {
'user.presenter': true,
},
};
const cb = (err, numChanged) => {
if (err) {
return Logger.error(`Assigning user as presenter: ${err}`);
}
if (numChanged) {
unassignCurrentPresenter(meetingId, presenterId);
return Logger.info(`Assigned user as presenter id=${presenterId} meeting=${meetingId}`);
}
};
return Users.update(selector, modifier, cb);
}

View File

@ -1,11 +1,9 @@
import { check } from 'meteor/check';
import addUser from '../modifiers/addUser';
export default function handleUserJoined({ header, body }) {
const { meetingId } = header;
export default function handleUserJoined(meetingId, { body }) {
const user = body;
check(meetingId, String);
check(user, Object);
return addUser(meetingId, user);

View File

@ -6,11 +6,37 @@ import Users from '/imports/api/2.0/users';
import addChat from '/imports/api/1.1/chat/server/modifiers/addChat';
import clearUserSystemMessages from '/imports/api/1.1/chat/server/modifiers/clearUserSystemMessages';
export default function handleValidateAuthToken({ header, body }) {
const { meetingId } = header;
const { userId, authToken, valid } = body;
const addWelcomeChatMessage = (meetingId, userId) => {
const APP_CONFIG = Meteor.settings.public.app;
const CHAT_CONFIG = Meteor.settings.public.chat;
const Meeting = Meetings.findOne({ 'meetingProp.intId': meetingId });
if (!Meeting) {
// TODO add meeting properly so it does not get reset
return;
}
const welcomeMessage = APP_CONFIG.defaultWelcomeMessage
.concat(APP_CONFIG.defaultWelcomeMessageFooter)
.replace(/%%CONFNAME%%/, Meeting.meetingProp.name);
const message = {
chat_type: CHAT_CONFIG.type_system,
message: welcomeMessage,
from_color: '0x3399FF',
to_userid: userId,
from_userid: CHAT_CONFIG.type_system,
from_username: '',
from_time: (new Date()).getTime(),
};
return addChat(meetingId, message);
};
export default function handleValidateAuthToken(meetingId, { body }) {
const { userId, valid } = body;
check(meetingId, String);
check(userId, String);
check(valid, Boolean);
@ -52,31 +78,3 @@ export default function handleValidateAuthToken({ header, body }) {
return Users.update(selector, modifier, cb);
}
const addWelcomeChatMessage = (meetingId, userId) => {
const APP_CONFIG = Meteor.settings.public.app;
const CHAT_CONFIG = Meteor.settings.public.chat;
const Meeting = Meetings.findOne({ 'meetingProp.intId': meetingId });
if (!Meeting) {
// TODO add meeting properly so it does not get reset
return;
}
const welcomeMessage = APP_CONFIG.defaultWelcomeMessage
.concat(APP_CONFIG.defaultWelcomeMessageFooter)
.replace(/%%CONFNAME%%/, Meeting.meetingProp.name);
const message = {
chat_type: CHAT_CONFIG.type_system,
message: welcomeMessage,
from_color: '0x3399FF',
to_userid: userId,
from_userid: CHAT_CONFIG.type_system,
from_username: '',
from_time: (new Date()).getTime(),
};
return addChat(meetingId, message);
};

View File

@ -2,11 +2,9 @@ import { check } from 'meteor/check';
import updateVoiceUser from '../modifiers/updateVoiceUser';
export default function handleVoiceUpdate({ body, header }) {
const { meetingId } = header;
export default function handleVoiceUpdate(meetingId, { body }) {
const user = body;
check(meetingId, String);
check(user, Object);
return updateVoiceUser(meetingId, user);

View File

@ -4,7 +4,6 @@ import Logger from '/imports/startup/server/logger';
import Users from '/imports/api/2.0/users';
export default function createDummyUser2x(meetingId, userId, authToken) {
console.error(`create dummy user2x ${meetingId} ${userId} ${authToken}`);
check(meetingId, String);
check(userId, String);
check(authToken, String);

View File

@ -65,7 +65,7 @@ class RedisPubSub {
}
handleMessage(pattern, channel, message = '') {
console.log(` 1.1: ${message}`);
Logger.info(` 1.1: ${message}`);
try {
message = JSON.parse(message);
} catch (e) {}

View File

@ -2,6 +2,7 @@ import Redis from 'redis';
import Logger from './logger';
import { Meteor } from 'meteor/meteor';
import { EventEmitter2 } from 'eventemitter2';
import { check } from 'meteor/check';
class RedisPubSub2x {
constructor(config = {}) {
@ -75,7 +76,7 @@ class RedisPubSub2x {
}
handleMessage(pattern, channel, message) {
console.error(`2.0 handleMessage: ${message}`);
Logger.error(`2.0 handleMessage: ${message}`);
const parsedMessage = JSON.parse(message);
const { header } = parsedMessage.core;
const eventName = header.name;
@ -94,11 +95,16 @@ class RedisPubSub2x {
const { header } = data.parsedMessage.core;
const { body } = data.parsedMessage.core;
const eventName = header.name;
const meetingId = header.meetingId;
check(meetingId, String);
check(eventName, String);
check(body, Object);
try {
this._debug(`${eventName} emitted`);
return this.emitter
.emitAsync(eventName, { header, body })
.emitAsync(eventName, meetingId, { header, body })
.then((_) => {
this._debug(`${eventName} completed`);
return next();