2021-10-16 03:07:13 +08:00
|
|
|
import { check } from 'meteor/check';
|
|
|
|
import Captions from '/imports/api/captions';
|
|
|
|
import { extractCredentials } from '/imports/api/common/server/helpers';
|
|
|
|
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';
|
|
|
|
|
2023-03-09 22:05:50 +08:00
|
|
|
export default async function pushSpeechTranscript(locale, transcript, type) {
|
2021-10-16 03:07:13 +08:00
|
|
|
try {
|
|
|
|
const { meetingId, requesterUserId } = extractCredentials(this.userId);
|
|
|
|
|
|
|
|
check(meetingId, String);
|
|
|
|
check(requesterUserId, String);
|
|
|
|
check(locale, String);
|
|
|
|
check(transcript, String);
|
|
|
|
check(type, String);
|
|
|
|
|
2023-03-09 22:05:50 +08:00
|
|
|
const captions = await Captions.findOneAsync({
|
2021-10-16 03:07:13 +08:00
|
|
|
meetingId,
|
|
|
|
ownerId: requesterUserId,
|
|
|
|
locale,
|
|
|
|
dictating: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
if (captions) {
|
|
|
|
if (type === 'final') {
|
|
|
|
const text = `\n${transcript}`;
|
|
|
|
updatePad(meetingId, requesterUserId, locale, text);
|
|
|
|
}
|
|
|
|
|
2023-03-09 22:05:50 +08:00
|
|
|
await setTranscript(meetingId, locale, transcript);
|
2021-10-16 03:07:13 +08:00
|
|
|
}
|
|
|
|
} catch (err) {
|
|
|
|
Logger.error(`Exception while invoking method pushSpeechTranscript ${err.stack}`);
|
|
|
|
}
|
|
|
|
}
|