From dd0c7f32a7dfcb034b940f6912728ad6f1731236 Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sun, 7 Oct 2018 23:28:37 +0200 Subject: [PATCH] Make sure the AudioContext is created only after user interaction See https://goo.gl/7K7WLu --- app/index.js | 10 +++++++--- app/voice.js | 2 +- app/worker-client.js | 4 +++- package.json | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/index.js b/app/index.js index fe786d1..f9aa729 100644 --- a/app/index.js +++ b/app/index.js @@ -262,7 +262,7 @@ class Settings { class GlobalBindings { constructor () { this.settings = new Settings() - this.connector = new WorkerBasedMumbleConnector(audioContext.sampleRate) + this.connector = new WorkerBasedMumbleConnector() this.client = null this.userContextMenu = new ContextMenu() this.channelContextMenu = new ContextMenu() @@ -334,6 +334,10 @@ class GlobalBindings { log('Connecting to server ', host) + // Note: This call needs to be delayed until the user has interacted with + // the page in some way (which at this point they have), see: https://goo.gl/7K7WLu + this.connector.setSampleRate(audioContext().sampleRate) + // TODO: token this.connector.connect(`wss://${host}:${port}`, { username: username, @@ -555,9 +559,9 @@ class GlobalBindings { }).on('voice', stream => { console.log(`User ${user.username} started takling`) var userNode = new BufferQueueNode({ - audioContext: audioContext + audioContext: audioContext() }) - userNode.connect(audioContext.destination) + userNode.connect(audioContext().destination) stream.on('data', data => { if (data.target === 'normal') { diff --git a/app/voice.js b/app/voice.js index ff538e3..6b048de 100644 --- a/app/voice.js +++ b/app/voice.js @@ -103,7 +103,7 @@ export class VADVoiceHandler extends VoiceHandler { super(client, settings) let level = settings.vadLevel const self = this - this._vad = vad(audioContext, theUserMedia, { + this._vad = vad(audioContext(), theUserMedia, { onVoiceStart () { console.log('vad: start') self._active = true diff --git a/app/worker-client.js b/app/worker-client.js index c6096b6..f1c2bac 100644 --- a/app/worker-client.js +++ b/app/worker-client.js @@ -12,7 +12,7 @@ import worker from './worker' * Only stuff which we need in mumble-web is proxied, i.e. this is not a generic solution. */ class WorkerBasedMumbleConnector { - constructor (sampleRate) { + constructor () { this._worker = webworkify(worker) this._worker.addEventListener('message', this._onMessage.bind(this)) this._reqId = 1 @@ -20,7 +20,9 @@ class WorkerBasedMumbleConnector { this._clients = {} this._nextVoiceId = 1 this._voiceStreams = {} + } + setSampleRate (sampleRate) { this._postMessage({ method: '_init', sampleRate: sampleRate diff --git a/package.json b/package.json index 962a039..5097a01 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ ], "devDependencies": { "audio-buffer-utils": "^3.1.2", - "audio-context": "^0.1.0", + "audio-context": "^1.0.3", "babel-core": "^6.18.2", "babel-loader": "^6.2.8", "babel-plugin-transform-runtime": "^6.15.0", @@ -52,6 +52,6 @@ "mumble-client-codecs-browser": "^1.2.0", "mumble-client-websocket": "^1.0.0", "mumble-client": "^1.3.0", - "web-audio-buffer-queue": "^1.0.0" + "web-audio-buffer-queue": "^1.1.0" } }