mirror of
https://github.com/darkwire/darkwire.io.git
synced 2025-07-18 10:49:02 +00:00
Start of reorganization: Audio class
This commit is contained in:
parent
27ae0a4fbf
commit
316db0cfc5
@ -28,10 +28,6 @@
|
||||
"compression": "^1.6.0",
|
||||
"gulp-nodemon": "^2.0.6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1",
|
||||
"jsbuild": "uglifyjs src/js/main.js --compress --mangle -o src/public/main.js"
|
||||
},
|
||||
"author": "Daniel Seripap",
|
||||
"license": "MIT"
|
||||
}
|
||||
|
21
src/js/audio.js
Normal file
21
src/js/audio.js
Normal file
@ -0,0 +1,21 @@
|
||||
export default class AudoHandler {
|
||||
constructor() {
|
||||
this.beep = new Audio('beep.mp3');
|
||||
this._soundEnabled = true;
|
||||
}
|
||||
|
||||
get soundEnabled() {
|
||||
return this._soundEnabled;
|
||||
}
|
||||
|
||||
set soundEnabled(state) {
|
||||
if (state) {
|
||||
this._soundEnabled = state;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
play() {
|
||||
this.beep.play();
|
||||
}
|
||||
}
|
@ -1,3 +1,5 @@
|
||||
import AudioHandler from './audio';
|
||||
|
||||
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
||||
|
||||
window.favicon = new Favico({
|
||||
@ -6,12 +8,12 @@ window.favicon = new Favico({
|
||||
});
|
||||
|
||||
$(function() {
|
||||
let beep = new Audio('beep.mp3');
|
||||
const audio = new AudioHandler();
|
||||
|
||||
let isActive = false;
|
||||
let newMessages = 0;
|
||||
let FADE_TIME = 150; // ms
|
||||
let TYPING_TIMER_LENGTH = 400; // ms
|
||||
let soundEnabled = true;
|
||||
|
||||
let COLORS = [
|
||||
'#e21400', '#ffe400', '#ff8f00',
|
||||
@ -437,8 +439,8 @@ $(function() {
|
||||
if (!isActive) {
|
||||
newMessages++;
|
||||
favicon.badge(newMessages);
|
||||
if (soundEnabled && beep) {
|
||||
beep.play();
|
||||
if (audio.soundEnabled && beep) {
|
||||
audio.play();
|
||||
}
|
||||
}
|
||||
|
||||
@ -567,7 +569,7 @@ $(function() {
|
||||
$('input.bs-switch').bootstrapSwitch();
|
||||
|
||||
$('input.bs-switch').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||
soundEnabled = state;
|
||||
audio.setSoundEnabled(state);
|
||||
});
|
||||
|
||||
function convertStringToArrayBufferView(str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user