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

New event hooks #50

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 51 additions & 5 deletions src/process/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export default class WebhooksEvent {
"meeting-screenshare-started",
"meeting-screenshare-stopped",
"meeting-presentation-changed",
"presentation-uploaded",
"presentation-annotated-pdf-ready",
"user-joined",
"user-left",
"user-audio-voice-enabled",
Expand Down Expand Up @@ -59,6 +61,10 @@ export default class WebhooksEvent {
"SetCurrentPresentationEvtMsg",
"RecordingStatusChangedEvtMsg",
],
PRESENTATION_EVENTS: [
"PresentationConversionCompletedEvtMsg",
"NewPresFileAvailableEvtMsg",
],
USER_EVENTS: [
"UserJoinedMeetingEvtMsg",
"UserLeftMeetingEvtMsg",
Expand Down Expand Up @@ -120,6 +126,8 @@ export default class WebhooksEvent {
if (this.inputEvent) {
if (this.mappedEvent(this.inputEvent, WebhooksEvent.RAW.MEETING_EVENTS)) {
this.meetingTemplate(this.inputEvent);
} else if (this.mappedEvent(this.inputEvent, WebhooksEvent.RAW.PRESENTATION_EVENTS)) {
this.presentationTemplate(this.inputEvent);
} else if (this.mappedEvent(this.inputEvent, WebhooksEvent.RAW.USER_EVENTS)) {
this.userTemplate(this.inputEvent);
} else if (this.mappedEvent(this.inputEvent, WebhooksEvent.RAW.CHAT_EVENTS)) {
Expand Down Expand Up @@ -157,6 +165,10 @@ export default class WebhooksEvent {
return true;
}

if (messageObj?.core?.header?.name === event) {
return true;
}

if (messageObj?.envelope?.name === event) {
return true;
}
Expand Down Expand Up @@ -365,6 +377,40 @@ export default class WebhooksEvent {
};
}

presentationTemplate(messageObj) {
const meetingId = messageObj.core.header.meetingId;
const userId = messageObj.core.header.userId;
const extId = UserMapping.get().getExternalUserID(userId) || "";
const data = messageObj.core.body;

this.outputEvent = {
data: {
"type": "event",
"id": this.mapInternalMessage(messageObj),
"attributes": {
"meeting": {
"internal-meeting-id": meetingId,
"external-meeting-id": IDMapping.get().getExternalMeetingID(meetingId)
},
"user":{
"internal-user-id": userId,
"external-user-id": extId,
}
},
"event": {
"ts": Date.now()
}
}
};

if (this.outputEvent.data.id === "presentation-uploaded") {
this.outputEvent.data.attributes["pres-id"] = data.presentation.id;
this.outputEvent.data.attributes["name"] = data.presentation.name;
} else if (this.outputEvent.data.id === "presentation-annotated-pdf-ready") {
this.outputEvent.data.attributes["pres-id"] = data.presId;
this.outputEvent.data.attributes["annotated-file-uri"] = data.annotatedFileURI;
}
}
rapTemplate(messageObj) {
const data = messageObj.core.body;
this.outputEvent = {
Expand Down Expand Up @@ -524,9 +570,7 @@ export default class WebhooksEvent {
}

mapInternalMessage(message) {
const name = message?.envelope?.name || message?.header?.name;

const mappedMsg = (() => { switch (name) {
const mappedMsg = (name) => { switch (name) {
case "MeetingCreatedEvtMsg": return "meeting-created";
case "MeetingDestroyedEvtMsg": return "meeting-ended";
case "RecordingStatusChangedEvtMsg": return this.handleRecordingStatusChanged(message);
Expand All @@ -552,6 +596,8 @@ export default class WebhooksEvent {
case "PadContentEvtMsg": return "pad-content";
case "PollStartedEvtMsg": return "poll-started";
case "UserRespondedToPollRespMsg": return "poll-responded";
case "PresentationConversionCompletedEvtMsg": return "presentation-uploaded";
case "NewPresFileAvailableEvtMsg": return "presentation-annotated-pdf-ready";
// RAP
case "archive_started": return "rap-archive-started";
case "archive_ended": return "rap-archive-ended";
Expand All @@ -570,8 +616,8 @@ export default class WebhooksEvent {
case "deleted": return "rap-deleted";
case "post_publish_started": return "rap-post-publish-started";
case "post_publish_ended": return "rap-post-publish-ended";
} })();
} };

return mappedMsg;
return mappedMsg(message?.envelope?.name) || mappedMsg(message?.header?.name) || mappedMsg(message?.core?.header?.name);
}
}
Loading