Просмотр исходного кода

@uppy/companion-client: do not open socket more than once

This also has the upside of letting the JS engine garbage collect the
underlying `WebSocket` instance.

Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
Artur Paikin 2 лет назад
Родитель
Сommit
5ce2da5b4a
1 измененных файлов с 3 добавлено и 0 удалено
  1. 3 0
      packages/@uppy/companion-client/src/Socket.js

+ 3 - 0
packages/@uppy/companion-client/src/Socket.js

@@ -24,6 +24,8 @@ export default class UppySocket {
   [Symbol.for('uppy test: getQueued')] () { return this.#queued }
 
   open () {
+    if (this.#socket != null) return
+
     this.#socket = new WebSocket(this.opts.target)
 
     this.#socket.onopen = () => {
@@ -37,6 +39,7 @@ export default class UppySocket {
 
     this.#socket.onclose = () => {
       this.#isOpen = false
+      this.#socket = null
     }
 
     this.#socket.onmessage = this.#handleMessage