audio-context-singleton
Advanced tools
Comparing version
34
index.js
@@ -12,23 +12,16 @@ /* global webkitAudioContext */ | ||
function getCurrentContext(done) { | ||
function getCurrentContext() { | ||
var { done } = organizeParams(arguments); | ||
if (audioContext) { | ||
// Warning: opts passed to getCurrentContext are ignored in this case. | ||
// TODO: Think about what to do about this. | ||
resolvedPromise.then(() => done(null, audioContext)); | ||
} else { | ||
getNewContext(done); | ||
getNewContext(arguments); | ||
} | ||
} | ||
function getNewContext(firstParam, secondParam) { | ||
var opts; | ||
var done; | ||
function getNewContext() { | ||
var { opts, done } = organizeParams(arguments); | ||
if (typeof firstParam === 'function') { | ||
done = firstParam; | ||
} else if (typeof secondParam === 'function') { | ||
done = secondParam; | ||
if (typeof firstParam === 'object') { | ||
opts = firstParam; | ||
} | ||
} | ||
if (audioContext) { | ||
@@ -55,2 +48,15 @@ audioContext.close().then(passNewContext); | ||
function organizeParams(firstParam, secondParam) { | ||
var done, opts; | ||
if (typeof firstParam === 'function') { | ||
done = firstParam; | ||
} else if (typeof secondParam === 'function') { | ||
done = secondParam; | ||
if (typeof firstParam === 'object') { | ||
opts = firstParam; | ||
} | ||
} | ||
return { done, opts }; | ||
} | ||
module.exports = AudioContextSingleton; |
{ | ||
"name": "audio-context-singleton", | ||
"version": "1.1.2", | ||
"version": "1.2.0", | ||
"description": "When you want to have an audioContext singleton but don't want to rewrite [this code](index.js), use this. Deals with browser differences in AudioContext and maintains the singleton.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5087
5.28%67
9.84%