From 95f6bc202deaf424d9d76ff7a73baf4ac7fa3dd2 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Fri, 21 Jun 2024 22:22:20 -0500 Subject: [PATCH] failsafes and more notification sounds --- webpage/audio.js | 58 ++++++++++++++++++++++++++++++++++++++++++++-- webpage/channel.js | 8 +------ webpage/index.js | 6 ++++- webpage/login.js | 17 +++++++++++++- 4 files changed, 78 insertions(+), 11 deletions(-) diff --git a/webpage/audio.js b/webpage/audio.js index b61162f..2300093 100644 --- a/webpage/audio.js +++ b/webpage/audio.js @@ -1,5 +1,5 @@ class voice{ - constructor(wave,freq){ + constructor(wave,freq,volume=1){ this.audioCtx = new (window.AudioContext || window.webkitAudioContext)(); this.info={wave:wave,freq:freq} this.playing=false; @@ -8,6 +8,9 @@ class voice{ this.audioCtx.sampleRate, this.audioCtx.sampleRate, ); + this.gainNode = this.audioCtx.createGain(); + this.gainNode.gain.value=volume; + this.gainNode.connect(this.audioCtx.destination); this.buffer=this.myArrayBuffer.getChannelData(0); this.source = this.audioCtx.createBufferSource(); this.source.buffer = this.myArrayBuffer; @@ -37,6 +40,9 @@ class voice{ } waveFucnion(){ + if(typeof this.wave === 'function'){ + return this.wave; + } switch(this.wave){ case "sin": return (t,freq)=>{ @@ -68,7 +74,7 @@ class voice{ if(this.playing){ return; } - this.source.connect(this.audioCtx.destination); + this.source.connect(this.gainNode); this.playing=true; } @@ -78,4 +84,52 @@ class voice{ this.playing=false; } } + static noises(noise){ + switch(noise){ + case "three":{ + const voicy=new voice("sin",800); + voicy.play(); + setTimeout(_=>{voicy.freq=1000},50); + setTimeout(_=>{voicy.freq=1300},100); + setTimeout(_=>{voicy.stop()},150); + break; + } + case "zip":{ + const voicy=new voice((t,freq)=>{ + return Math.sin(((t+2)**(Math.cos(t*4)))*Math.PI*2*freq); + },700); + voicy.play(); + setTimeout(_=>{voicy.stop()},150); + break; + } + case "square":{ + const voicy=new voice("square",600,.4); + voicy.play() + setTimeout(_=>{voicy.freq=800},50); + setTimeout(_=>{voicy.freq=1000},100); + setTimeout(_=>{voicy.stop()},150); + break; + } + case "beep":{ + const voicy=new voice("sin",800); + voicy.play(); + setTimeout(_=>{voicy.stop()},50); + setTimeout(_=>{voicy.play();},100); + setTimeout(_=>{voicy.stop()},150); + break; + } + } + } + static get sounds(){ + return ["three","zip","square","beep"]; + } + static setNotificationSound(sound){ + let userinfos=JSON.parse(localStorage.getItem("userinfos")); + userinfos.preferances.notisound=sound; + localStorage.setItem("userinfos",JSON.stringify(userinfos)); + } + static getNotificationSound(){ + let userinfos=JSON.parse(localStorage.getItem("userinfos")); + return userinfos.preferances.notisound; + } } diff --git a/webpage/channel.js b/webpage/channel.js index a94f377..7fcc06a 100644 --- a/webpage/channel.js +++ b/webpage/channel.js @@ -509,13 +509,7 @@ class channel{ return message.author.username+" > "+this.owner.properties.name+" > "+this.name; } notify(message){ - { - const voicy=new voice("sin",800); - voicy.play() - setTimeout(_=>{voicy.freq=1000},50); - setTimeout(_=>{voicy.freq=1300},100); - setTimeout(_=>{voicy.stop()},150); - } + voice.noises(voice.getNotificationSound()); if (!("Notification" in window)) { } else if (Notification.permission === "granted") { diff --git a/webpage/index.js b/webpage/index.js index b8a1f6d..a5aa048 100644 --- a/webpage/index.js +++ b/webpage/index.js @@ -459,7 +459,11 @@ function genusersettings(){ ["select","Theme:",["Dark","Light","WHITE"],e=>{ localStorage.setItem("theme",["Dark","Light","WHITE"][e.target.selectedIndex]); setTheme(); - },["Dark","Light","WHITE"].indexOf(localStorage.getItem("theme"))] + },["Dark","Light","WHITE"].indexOf(localStorage.getItem("theme"))], + ["select","Notification sound:",voice.sounds,e=>{ + voice.setNotificationSound(voice.sounds[e.target.selectedIndex]); + voice.noises(voice.sounds[e.target.selectedIndex]); + },voice.sounds.indexOf(voice.getNotificationSound())] ], ["vdiv", ["html",hypothetcialprofie] diff --git a/webpage/login.js b/webpage/login.js index df99e21..8ef8ec4 100644 --- a/webpage/login.js +++ b/webpage/login.js @@ -19,7 +19,7 @@ function getBulkInfo(){ return JSON.parse(localStorage.getItem("userinfos")); } function setDefaults(){ - let userinfos=localStorage.getItem("userinfos"); + let userinfos=JSON.parse(localStorage.getItem("userinfos")); if(!userinfos){ localStorage.setItem("userinfos",JSON.stringify({ currentuser:null, @@ -28,9 +28,24 @@ function setDefaults(){ { theme:"Dark", notifcations:false, + notisound:"three", }, })); } + if(userinfos.users===undefined){ + userinfos.users={}; + } + if(userinfos.preferances===undefined){ + userinfos.preferances={ + theme:"Dark", + notifcations:false, + notisound:"three", + } + } + if(userinfos.preferances&&(userinfos.preferances.notisound===undefined)){ + userinfos.preferances.notisound="three"; + } + localStorage.setItem("userinfos",JSON.stringify(userinfos)); } setDefaults(); class specialuser{