Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added client/assets/beep.wav
Binary file not shown.
7 changes: 7 additions & 0 deletions client/stores/clicks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const animate = require('../utils/animate')
const { start, checkForAccount } = require('../../src/')
const validUrl = require('valid-url')
const uuid = require('uuid/v1')
const AudioMachine = require('../utils/audio-machine')
const { OBJECT, STRING, UNDEFINED,
ARRAY, INTEGER, BOOL, FUNCTION } = require('../../src/utils')

Expand Down Expand Up @@ -85,6 +86,11 @@ function store (state, emitter) {
state.proofForm = { username: '', service: '', text: '' }
state.navAnimation = true

// set up sound things
const audio = new AudioMachine();
// http://soundbible.com/419-Tiny-Button-Push.html
audio.addSound('peerOnEnter', 'assets/beep.wav')

emitter.on('DOMContentLoaded', function () {
animate.startAnimation('nav-animation')

Expand Down Expand Up @@ -139,6 +145,7 @@ function store (state, emitter) {
}

emitter.emit('updatePeerProfile', profile)
audio.playSound('peerOnEnter')
},

'peer left': (message) => {
Expand Down
37 changes: 37 additions & 0 deletions client/utils/audio-machine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const { isNode } = require('../../src/utils')
module.exports = class AudioMachine {
constructor () {
// enviornment check, currently node isn't supported
// TODO: make this work with node
if (isNode()){
throw new Error('Can not instantiate AudioMachine in node env. Currently unsupported.')
}

this.playlist = {}
}

addSound (name, src) {
const newSound = {}
const soundElement = document.createElement('audio')

soundElement.setAttribute('src', src);
newSound[name] = soundElement

this.playlist = Object.assign(
newSound,
this.playlist
)
}

playSound (name) {
if (typeof name !== 'string') {
throw new TypeError('AudioMachine.playSound type of name is not string.')
}

if (!this.playlist.hasOwnProperty(name)) {
throw new ReferenceError(`AudioMachine.playlist does not have sound ${name}`)
}

this.playlist[name].play()
}
}
8 changes: 8 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ function a2t (arrayBuffer) {
return new TextDecoder("utf-8").decode(arrayBuffer)
}

function isNode () {
if (typeof process === 'undefined') {
return false
}
return true
}

module.exports = {
isNode: isNode,
a2t: a2t,
t2a: t2a,
STRING: 'string',
Expand Down