2022-04-07 21:42:26 +08:00
|
|
|
import React from 'react';
|
2023-03-02 21:25:08 +08:00
|
|
|
import { throttle } from '/imports/utils/throttle';
|
2022-04-06 05:02:05 +08:00
|
|
|
import { notify } from '/imports/ui/services/notification';
|
|
|
|
import Settings from '/imports/ui/services/settings';
|
|
|
|
import Styled from './styles';
|
|
|
|
|
|
|
|
const CDN = Meteor.settings.public.app.cdn;
|
|
|
|
const BASENAME = Meteor.settings.public.app.basename;
|
|
|
|
const HOST = CDN + BASENAME;
|
|
|
|
const GUEST_WAITING_BELL_THROTTLE_TIME = 10000;
|
|
|
|
|
|
|
|
function ringGuestWaitingBell() {
|
|
|
|
if (Settings.application.guestWaitingAudioAlerts) {
|
|
|
|
const audio = new Audio(`${HOST}/resources/sounds/doorbell.mp3`);
|
|
|
|
audio.play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-02 02:13:29 +08:00
|
|
|
const ringGuestWaitingBellThrottled = throttle(
|
2022-04-06 05:02:05 +08:00
|
|
|
ringGuestWaitingBell,
|
|
|
|
GUEST_WAITING_BELL_THROTTLE_TIME,
|
|
|
|
{ leading: true, trailing: false },
|
|
|
|
);
|
|
|
|
|
|
|
|
function messageElement(text, type) {
|
|
|
|
if (type === 'title') {
|
|
|
|
return <Styled.TitleMessage>{ text }</Styled.TitleMessage>;
|
|
|
|
}
|
|
|
|
if (type === 'content') {
|
|
|
|
return <Styled.ContentMessage>{ text }</Styled.ContentMessage>;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-07 21:42:26 +08:00
|
|
|
function alert(obj, intl) {
|
2022-04-06 05:02:05 +08:00
|
|
|
if (Settings.application.guestWaitingPushAlerts) {
|
|
|
|
notify(
|
|
|
|
messageElement(obj.messageValues[0], 'title'),
|
2022-04-06 23:07:12 +08:00
|
|
|
obj.notificationType,
|
|
|
|
obj.icon,
|
2022-04-06 05:02:05 +08:00
|
|
|
null,
|
|
|
|
messageElement(
|
2022-04-06 23:07:12 +08:00
|
|
|
intl.formatMessage({
|
|
|
|
id: obj.messageId,
|
|
|
|
description: obj.messageDescription,
|
|
|
|
}),
|
2022-04-06 05:02:05 +08:00
|
|
|
'content',
|
|
|
|
),
|
|
|
|
true,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ringGuestWaitingBellThrottled();
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
alert,
|
|
|
|
};
|