bigbluebutton-Github/bbb-export-annotations/lib/utils/message-builder.js

90 lines
2.0 KiB
JavaScript
Raw Normal View History

import fs from 'fs';
const config = JSON.parse(fs.readFileSync('./config/settings.json', 'utf8'));
2022-12-19 02:43:14 +08:00
const EXPORT_STATUSES = Object.freeze({
COLLECTING: 'COLLECTING',
PROCESSING: 'PROCESSING',
});
class PresAnnStatusMsg {
constructor(exportJob, status = EXPORT_STATUSES.COLLECTING) {
this.message = {
envelope: {
name: config.log.msgName,
routing: {
sender: exportJob.module,
},
timestamp: (new Date()).getTime(),
},
core: {
header: {
name: config.log.msgName,
meetingId: exportJob.parentMeetingId,
userId: '',
},
body: {
presId: exportJob.presId,
pageNumber: 1,
totalPages: JSON.parse(exportJob.pages).length,
status,
error: false,
},
},
};
}
build = (pageNumber = 1) => {
this.message.core.body.pageNumber = pageNumber;
this.message.envelope.timestamp = (new Date()).getTime();
const event = JSON.stringify(this.message);
this.message.core.body.error = false;
return event;
};
setError = (error = true) => {
this.message.core.body.error = error;
};
setStatus = (status) => {
this.message.core.body.status = status;
};
static get EXPORT_STATUSES() {
return EXPORT_STATUSES;
}
};
class NewPresFileAvailableMsg {
2022-12-19 02:43:14 +08:00
constructor(exportJob, link) {
this.message = {
envelope: {
name: config.notifier.msgName,
routing: {
sender: exportJob.module,
},
timestamp: (new Date()).getTime(),
},
core: {
header: {
name: config.notifier.msgName,
meetingId: exportJob.parentMeetingId,
userId: '',
},
body: {
annotatedFileURI: link,
originalFileURI: '',
convertedFileURI: '',
2022-12-19 02:43:14 +08:00
presId: exportJob.presId,
2023-08-18 21:57:50 +08:00
fileStateType: 'Annotated',
2022-12-19 02:43:14 +08:00
},
},
};
}
build = () => {
return JSON.stringify(this.message);
};
};
export {PresAnnStatusMsg, NewPresFileAvailableMsg};