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",
|
"compression": "^1.6.0",
|
||||||
"gulp-nodemon": "^2.0.6"
|
"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",
|
"author": "Daniel Seripap",
|
||||||
"license": "MIT"
|
"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;
|
let fs = window.RequestFileSystem || window.webkitRequestFileSystem;
|
||||||
|
|
||||||
window.favicon = new Favico({
|
window.favicon = new Favico({
|
||||||
@ -6,12 +8,12 @@ window.favicon = new Favico({
|
|||||||
});
|
});
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
let beep = new Audio('beep.mp3');
|
const audio = new AudioHandler();
|
||||||
|
|
||||||
let isActive = false;
|
let isActive = false;
|
||||||
let newMessages = 0;
|
let newMessages = 0;
|
||||||
let FADE_TIME = 150; // ms
|
let FADE_TIME = 150; // ms
|
||||||
let TYPING_TIMER_LENGTH = 400; // ms
|
let TYPING_TIMER_LENGTH = 400; // ms
|
||||||
let soundEnabled = true;
|
|
||||||
|
|
||||||
let COLORS = [
|
let COLORS = [
|
||||||
'#e21400', '#ffe400', '#ff8f00',
|
'#e21400', '#ffe400', '#ff8f00',
|
||||||
@ -437,8 +439,8 @@ $(function() {
|
|||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
newMessages++;
|
newMessages++;
|
||||||
favicon.badge(newMessages);
|
favicon.badge(newMessages);
|
||||||
if (soundEnabled && beep) {
|
if (audio.soundEnabled && beep) {
|
||||||
beep.play();
|
audio.play();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -567,7 +569,7 @@ $(function() {
|
|||||||
$('input.bs-switch').bootstrapSwitch();
|
$('input.bs-switch').bootstrapSwitch();
|
||||||
|
|
||||||
$('input.bs-switch').on('switchChange.bootstrapSwitch', function(event, state) {
|
$('input.bs-switch').on('switchChange.bootstrapSwitch', function(event, state) {
|
||||||
soundEnabled = state;
|
audio.setSoundEnabled(state);
|
||||||
});
|
});
|
||||||
|
|
||||||
function convertStringToArrayBufferView(str) {
|
function convertStringToArrayBufferView(str) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user