chopme-frontend-common 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/utils/index.d.ts
CHANGED
package/build/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const playNotificationSound: () => void;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.playNotificationSound = void 0;
|
|
4
|
+
let audioContext = null;
|
|
5
|
+
const getAudioContext = () => {
|
|
6
|
+
if (typeof window === "undefined")
|
|
7
|
+
return null;
|
|
8
|
+
const AudioContextClass = window.AudioContext ||
|
|
9
|
+
window
|
|
10
|
+
.webkitAudioContext;
|
|
11
|
+
if (!AudioContextClass)
|
|
12
|
+
return null;
|
|
13
|
+
if (!audioContext) {
|
|
14
|
+
audioContext = new AudioContextClass();
|
|
15
|
+
}
|
|
16
|
+
return audioContext;
|
|
17
|
+
};
|
|
18
|
+
const playTone = (ctx, frequency, startTime, duration) => {
|
|
19
|
+
const oscillator = ctx.createOscillator();
|
|
20
|
+
const gainNode = ctx.createGain();
|
|
21
|
+
oscillator.type = "sine";
|
|
22
|
+
oscillator.frequency.value = frequency;
|
|
23
|
+
gainNode.gain.setValueAtTime(0, startTime);
|
|
24
|
+
gainNode.gain.linearRampToValueAtTime(0.2, startTime + 0.02);
|
|
25
|
+
gainNode.gain.exponentialRampToValueAtTime(0.0001, startTime + duration);
|
|
26
|
+
oscillator.connect(gainNode);
|
|
27
|
+
gainNode.connect(ctx.destination);
|
|
28
|
+
oscillator.start(startTime);
|
|
29
|
+
oscillator.stop(startTime + duration);
|
|
30
|
+
};
|
|
31
|
+
const playNotificationSound = () => {
|
|
32
|
+
const ctx = getAudioContext();
|
|
33
|
+
if (!ctx)
|
|
34
|
+
return;
|
|
35
|
+
try {
|
|
36
|
+
if (ctx.state === "suspended") {
|
|
37
|
+
ctx.resume();
|
|
38
|
+
}
|
|
39
|
+
const now = ctx.currentTime;
|
|
40
|
+
playTone(ctx, 880, now, 0.15);
|
|
41
|
+
playTone(ctx, 1175, now + 0.12, 0.18);
|
|
42
|
+
}
|
|
43
|
+
catch (_a) {
|
|
44
|
+
// Ignore playback failures (e.g. autoplay restrictions)
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.playNotificationSound = playNotificationSound;
|