2024-04-19 08:43:26 +08:00
|
|
|
import { makeVar } from '@apollo/client';
|
|
|
|
import { Notification } from './queries';
|
2024-05-29 21:26:11 +08:00
|
|
|
import { getSettingsSingletonInstance } from '/imports/ui/services/settings';
|
2024-04-19 08:43:26 +08:00
|
|
|
import { throttle } from '/imports/utils/throttle';
|
|
|
|
|
|
|
|
const GUEST_WAITING_BELL_THROTTLE_TIME = 10000;
|
|
|
|
|
2024-04-22 22:16:18 +08:00
|
|
|
const lastLayoutUpdateNotification = makeVar(new Date().getTime());
|
2024-04-19 08:43:26 +08:00
|
|
|
|
|
|
|
export const NotifyPublishedPoll = (
|
|
|
|
notification: Notification,
|
|
|
|
notifier: (notification: Notification) => void,
|
2024-04-23 04:54:12 +08:00
|
|
|
isModerator: boolean,
|
2024-04-19 08:43:26 +08:00
|
|
|
presenter: boolean,
|
|
|
|
) => {
|
|
|
|
if (
|
2024-04-23 07:31:31 +08:00
|
|
|
(presenter || isModerator)
|
2024-04-19 08:43:26 +08:00
|
|
|
) {
|
|
|
|
notifier(notification);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function ringGuestWaitingBell() {
|
2024-05-29 21:26:11 +08:00
|
|
|
const Settings = getSettingsSingletonInstance();
|
2024-04-19 08:43:26 +08:00
|
|
|
// @ts-ignore - JS code
|
|
|
|
if (Settings.application.guestWaitingAudioAlerts) {
|
2024-05-29 21:26:11 +08:00
|
|
|
const CDN = window.meetingClientSettings.public.app.cdn;
|
|
|
|
const BASENAME = window.meetingClientSettings.public.app.basename;
|
|
|
|
const HOST = CDN + BASENAME;
|
|
|
|
|
2024-04-19 08:43:26 +08:00
|
|
|
const audio = new Audio(`${HOST}/resources/sounds/doorbell.mp3`);
|
|
|
|
audio.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const ringGuestWaitingBellThrottled = throttle(
|
|
|
|
ringGuestWaitingBell,
|
|
|
|
GUEST_WAITING_BELL_THROTTLE_TIME,
|
|
|
|
{ leading: true, trailing: false },
|
|
|
|
);
|
|
|
|
|
|
|
|
export const pendingGuestAlert = (
|
|
|
|
notification: Notification,
|
|
|
|
notifier: (notification: Notification) => void,
|
|
|
|
) => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const Settings = getSettingsSingletonInstance();
|
2024-04-19 08:43:26 +08:00
|
|
|
// @ts-ignore - JS code
|
|
|
|
if (Settings.application.guestWaitingPushAlerts) {
|
|
|
|
notifier(notification);
|
|
|
|
}
|
|
|
|
|
|
|
|
ringGuestWaitingBellThrottled();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const userJoinPushAlert = (
|
|
|
|
notification: Notification,
|
|
|
|
notifier: (notification: Notification) => void,
|
|
|
|
) => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const Settings = getSettingsSingletonInstance();
|
2024-04-19 08:43:26 +08:00
|
|
|
const {
|
|
|
|
userJoinAudioAlerts,
|
|
|
|
userJoinPushAlerts,
|
|
|
|
// @ts-ignore - JS code
|
|
|
|
} = Settings.application;
|
|
|
|
|
|
|
|
if (!userJoinAudioAlerts && !userJoinPushAlerts) return;
|
|
|
|
|
|
|
|
if (userJoinAudioAlerts) {
|
|
|
|
new Audio(`${window.meetingClientSettings.public.app.cdn
|
2024-08-03 02:10:39 +08:00
|
|
|
+ window.meetingClientSettings.public.app.basename}`
|
2024-04-19 08:43:26 +08:00
|
|
|
+ '/resources/sounds/userJoin.mp3').play();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userJoinPushAlerts) {
|
|
|
|
notifier(notification);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const userLeavePushAlert = (
|
|
|
|
notification: Notification,
|
|
|
|
notifier: (notification: Notification) => void,
|
|
|
|
) => {
|
2024-05-29 21:26:11 +08:00
|
|
|
const Settings = getSettingsSingletonInstance();
|
2024-04-19 08:43:26 +08:00
|
|
|
const {
|
|
|
|
userLeaveAudioAlerts,
|
|
|
|
userLeavePushAlerts,
|
|
|
|
// @ts-ignore - JS code
|
|
|
|
} = Settings.application;
|
|
|
|
|
|
|
|
if (!userLeaveAudioAlerts && !userLeavePushAlerts) return;
|
|
|
|
|
|
|
|
if (userLeaveAudioAlerts) {
|
|
|
|
new Audio(`${window.meetingClientSettings.public.app.cdn
|
2024-08-03 02:10:39 +08:00
|
|
|
+ window.meetingClientSettings.public.app.basename}`
|
2024-04-19 08:43:26 +08:00
|
|
|
+ '/resources/sounds/userJoin.mp3').play();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userLeavePushAlerts) {
|
|
|
|
notifier(notification);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export const layoutUpdate = (
|
|
|
|
notification: Notification,
|
|
|
|
notifier: (notification: Notification) => void,
|
|
|
|
) => {
|
|
|
|
const last = new Date(lastLayoutUpdateNotification()).getTime();
|
|
|
|
const now = new Date().getTime();
|
|
|
|
if (now - last < 1000) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
lastLayoutUpdateNotification(now);
|
|
|
|
notifier(notification);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default {
|
|
|
|
NotifyPublishedPoll,
|
|
|
|
pendingGuestAlert,
|
|
|
|
userJoinPushAlert,
|
|
|
|
userLeavePushAlert,
|
|
|
|
layoutUpdate,
|
|
|
|
};
|