Pārlūkot izejas kodu

Lazily initialize fallback client

So we do not need to load the huge encoders bundle if we do not even need it.
Jonas Herzig 3 gadi atpakaļ
vecāks
revīzija
59bb00cbe4
2 mainītis faili ar 7 papildinājumiem un 3 dzēšanām
  1. 3 1
      app/index.js
  2. 4 2
      app/worker-client.js

+ 3 - 1
app/index.js

@@ -457,7 +457,9 @@ class GlobalBindings {
       // 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
       let ctx = audioContext()
-      this.fallbackConnector.setSampleRate(ctx.sampleRate)
+      if (!this.webrtc) {
+        this.fallbackConnector.setSampleRate(ctx.sampleRate)
+      }
       if (!this._delayedMicNode) {
         this._micNode = ctx.createMediaStreamSource(this._micStream)
         this._delayNode = ctx.createDelay()

+ 4 - 2
app/worker-client.js

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