43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
export function deepEqual(obj1: any, obj2: any) {
|
|
if (obj1 === obj2) return true;
|
|
|
|
if (typeof obj1 !== "object" || obj1 === null || typeof obj2 !== "object" || obj2 === null) {
|
|
return false;
|
|
}
|
|
|
|
const keys1 = Object.keys(obj1);
|
|
const keys2 = Object.keys(obj2);
|
|
|
|
if (keys1.length !== keys2.length) return false;
|
|
|
|
for (let key of keys1) {
|
|
if (!keys2.includes(key)) return false;
|
|
if (!deepEqual(obj1[key], obj2[key])) return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
export function useBeep() {
|
|
const audioContext = ref(new (window.AudioContext)());
|
|
|
|
const playBeep = (frequency = 440, duration = 0.1) => {
|
|
const oscillator = audioContext.value.createOscillator();
|
|
const gainNode = audioContext.value.createGain();
|
|
|
|
oscillator.connect(gainNode);
|
|
gainNode.connect(audioContext.value.destination);
|
|
|
|
gainNode.gain.setValueAtTime(0, audioContext.value.currentTime);
|
|
gainNode.gain.linearRampToValueAtTime(1, audioContext.value.currentTime + 0.01);
|
|
gainNode.gain.linearRampToValueAtTime(0, audioContext.value.currentTime + duration);
|
|
|
|
oscillator.frequency.value = frequency;
|
|
oscillator.start(audioContext.value.currentTime);
|
|
oscillator.stop(audioContext.value.currentTime + duration);
|
|
};
|
|
|
|
return {playBeep};
|
|
}
|