1 year ago

#377897

test-img

Neost

API communication in js web worker

I have a problem with my code: I'm using RecorderJS, and I'm trying to permise this to send sound to my back-end, but as streaming, not as complete recording. I'm using HTML 5 and the last versions of python and flask. I found where I had to put my code for doing that, but my problem is the communication beetween my back and my worker.

I tried to use XMLHttpRequest :

function send_buffer_to_transcription(sound_buffer) {
              // no jquery in workers

              var request = new XMLHttpRequest();
              var url = "'/updateSound2'";
              request.open("POST", url, true);
              request.setRequestHeader("Content-Type", "application/json");
              request.onreadystatechange = function () {
                  if (request.readyState === 4 && request.status === 200) {
                      console.log("son transmis");
                  }
              };

              var data = {
                audioBuffer:JSON.stringify(Array(new Int16Array(sound_buffer)))
              }

              request.send(data);
            }

But I had an issue with that :

Uncaught DOMException: Failed to execute 'open' on 'XMLHttpRequest': Invalid URL
    at send_buffer_to_transcription (blob:http://127.0.0.1:5000/feb04c56-4e80-4418-885f-5f24bc7b9409:79:23)
    at streaming_record (blob:http://127.0.0.1:5000/feb04c56-4e80-4418-885f-5f24bc7b9409:62:19)
    at record (blob:http://127.0.0.1:5000/feb04c56-4e80-4418-885f-5f24bc7b9409:101:17)
    at self.onmessage (blob:http://127.0.0.1:5000/feb04c56-4e80-4418-885f-5f24bc7b9409:27:25)

I tried with webSocket too :

let socket = new WebSocket("wss://127.0.0.1:5000/soudtesting");
            socket.onerror = function (error) {
              console.error(error);
            }

function send_as_socket() {
              socket.send('my message');
            }

But here is the issue I've had :

7fdd8dd0-6354-467b-8b58-253c98412fdd:10 WebSocket connection to 'wss://127.0.0.1:5000/soudtesting' failed: 

(nothing next)

the error looks :

isTrusted: true
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: WebSocket {url: 'wss://127.0.0.1:5000/soudtesting', readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
defaultPrevented: false
eventPhase: 0
path: []
returnValue: true
srcElement: WebSocket {url: 'wss://127.0.0.1:5000/soudtesting', readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
target: WebSocket {url: 'wss://127.0.0.1:5000/soudtesting', readyState: 3, bufferedAmount: 0, onopen: null, onerror: ƒ, …}
timeStamp: 0
type: "error"
[[Prototype]]: Event

Does someone has an explaination, and, if possible a solution please? Really needed.

===== Oops, I forget this : Here's the error which has occured in my back-end (I don't think this will be helpfull, but why not)


127.0.0.1 - - [06/Apr/2022 13:51:55] code 400, message Bad request version ('úú\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93êê\x00\x00\x00\x17\x00\x00ÿ\x01\x00\x01\x00\x00')
ax°×¥¡²DüöàO»Ëgïò&åf@  úúÀ+À/À,À0̨̩ÀÀ   / 5 êê     ÿ   " HTTPStatus.BAD_REQUEST -
127.0.0.1 - - [06/Apr/2022 13:51:55] code 400, message Bad request version ('êê\x13\x01\x13\x02\x13\x03À+À/À,À0̨̩À\x13À\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93úú\x00\x00\x00\x17\x00\x00ÿ\x01\x00\x01\x00\x00')
èbÄÍdµÜQýH³¾²§¶E|}½eO ËX|Da¼j»-ÃñUxù©í弪v[`  êêÀ+À/À,À0̨̩ÀÀ   / 5 úú     ÿ   " HTTPStatus.BAD_REQUEST -

javascript

http

flask

web-worker

0 Answers

Your Answer

Accepted video resources