bigbluebutton-Github/bigbluebutton-html5/imports/api/ping-pong/server/publishers.js
2019-07-01 16:00:27 -03:00

34 lines
884 B
JavaScript

import { Meteor } from 'meteor/meteor';
import Logger from '/imports/startup/server/logger';
import _ from 'lodash';
const COLLECTION_NAME = 'ping-pong';
const POLL_INTERVAL = 5000;
function pingPong(credentials) {
const { meetingId, requesterUserId } = credentials;
const id = _.uniqueId('pong-');
Logger.info(`Starting ping-pong publish for userId: ${requesterUserId}`);
const pongSender = (interval) => {
const payload = {
pong: {
message: 'pong',
time: Date.now(),
meetingId,
},
};
let fn = this.added.bind(this);
if (interval) fn = this.changed.bind(this);
fn(COLLECTION_NAME, id, payload);
};
pongSender();
this.ready();
const interval = Meteor.setInterval(() => pongSender(true), POLL_INTERVAL);
this.onStop(() => {
Meteor.clearInterval(interval);
});
}
Meteor.publish('ping-pong', pingPong);