Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this._endedListener = this.audio.addEventListener('ended', function () {
if (!self.seeking) self.emit('ended')
})
this._timeListener = this.audio.addEventListener('timeupdate', function (ev) {
if (self.seeking) return
var timeupdate = Math.floor(self.audio.currentTime)
if (self.timeupdate === timeupdate) return
self.timeupdate = timeupdate
self.emit('timeupdate', self.timeupdate)
})
this.emit('initialized', this)
}
AudioPlayer.prototype = Object.create(Nanobus.prototype)
AudioPlayer.prototype.seekDebounce = function () {
this.seeking = true
if (this.seekDebounceTimer) clearTimeout(this.seekDebounceTimer)
var self = this
this.seekDebounceTimer = setTimeout(function () {
self.emit('debounce cleared')
self.seeking = false
self.seekDebounceTimer = null
// TODO: check if we are at the end and we lost the endedEvent
}, 1000)
}
AudioPlayer.prototype.queue = function (newIndex) {
this.currentIndex = newIndex
var key = this.trackOrder[this.currentIndex]
Nanostate.prototype.emit = function (eventName) {
var nextState = this._next(eventName)
assert.ok(nextState, 'nanostate.emit: invalid transition' + this.state + '->' + eventName)
if (this._submachine && Object.keys(this.transitions).indexOf(nextState) !== -1) {
this._unregister()
}
this.state = nextState
Nanobus.prototype.emit.call(this, nextState)
}
module.exports = Nanostate
function Nanostate (initialState, transitions) {
if (!(this instanceof Nanostate)) return new Nanostate(initialState, transitions)
assert.equal(typeof initialState, 'string', 'nanostate: initialState should be type string')
assert.equal(typeof transitions, 'object', 'nanostate: transitions should be type object')
this.transitions = transitions
this.state = initialState
this.submachines = {}
this._submachine = null
Nanobus.call(this)
}
Nanostate.prototype = Object.create(Nanobus.prototype)
Nanostate.prototype.constructor = Nanostate
Nanostate.prototype.emit = function (eventName) {
var nextState = this._next(eventName)
assert.ok(nextState, 'nanostate.emit: invalid transition' + this.state + '->' + eventName)
if (this._submachine && Object.keys(this.transitions).indexOf(nextState) !== -1) {
this._unregister()
}
this.state = nextState
Nanobus.prototype.emit.call(this, nextState)
}
Nanostate.prototype.event = function (eventName, machine) {
module.exports = Nanoidb
function Nanoidb (name, version) {
if (!(this instanceof Nanoidb)) return new Nanoidb(name, version)
Nanobus.call(this, 'Nanoidb')
this._name = name
this._version = version
assert.equal(typeof name, 'string', 'Nanoidb: name should be type string')
assert.equal(typeof version, 'number', 'Nanoidb: version should be type number')
this.upgrade(this._version)
}
Nanoidb.prototype = Object.create(Nanobus.prototype)
Nanoidb.prototype.upgrade = function (version) {
assert.equal(typeof version, 'number', 'Nanoidb.upgrade: version should be type number')
this._version = version
this.request = window.indexedDB.open(this._name, this._version)
this.request.onerror = this.onerror.bind(this)
this.request.onsuccess = this.onsuccess.bind(this)
this.request.onupgradeneeded = this.onupgradeneeded.bind(this)
}
Nanoidb.prototype.onsuccess = function (event) {
var storeNames = event.target.result.objectStoreNames
this.db = event.target.result