bigbluebutton-Github/bigbluebutton-html5/imports/ui/services/meeting-settings/index.js
prlanzarin 71f958ca47 fix(bbb-html5): crash due to undefined metadataProp access
A client crash may happen if either the Meeting collection or the
document's metadataProp attribute are undefined whenever the
getFromMeetingSettings util is called to fetch metadata.
It's debatable whether anything is working in the client if the
documents being accessed here are unavailable, but it'll still be logged
and might bork an ongoing reconnect.

Use optional chaining + nullish coalescing to avoid causing TypeErrors
in those situations while also returning default metadata values
properly.
2024-04-12 14:31:38 -03:00

12 lines
350 B
JavaScript

import Auth from '/imports/ui/services/auth';
import Meetings from '/imports/api/meetings';
export default function getFromMeetingSettings(setting, defaultValue) {
const meeting = Meetings.findOne(
{ meetingId: Auth.meetingID },
{ fields: { metadataProp: 1 } },
);
return meeting?.metadataProp?.metadata?.[setting] ?? defaultValue;
}