Split Meteor roles backend-frontend revisit

This commit is contained in:
Anton Georgiev 2021-02-05 17:47:46 +00:00
parent 0d63383c2a
commit 8c0f0fdd52
10 changed files with 109 additions and 29 deletions

View File

@ -70,13 +70,13 @@ class FromAkkaAppsMsgSenderActor(msgSender: MessageSender)
// Whiteboard
case SendWhiteboardAnnotationEvtMsg.NAME =>
msgSender.send(fromAkkaAppsWbRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case SendCursorPositionEvtMsg.NAME =>
msgSender.send(fromAkkaAppsWbRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case ClearWhiteboardEvtMsg.NAME =>
msgSender.send(fromAkkaAppsWbRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case UndoWhiteboardEvtMsg.NAME =>
msgSender.send(fromAkkaAppsWbRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
// Chat
case SendPublicMessageEvtMsg.NAME =>
@ -118,6 +118,22 @@ class FromAkkaAppsMsgSenderActor(msgSender: MessageSender)
case UserRespondedToPollRecordMsg.NAME =>
//==================================================================
case ValidateAuthTokenRespMsg.NAME =>
msgSender.send("from-akka-apps-frontend-redis-channel", json)
// Message duplicated for frontend and backend processes
case MeetingCreatedEvtMsg.NAME =>
msgSender.send(fromAkkaAppsRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case MeetingEndingEvtMsg.NAME =>
msgSender.send(fromAkkaAppsRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case MeetingDestroyedEvtMsg.NAME =>
msgSender.send(fromAkkaAppsRedisChannel, json)
msgSender.send("from-akka-apps-frontend-redis-channel", json)
case _ =>
msgSender.send(fromAkkaAppsRedisChannel, json)
}

View File

@ -10,9 +10,11 @@ export default function handleMeetingDestruction({ body }) {
const { meetingId } = body;
check(meetingId, String);
destroyExternalVideo(meetingId);
removeAnnotationsStreamer(meetingId);
removeCursorStreamer(meetingId);
if (!process.env.METEOR_ROLE || process.env.METEOR_ROLE === 'frontend') {
destroyExternalVideo(meetingId);
removeAnnotationsStreamer(meetingId);
removeCursorStreamer(meetingId);
}
return RedisPubSub.destroyMeetingQueue(meetingId);
}

View File

@ -167,8 +167,11 @@ export default function addMeeting(meeting) {
try {
const { insertedId, numberAffected } = Meetings.upsert(selector, modifier);
addAnnotationsStreamer(meetingId);
addCursorStreamer(meetingId);
if (!process.env.METEOR_ROLE || process.env.METEOR_ROLE === 'frontend') {
addAnnotationsStreamer(meetingId);
addCursorStreamer(meetingId);
// TODO add addExternalVideoStreamer(meetingId);
}
if (insertedId) {
Logger.info(`Added meeting id=${meetingId}`);

View File

@ -27,8 +27,11 @@ import clearAuthTokenValidation from '/imports/api/auth-token-validation/server/
import Metrics from '/imports/startup/server/metrics';
export default function meetingHasEnded(meetingId) {
removeAnnotationsStreamer(meetingId);
removeCursorStreamer(meetingId);
if (!process.env.METEOR_ROLE || process.env.METEOR_ROLE === 'frontend') {
removeAnnotationsStreamer(meetingId);
removeCursorStreamer(meetingId);
// TODO add removeExternalVideoStreamer(meetingId);
}
return Meetings.remove({ meetingId }, () => {
clearCaptions(meetingId);

View File

@ -32,6 +32,9 @@ export default function handleValidateAuthToken({ body }, meetingId) {
const pendingAuths = pendingAuthenticationsStore.take(meetingId, userId, authToken);
Logger.info(`PendingAuths length [${pendingAuths.length}]`);
if (pendingAuths.length === 0) return;
if (!valid) {
pendingAuths.forEach(
(pendingAuth) => {

View File

@ -1,34 +1,74 @@
import {check} from 'meteor/check';
import Logger from '/imports/startup/server/logger';
class BannedUsers {
constructor() {
Logger.debug('BannedUsers :: Initializing');
this.store = {};
this.store = new Mongo.Collection('users-banned');
if (Meteor.isServer) {
// types of queries for the users:
// 1. meetingId
// 2. meetingId, userId
this.store._ensureIndex({meetingId: 1, userId: 1});
}
}
init(meetingId) {
Logger.debug('BannedUsers :: init', { meetingId });
Logger.debug('BannedUsers :: init', {meetingId});
if (!this.store[meetingId]) this.store[meetingId] = new Set();
// if (!this.store[meetingId]) this.store[meetingId] = new Set();
}
add(meetingId, externalId) {
Logger.debug('BannedUsers :: add', { meetingId, externalId });
if (!this.store[meetingId]) this.store[meetingId] = new Set();
check(meetingId, String);
check(externalId, String);
this.store[meetingId].add(externalId);
Logger.debug('BannedUsers :: add', {meetingId, externalId});
const selector = {
meetingId,
externalId,
};
const modifier = Object.assign( // TODO
{meetingId},
{externalId},
);
try {
const insertedId = this.store.upsert(selector, modifier);
if (insertedId) {
Logger.info('BannedUsers :: Added to BannedUsers collection', {meetingId, externalId});
}
} catch (err) {
Logger.error('BannedUsers :: Error on adding to BannedUsers collection', {meetingId, externalId, err});
}
}
delete(meetingId) {
Logger.debug('BannedUsers :: delete', { meetingId });
delete this.store[meetingId];
check(meetingId, String);
const selector = {
meetingId,
};
try {
this.store.remove(selector);
Logger.info('BannedUsers :: Removed meeting', {meetingId});
} catch (err) {
Logger.error('BannedUsers :: Removing from collection', {err});
}
}
has(meetingId, externalId) {
Logger.debug('BannedUsers :: has', { meetingId, externalId });
if (!this.store[meetingId]) this.store[meetingId] = new Set();
check(meetingId, String);
check(externalId, String);
return this.store[meetingId].has(externalId);
Logger.info('BannedUsers :: has', {meetingId, externalId});
return this.store.findOne({meetingId, externalId});
}
}

View File

@ -132,7 +132,7 @@ Meteor.startup(() => {
setMinBrowserVersions();
Logger.warn(`SERVER STARTED.\nENV=${env},\nnodejs version=${process.version}\nCDN=${CDN_URL}\n`, APP_CONFIG);
Logger.warn(`SERVER STARTED.\nENV=${env},\nnodejs version=${process.version}\nMETEOR_ROLE=${process.env.METEOR_ROLE}\nCDN=${CDN_URL}\n`, APP_CONFIG);
}
});

View File

@ -155,12 +155,23 @@ class RedisPubSub {
channelsToSubscribe.push(this.customRedisChannel);
channelsToSubscribe.forEach((channel) => {
this.sub.psubscribe(channel);
});
if (this.redisDebugEnabled) {
Logger.debug(`Redis: Subscribed to '${channelsToSubscribe}'`);
switch (process.env.METEOR_ROLE) {
case 'frontend':
this.sub.psubscribe('from-akka-apps-frontend-redis-channel');
if (this.redisDebugEnabled) {
Logger.debug(`Redis: NodeJSPool:${this.instanceId} Role: frontend. Subscribed to 'from-akka-apps-frontend-redis-channel'`);
}
break;
default:
channelsToSubscribe.forEach((channel) => {
this.sub.psubscribe(channel);
if (this.redisDebugEnabled) {
Logger.debug(`Redis: NodeJSPool:${this.instanceId} Role: backend. Subscribed to '${channelsToSubscribe}'`);
}
});
break;
}
}

View File

@ -11,6 +11,8 @@
"start:prod": "meteor reset && ROOT_URL=http://127.0.0.1/html5client/1 meteor run --production --port=4000",
"start:dev": "ROOT_URL=http://127.0.0.1/html5client/1 meteor run --port=4000",
"start:dev-fast-mongo": "env ROOT_URL=http://127.0.0.1/html5client/1 MONGO_OPLOG_URL=mongodb://127.0.1.1/local MONGO_URL=mongodb://127.0.1.1/meteor ROOT_URL=http://127.0.0.1/html5client/1 NODE_ENV=development meteor run --port=4000",
"start:backend": "env METEOR_ROLE=backend MONGO_OPLOG_URL=mongodb://127.0.1.1/local MONGO_URL=mongodb://127.0.1.1/meteor ROOT_URL=http://127.0.0.1/html5client/1 PORT=3100 NODE_ENV=development meteor run --port 3100",
"start:frontend": "env METEOR_ROLE=frontend MONGO_OPLOG_URL=mongodb://127.0.1.1/local MONGO_URL=mongodb://127.0.1.1/meteor ROOT_URL=http://127.0.0.1/html5client/1 NODE_ENV=development meteor",
"test": "wdio ./tests/webdriverio/wdio.conf.js",
"lint": "eslint . --ext .jsx,.js"
},

View File

@ -549,7 +549,7 @@ private:
toThirdParty: to-third-party-redis-channel
subscribeTo:
- to-html5-redis-channel
- from-akka-apps-*
- from-akka-apps-[^f]*
- from-third-party-redis-channel
- from-etherpad-redis-channel
async: