Corrected cursor messages, added whiteboardId

This commit is contained in:
Oleksandr Zhurbenko 2018-04-09 23:08:23 -07:00
parent 6c1e791adb
commit a39700bc79
5 changed files with 31 additions and 21 deletions

View File

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

View File

@ -2,7 +2,7 @@ import Logger from '/imports/startup/server/logger';
import Cursor from '/imports/api/cursor';
import { check } from 'meteor/check';
export default function updateCursor(meetingId, userId, x = -1, y = -1) {
export default function updateCursor(meetingId, whiteboardId, userId, x = -1, y = -1) {
check(meetingId, String);
check(userId, String);
check(x, Number);
@ -10,13 +10,15 @@ export default function updateCursor(meetingId, userId, x = -1, y = -1) {
const selector = {
meetingId,
whiteboardId,
userId,
};
const modifier = {
$set: {
userId,
meetingId,
whiteboardId,
userId,
x,
y,
},

View File

@ -200,6 +200,7 @@ export default class PresentationArea extends Component {
whiteboardId={slideObj.id}
/>
<CursorWrapperContainer
podId={this.props.podId}
whiteboardId={slideObj.id}
widthRatio={slideObj.widthRatio}
physicalWidthRatio={adjustedSizes.width / width}

View File

@ -40,8 +40,10 @@ const CursorWrapperContainer = ({ presenterCursorId, multiUserCursorIds, ...rest
);
export default withTracker((params) => {
const { whiteboardId } = params;
const { presenterCursorId, multiUserCursorIds } = CursorWrapperService.getCurrentCursorIds(whiteboardId);
const { podId, whiteboardId } = params;
const cursorIds = CursorWrapperService.getCurrentCursorIds(podId, whiteboardId);
const { presenterCursorId, multiUserCursorIds } = cursorIds;
const isMultiUser = CursorWrapperService.getMultiUserStatus(whiteboardId);
return {

View File

@ -1,25 +1,31 @@
import WhiteboardMultiUser from '/imports/api/whiteboard-multi-user/';
import PresentationPods from '/imports/api/presentation-pods';
import Auth from '/imports/ui/services/auth';
import Cursor from '/imports/api/cursor';
import Users from '/imports/api/users';
const getMultiUserStatus = (whiteboardId) => {
const data = WhiteboardMultiUser.findOne({ meetingId: Auth.meetingID, whiteboardId });
return data ? data.multiUser : false;
};
const getPresenterCursorId = userId => Cursor.findOne({ userId }, { fields: { _id: 1 } });
const getPresenterCursorId = (whiteboardId, userId) =>
Cursor.findOne(
{
whiteboardId,
userId,
},
{ fields: { _id: 1 } },
);
const getCurrentCursorIds = (whiteboardId) => {
const getCurrentCursorIds = (podId, whiteboardId) => {
// object to return
const data = {};
// fetching the presenter's id
const user = Users.findOne({ presenter: true }, { fields: { userId: 1 } });
if (user) {
// fetching the pod owner's id
const pod = PresentationPods.findOne({ meetingId: Auth.meetingID, podId });
if (pod) {
// fetching the presenter cursor id
data.presenterCursorId = getPresenterCursorId(user.userId);
data.presenterCursorId = getPresenterCursorId(whiteboardId, pod.currentPresenterId);
}
// checking whether multiUser mode is on or off
@ -27,7 +33,7 @@ const getCurrentCursorIds = (whiteboardId) => {
// it's a multi-user mode - fetching all the cursors except the presenter's
if (isMultiUser) {
let selector = {};
const selector = { whiteboardId };
const filter = {
fields: {
_id: 1,
@ -36,10 +42,8 @@ const getCurrentCursorIds = (whiteboardId) => {
// if there is a presenter cursor - excluding it from the query
if (data.presenterCursorId) {
selector = {
_id: {
$ne: data.presenterCursorId._id,
},
selector._id = {
$ne: data.presenterCursorId._id,
};
}