Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-70177

WASM QWebSocket doesn't work with strings, strings considered Blobs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.11.0
    • WebSockets
    • None
    • emsdk clang e1.38.11_64bit

    Description

      function onMessage(evt) {
          var ptr;
          var bufferLength = 0;
          var dataType;
          if (window.webSocker.binaryType == "arraybuffer" && typeof evt.data == "object") {
      
              var byteArray = new Uint8Array(evt.data);
              bufferLength = byteArray.length;
      
              ptr = _malloc(byteArray.length);
              HEAP8.set(byteArray, ptr);
      
              dataType = 2;
          }
          else if (window.webSocker.binaryType == "blob") {
              var byteArray = new Int8Array($0);
              console.log("type blob");
              ptr = new Blob(byteArray.buffer);
              dataType = 1;
          }
          else if (typeof evt.data == "string") {
              dataType = 0;
              ptr = allocate(intArrayFromString(evt.data), 'i8', ALLOC_NORMAL);
          }
      
          Runtime.dynCall('viiii', onIncomingMessageCallback, [handler, ptr, bufferLength, dataType]);
          _free(ptr);
      }
      

       

      The above onMessage JavaScript function is from qwebsocket_wasm_p.cpp. As you can see a string will never be emit by QWebSocket::textMessageReceived if window.webSocker.binaryType == "blob". It seams the default binaryType is "blob", so the string case is never executed.

      Workaround: When QWebSocket::connected is emit call QWebSocket::ping(). This will internally send a binary frames and changes the window.webSocker.binaryType to "arraybuffer" so the string case in the above function will now be executed.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            lpotter Lorn Potter
            seamus Seamus Boyle
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes