From d1d6f6767d3b826446a1ad60e4059ae468f6200b Mon Sep 17 00:00:00 2001 From: Chad Phillips Date: Wed, 15 Nov 2017 18:26:06 -0800 Subject: [PATCH] State management for underlying AudioContext object This allows the AudioContext object created by hark to be managed by a user of the library. In particular, useful for iOS WebRTC scenarios where the AudioContext stream must be started by a user action. --- hark.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/hark.js b/hark.js index c1ef408..a1d8c50 100644 --- a/hark.js +++ b/hark.js @@ -64,6 +64,19 @@ module.exports = function(stream, options) { harker.speaking = false; + harker.suspend = function() { + audioContext.suspend(); + } + harker.resume = function() { + audioContext.resume(); + } + Object.defineProperty(harker, 'state', { get: function() { + return audioContext.state; + }}); + audioContext.onstatechange = function() { + harker.emit('state_change', audioContext.state); + } + harker.setThreshold = function(t) { threshold = t; };