Lazily initialize fallback client

So we do not need to load the huge encoders bundle if we do not even need it.
This commit is contained in:
Jonas Herzig 2020-11-25 17:27:37 +01:00
parent 506a799592
commit 59bb00cbe4
2 changed files with 7 additions and 3 deletions

View file

@ -457,7 +457,9 @@ class GlobalBindings {
// Note: This call needs to be delayed until the user has interacted with // 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 // the page in some way (which at this point they have), see: https://goo.gl/7K7WLu
let ctx = audioContext() let ctx = audioContext()
this.fallbackConnector.setSampleRate(ctx.sampleRate) if (!this.webrtc) {
this.fallbackConnector.setSampleRate(ctx.sampleRate)
}
if (!this._delayedMicNode) { if (!this._delayedMicNode) {
this._micNode = ctx.createMediaStreamSource(this._micStream) this._micNode = ctx.createMediaStreamSource(this._micStream)
this._delayNode = ctx.createDelay() this._delayNode = ctx.createDelay()

View file

@ -12,8 +12,6 @@ import Worker from './worker'
*/ */
class WorkerBasedMumbleConnector { class WorkerBasedMumbleConnector {
constructor () { constructor () {
this._worker = new Worker()
this._worker.addEventListener('message', this._onMessage.bind(this))
this._reqId = 1 this._reqId = 1
this._requests = {} this._requests = {}
this._clients = {} this._clients = {}
@ -29,6 +27,10 @@ class WorkerBasedMumbleConnector {
} }
_postMessage (msg, transfer) { _postMessage (msg, transfer) {
if (!this._worker) {
this._worker = new Worker()
this._worker.addEventListener('message', this._onMessage.bind(this))
}
try { try {
this._worker.postMessage(msg, transfer) this._worker.postMessage(msg, transfer)
} catch (err) { } catch (err) {