failsafes and more notification sounds
This commit is contained in:
parent
ae43fd497a
commit
95f6bc202d
4 changed files with 78 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
||||||
class voice{
|
class voice{
|
||||||
constructor(wave,freq){
|
constructor(wave,freq,volume=1){
|
||||||
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
this.audioCtx = new (window.AudioContext || window.webkitAudioContext)();
|
||||||
this.info={wave:wave,freq:freq}
|
this.info={wave:wave,freq:freq}
|
||||||
this.playing=false;
|
this.playing=false;
|
||||||
|
@ -8,6 +8,9 @@ class voice{
|
||||||
this.audioCtx.sampleRate,
|
this.audioCtx.sampleRate,
|
||||||
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.buffer=this.myArrayBuffer.getChannelData(0);
|
||||||
this.source = this.audioCtx.createBufferSource();
|
this.source = this.audioCtx.createBufferSource();
|
||||||
this.source.buffer = this.myArrayBuffer;
|
this.source.buffer = this.myArrayBuffer;
|
||||||
|
@ -37,6 +40,9 @@ class voice{
|
||||||
|
|
||||||
}
|
}
|
||||||
waveFucnion(){
|
waveFucnion(){
|
||||||
|
if(typeof this.wave === 'function'){
|
||||||
|
return this.wave;
|
||||||
|
}
|
||||||
switch(this.wave){
|
switch(this.wave){
|
||||||
case "sin":
|
case "sin":
|
||||||
return (t,freq)=>{
|
return (t,freq)=>{
|
||||||
|
@ -68,7 +74,7 @@ class voice{
|
||||||
if(this.playing){
|
if(this.playing){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.source.connect(this.audioCtx.destination);
|
this.source.connect(this.gainNode);
|
||||||
this.playing=true;
|
this.playing=true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -78,4 +84,52 @@ class voice{
|
||||||
this.playing=false;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -509,13 +509,7 @@ class channel{
|
||||||
return message.author.username+" > "+this.owner.properties.name+" > "+this.name;
|
return message.author.username+" > "+this.owner.properties.name+" > "+this.name;
|
||||||
}
|
}
|
||||||
notify(message){
|
notify(message){
|
||||||
{
|
voice.noises(voice.getNotificationSound());
|
||||||
const voicy=new voice("sin",800);
|
|
||||||
voicy.play()
|
|
||||||
setTimeout(_=>{voicy.freq=1000},50);
|
|
||||||
setTimeout(_=>{voicy.freq=1300},100);
|
|
||||||
setTimeout(_=>{voicy.stop()},150);
|
|
||||||
}
|
|
||||||
if (!("Notification" in window)) {
|
if (!("Notification" in window)) {
|
||||||
|
|
||||||
} else if (Notification.permission === "granted") {
|
} else if (Notification.permission === "granted") {
|
||||||
|
|
|
@ -459,7 +459,11 @@ function genusersettings(){
|
||||||
["select","Theme:",["Dark","Light","WHITE"],e=>{
|
["select","Theme:",["Dark","Light","WHITE"],e=>{
|
||||||
localStorage.setItem("theme",["Dark","Light","WHITE"][e.target.selectedIndex]);
|
localStorage.setItem("theme",["Dark","Light","WHITE"][e.target.selectedIndex]);
|
||||||
setTheme();
|
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",
|
["vdiv",
|
||||||
["html",hypothetcialprofie]
|
["html",hypothetcialprofie]
|
||||||
|
|
|
@ -19,7 +19,7 @@ function getBulkInfo(){
|
||||||
return JSON.parse(localStorage.getItem("userinfos"));
|
return JSON.parse(localStorage.getItem("userinfos"));
|
||||||
}
|
}
|
||||||
function setDefaults(){
|
function setDefaults(){
|
||||||
let userinfos=localStorage.getItem("userinfos");
|
let userinfos=JSON.parse(localStorage.getItem("userinfos"));
|
||||||
if(!userinfos){
|
if(!userinfos){
|
||||||
localStorage.setItem("userinfos",JSON.stringify({
|
localStorage.setItem("userinfos",JSON.stringify({
|
||||||
currentuser:null,
|
currentuser:null,
|
||||||
|
@ -28,9 +28,24 @@ function setDefaults(){
|
||||||
{
|
{
|
||||||
theme:"Dark",
|
theme:"Dark",
|
||||||
notifcations:false,
|
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();
|
setDefaults();
|
||||||
class specialuser{
|
class specialuser{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue