Skip to content

Commit

Permalink
widgets: soundboard widget to interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sogehige committed Feb 6, 2019
1 parent 997a9d5 commit 68ff8e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 28 deletions.
24 changes: 0 additions & 24 deletions src/bot/widgets/soundboard.js

This file was deleted.

30 changes: 30 additions & 0 deletions src/bot/widgets/soundboard.ts
@@ -0,0 +1,30 @@
import * as glob from 'glob';

import Widget from './_interface';

class SoundBoard extends Widget {
[x: string]: any; // TODO: remove after interface ported to TS

constructor() {
super({});
this.addWidget('soundboard', 'widget-title-soundboard', 'fas fa-music');
}

public sockets() {
this.socket.on('connection', (socket) => {
socket.on('getSoundBoardSounds', (cb) => {
glob('public/dist/soundboard/*.mp3', (err, files) => {
if (err) { return cb([]); }

const sounds: string[] = [];
for (const file of files) {
sounds.push(file.split('/').pop().replace('.mp3', ''));
}
cb(sounds);
});
});
});
}
}

module.exports = new SoundBoard();
7 changes: 3 additions & 4 deletions src/panel/widgets/components/soundboard.vue
Expand Up @@ -60,12 +60,13 @@ import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'
library.add(faMusic, faVolumeUp, faVolumeDown, faVolumeOff)
export default {
props: ['socket', 'commons'],
props: ['commons'],
components: {
'font-awesome-icon': FontAwesomeIcon
},
data: function () {
return {
socket: io('/widgets/soundboard', { query: "token=" + this.token }),
volume: 50,
audio: null,
sounds: []
Expand All @@ -88,9 +89,7 @@ export default {
}
},
created: function () {
this.socket.emit('getSoundBoardSounds')
this.socket.off('soundBoardSounds').on('soundBoardSounds', sounds => this.sounds = sounds)
this.socket.emit('getSoundBoardSounds', (sounds) => this.sounds = sounds)
if (localStorage.getItem('/widget/soundboard/volume')) this.volume = JSON.parse(localStorage.getItem('/widget/soundboard/volume'))
},
methods: {
Expand Down

0 comments on commit 68ff8e2

Please sign in to comment.