-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
30 lines (27 loc) · 894 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { Utils } from 'cable_ready'
import './event_listeners'
const { dispatch, before, operate, after } = Utils
export default {
playSound: (operation, callee) => {
before(document, callee, operation)
if (
!operate(operation, () => {
const { src } = operation
const canplaythrough = () => {
document.audio.removeEventListener('canplaythrough', canplaythrough)
document.audio.play()
}
const ended = () => {
document.audio.removeEventListener('ended', ended)
dispatch(document, 'cable-ready:after-play-sound', operation)
}
document.audio.addEventListener('canplaythrough', canplaythrough)
document.audio.addEventListener('ended', ended)
if (src) document.audio.src = src
document.audio.play()
})
) {
after(document, callee, operation)
}
}
}