2020-04-10 01:01:46 +08:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Logger from '/imports/startup/server/logger';
|
|
|
|
import ConnectionStatus from '/imports/api/connection-status';
|
2020-09-02 00:31:11 +08:00
|
|
|
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';
|
2020-04-10 01:01:46 +08:00
|
|
|
|
|
|
|
function connectionStatus() {
|
2020-09-02 00:31:11 +08:00
|
|
|
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
|
|
|
|
|
|
|
|
if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
|
|
|
|
Logger.warn(`Publishing ConnectionStatus was requested by unauth connection ${this.connection.id}`);
|
2020-04-10 01:01:46 +08:00
|
|
|
return ConnectionStatus.find({ meetingId: '' });
|
|
|
|
}
|
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
const { meetingId, userId } = tokenValidation;
|
2020-04-10 01:01:46 +08:00
|
|
|
|
|
|
|
check(meetingId, String);
|
2020-09-02 00:31:11 +08:00
|
|
|
check(userId, String);
|
2020-04-10 01:01:46 +08:00
|
|
|
|
2020-09-02 00:31:11 +08:00
|
|
|
Logger.info(`Publishing connection status for ${meetingId} ${userId}`);
|
2020-04-10 01:01:46 +08:00
|
|
|
|
|
|
|
return ConnectionStatus.find({ meetingId });
|
|
|
|
}
|
|
|
|
|
|
|
|
function publish(...args) {
|
|
|
|
const boundNote = connectionStatus.bind(this);
|
|
|
|
return boundNote(...args);
|
|
|
|
}
|
|
|
|
|
|
|
|
Meteor.publish('connection-status', publish);
|