Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Migrate captions for the Meteor 3.0 api #16978

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion bigbluebutton-html5/imports/api/captions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const collectionOptions = Meteor.isClient ? {
const Captions = new Mongo.Collection('captions', collectionOptions);

if (Meteor.isServer) {
Captions._ensureIndex({ meetingId: 1, locale: 1 });
Captions.createIndexAsync({ meetingId: 1, locale: 1 });
}

export default Captions;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import updateCaptionsOwner from '/imports/api/captions/server/modifiers/updateCaptionsOwner';

export default function captionsOwnerUpdated({ header, body }) {
export default async function captionsOwnerUpdated({ header, body }) {
const { meetingId } = header;
const {
locale,
ownerId,
} = body;

updateCaptionsOwner(meetingId, locale, ownerId);
await updateCaptionsOwner(meetingId, locale, ownerId);
}
7 changes: 5 additions & 2 deletions bigbluebutton-html5/imports/api/captions/server/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ const init = (meetingId) => {
method: 'get',
url: LOCALES_URL,
responseType: 'json',
}).then((response) => {
}).then(async (response) => {
const { status } = response;
if (status !== 200) return;

const locales = response.data;
locales.forEach((locale) => createCaptions(meetingId, locale.locale, locale.name));
await Promise.all(locales.map(async (locale) => {
const caption = await createCaptions(meetingId, locale.locale, locale.name);
return caption;
}));
}).catch((error) => Logger.error(`Could not create captions for ${meetingId}: ${error}`));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Logger from '/imports/startup/server/logger';
import setTranscript from '/imports/api/captions/server/modifiers/setTranscript';
import updatePad from '/imports/api/pads/server/methods/updatePad';

export default function pushSpeechTranscript(locale, transcript, type) {
export default async function pushSpeechTranscript(locale, transcript, type) {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);

Expand All @@ -15,7 +15,7 @@ export default function pushSpeechTranscript(locale, transcript, type) {
check(transcript, String);
check(type, String);

const captions = Captions.findOne({
const captions = await Captions.findOneAsync({
meetingId,
ownerId: requesterUserId,
locale,
Expand All @@ -28,7 +28,7 @@ export default function pushSpeechTranscript(locale, transcript, type) {
updatePad(meetingId, requesterUserId, locale, text);
}

setTranscript(meetingId, locale, transcript);
await setTranscript(meetingId, locale, transcript);
}
} catch (err) {
Logger.error(`Exception while invoking method pushSpeechTranscript ${err.stack}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { extractCredentials } from '/imports/api/common/server/helpers';
import Logger from '/imports/startup/server/logger';
import setDictation from '/imports/api/captions/server/modifiers/setDictation';

export default function startDictation(locale) {
export default async function startDictation(locale) {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);

check(meetingId, String);
check(requesterUserId, String);
check(locale, String);

const captions = Captions.findOne({
const captions = await Captions.findOneAsync({
meetingId,
ownerId: requesterUserId,
locale,
});

if (captions) setDictation(meetingId, locale, true);
if (captions) await setDictation(meetingId, locale, true);
} catch (err) {
Logger.error(`Exception while invoking method startDictation ${err.stack}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import { extractCredentials } from '/imports/api/common/server/helpers';
import Logger from '/imports/startup/server/logger';
import setDictation from '/imports/api/captions/server/modifiers/setDictation';

export default function stopDictation(locale) {
export default async function stopDictation(locale) {
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);

check(meetingId, String);
check(requesterUserId, String);
check(locale, String);

const captions = Captions.findOne({
const captions = await Captions.findOne({
meetingId,
ownerId: requesterUserId,
locale,
});

if (captions) setDictation(meetingId, locale, false);
if (captions) await setDictation(meetingId, locale, false);
} catch (err) {
Logger.error(`Exception while invoking method stopDictation ${err.stack}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import Captions from '/imports/api/captions';
import Logger from '/imports/startup/server/logger';

export default function clearCaptions(meetingId) {
export default async function clearCaptions(meetingId) {
if (meetingId) {
try {
const numberAffected = Captions.remove({ meetingId });
const numberAffected = await Captions.removeAsync({ meetingId });

if (numberAffected) {
Logger.info(`Cleared Captions (${meetingId})`);
Expand All @@ -14,7 +14,7 @@ export default function clearCaptions(meetingId) {
}
} else {
try {
const numberAffected = Captions.remove({});
const numberAffected = await Captions.removeAsync({});

if (numberAffected) {
Logger.info('Cleared Captions (all)');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Captions from '/imports/api/captions';
import Logger from '/imports/startup/server/logger';

export default function createCaptions(meetingId, locale, name) {
export default async function createCaptions(meetingId, locale, name) {
try {
check(meetingId, String);
check(locale, String);
Expand All @@ -22,7 +22,7 @@ export default function createCaptions(meetingId, locale, name) {
transcript: '',
};

const numberAffected = Captions.upsert(selector, modifier);
const { numberAffected } = await Captions.upsertAsync(selector, modifier);

if (numberAffected) {
Logger.verbose(`Created captions=${locale} meeting=${meetingId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Captions from '/imports/api/captions';
import Logger from '/imports/startup/server/logger';

export default function setDictation(meetingId, locale, dictating) {
export default async function setDictation(meetingId, locale, dictating) {
try {
check(meetingId, String);
check(locale, String);
Expand All @@ -20,7 +20,7 @@ export default function setDictation(meetingId, locale, dictating) {
},
};

const numberAffected = Captions.upsert(selector, modifier);
const { numberAffected } = Captions.upsertAsync(selector, modifier);

if (numberAffected) {
Logger.info(`Set captions=${locale} dictating=${dictating} meeting=${meetingId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Captions from '/imports/api/captions';
import Logger from '/imports/startup/server/logger';

export default function setTranscript(meetingId, locale, transcript) {
export default async function setTranscript(meetingId, locale, transcript) {
try {
check(meetingId, String);
check(locale, String);
Expand All @@ -19,7 +19,7 @@ export default function setTranscript(meetingId, locale, transcript) {
},
};

const numberAffected = Captions.upsert(selector, modifier);
const numberAffected = await Captions.upsertAsync(selector, modifier);

if (numberAffected) {
Logger.debug(`Set captions=${locale} transcript=${transcript} meeting=${meetingId}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { check } from 'meteor/check';
import Captions from '/imports/api/captions';
import Logger from '/imports/startup/server/logger';

export default function updateCaptionsOwner(meetingId, locale, ownerId) {
export default async function updateCaptionsOwner(meetingId, locale, ownerId) {
try {
check(meetingId, String);
check(locale, String);
Expand All @@ -20,7 +20,7 @@ export default function updateCaptionsOwner(meetingId, locale, ownerId) {
},
};

const numberAffected = Captions.upsert(selector, modifier);
const numberAffected = await Captions.upsert(selector, modifier);

if (numberAffected) {
Logger.info(`Added captions=${locale} owner=${ownerId} meeting=${meetingId}`);
Expand Down
5 changes: 3 additions & 2 deletions bigbluebutton-html5/imports/api/captions/server/publishers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Meteor } from 'meteor/meteor';
import Logger from '/imports/startup/server/logger';
import AuthTokenValidation, { ValidationStates } from '/imports/api/auth-token-validation';

function captions() {
const tokenValidation = AuthTokenValidation.findOne({ connectionId: this.connection.id });
async function captions() {
const tokenValidation = await AuthTokenValidation
.findOneAsync({ connectionId: this.connection.id });

if (!tokenValidation || tokenValidation.validationStatus !== ValidationStates.VALIDATED) {
Logger.warn(`Publishing Captions was requested by unauth connection ${this.connection.id}`);
Expand Down