From 04c6e375278068d1a052c89f4b3278707e8c3841 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 10 Apr 2018 00:53:17 +0200 Subject: [PATCH] [lib.audio-manager] chromium/webkit fix (must connect scriptProcessor to output --- parcel/lib/audio-manager.js | 82 ++++++++++++++++++++++++------------- 1 file changed, 53 insertions(+), 29 deletions(-) diff --git a/parcel/lib/audio-manager.js b/parcel/lib/audio-manager.js index 25451fe..d12590d 100644 --- a/parcel/lib/audio-manager.js +++ b/parcel/lib/audio-manager.js @@ -54,6 +54,7 @@ export default class AudioManager{ /* (5) Bind network controller to send() function */ this.network.out.onaudioprocess = this.send.bind(this); + /*Chrome fix*/this.network.out.connect(this.output); /* (6) Set up our filters' parameters */ this.setUpFilters(); @@ -99,9 +100,6 @@ export default class AudioManager{ }.bind(this.dbg), this.dbg.interval*1000); - - this.test = true; - } @@ -162,21 +160,24 @@ export default class AudioManager{ /* (1) Disconnect all by default */ this.input.disconnect(); - /* (2) Get first filter */ + /* (2) Also link to analyser */ + this.input.connect(this.analyser); + + /* (3) Get first filter */ let first_filter = this.filters.voice_clarity; let last_filter = this.filters.voice_sss; - /* (3) If unlink -> connect directly to NETWORK output */ + /* (4) If unlink -> connect directly to NETWORK output */ if( unlink === true ) return this.input.connect(this.network.out); - /* (4) If linking -> connect input to volume */ + /* (5) If linking -> connect input to volume */ this.input.connect(this.volume); - /* (5) If linking -> connect volume to filter stack */ + /* (6) If linking -> connect volume to filter stack */ this.volume.connect(first_filter); - /* (5) If linking -> connect stack end to network.out */ + /* (7) If linking -> connect stack end to network.out */ last_filter.connect(this.network.out); @@ -190,8 +191,9 @@ export default class AudioManager{ /* (1) Bind audio stream ---------------------------------------------------------*/ + console.log('BINDING', _stream); + /* (1) bind our audio stream to our source */ - console.log(_stream); this.input = this.ctx.createMediaStreamSource(_stream); @@ -200,9 +202,6 @@ export default class AudioManager{ /* (1) Link through filters */ this.linkFilters(); - /* (2) Also link to analyser */ - this.input.connect(this.analyser); - gs.get.audio_conn = 2; // voice connected @@ -406,7 +405,7 @@ export default class AudioManager{ }.bind(this); /* (3) Debug */ - this.ws.onopen = () => ( gs.get.audio_conn = 1 ); // listening + this.ws.onopen = () => gs.get.audio_conn !== 2 && (gs.get.audio_conn = 1); // listening this.ws.onclose = () => ( gs.get.audio_conn = null ); // disconnected @@ -422,29 +421,54 @@ export default class AudioManager{ /* (1) Start websocket */ this.wsconnect(wsAddress); + /* (2) Set our streaming binding function */ + let streaming_binding = function(stream){ + + // this.recorder = new MediaRecorder(stream); + + this.bindRecorderStream(stream); + + // this.recorder.onstart = () => console.warn('[audio] recording'); + + // this.recorder.onstop = () => { + // this.recorder.stream.getTracks().map( t => t.stop() ); + // this.recorder = null; + // console.warn('[audio] stopped recording'); + // }; + + // // start recording + // this.recorder.start(); + + }.bind(this); + + + navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia; + + + /* (3) If navigator.mediaDevices.getUserMedia */ if( navigator.mediaDevices && navigator.mediaDevices.getUserMedia ){ - navigator.mediaDevices.getUserMedia({ audio: true }) - .then( stream => { + console.log('[audio] using "navigator.mediaDevices.getUserMedia"') - this.recorder = new MediaRecorder(stream); - this.bindRecorderStream(stream); + return navigator.mediaDevices.getUserMedia({ audio: true }) + .then(streaming_binding) + .catch((e) => console.warn('[audio] microphone recorder issue', e)); - this.recorder.onstart = () => console.warn('[audio] recording'); - this.recorder.onstop = () => { - this.recorder.stream.getTracks().map( t => t.stop() ); - this.recorder = null; - console.warn('[audio] stopped recording'); - }; + } - // start recording - this.recorder.start(); + /* (4) If old version */ + if( navigator.getUserMedia ){ - }) - .catch( e => console.warn('[audio] microphone permission issue', e) ); + console.log('[audio] using "navigator.getUserMedia"') - }else - console.warn('[audio] microphone not supported'); + return navigator.getUserMedia({ audio: true }, + streaming_binding, + (e) => console.warn('[audio] microphone recorder issue', e)); + + } + + + console.warn('[audio] recorder not supported'); }