Преглед изворни кода

@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 година
родитељ
комит
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 }
   [Symbol.for('uppy test: getQueued')] () { return this.#queued }
 
 
   open () {
   open () {
+    if (this.#socket != null) return
+
     this.#socket = new WebSocket(this.opts.target)
     this.#socket = new WebSocket(this.opts.target)
 
 
     this.#socket.onopen = () => {
     this.#socket.onopen = () => {
@@ -37,6 +39,7 @@ export default class UppySocket {
 
 
     this.#socket.onclose = () => {
     this.#socket.onclose = () => {
       this.#isOpen = false
       this.#isOpen = false
+      this.#socket = null
     }
     }
 
 
     this.#socket.onmessage = this.#handleMessage
     this.#socket.onmessage = this.#handleMessage