Parcourir la source

@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 il y a 2 ans
Parent
commit
5ce2da5b4a
1 fichiers modifiés avec 3 ajouts et 0 suppressions
  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