uwsgi-websocket GET / websocket нет PONG получено в течение 3 секунд - PullRequest
0 голосов
/ 31 мая 2018

Я пытаюсь реализовать websocket через uwsgi Gevent.Но между 2,3 запросами я всегда получаю no PONG received in 3 seconds ошибку.

Код на стороне сервера:

@ws.route('/websocket')
def audio(ws):
   first_message = True
   total_msg = ""
   sample_rate = 0
   total_data = []
   while True:
      msg = ws.receive()
      # processing message here and sending response back
      ws.send("response")


if __name__ == '__main__':
    app.run(https='0.0.0.0:443,{},{}'.format(ssl_cert,ssl_key), port = 5002, gevent=1000)

Код на стороне клиента:

ws = new WebSocket('wss://ec2-54-72-7-110.eu-west-1.compute.amazonaws.com/websocket');
    //ws = new WebSocket('wss://ec2-54-72-7-110.eu-west-1.compute.amazonaws.com:5000/websocket');
    ws.onopen = function(evt) {
    console.log('Connected to websocket.');
    alert("Recording started")

     navigator.getUserMedia({audio: true, video: false}, initializeRecorder, function(e) {
          console.log('No live audio input: ' + e);
      });
  }

function initializeRecorder(stream){
   audio_context = new AudioContext;
   sampleRate = audio_context.sampleRate;
   ws.send("sample rate:" + sampleRate);
   var audioInput = audio_context.createMediaStreamSource(stream);

   console.log("Created media stream.");

   var bufferSize = 4096;
   // record only 1 channel
   recorder = audio_context.createScriptProcessor(bufferSize, 1, 1);
   // specify the processing function
   recorder.onaudioprocess = recorderProcess;

   // connect stream to our recorder
   audioInput.connect(recorder);
   // connect our recorder to the previous destination
   recorder.connect(audio_context.destination);
}

function recorderProcess(e) {
    var left = e.inputBuffer.getChannelData(0);
    if (ws.readyState === WebSocket.OPEN) {
        var view   = new Int16Array(convertFloat32ToInt16(left))
        console.log(view);
        ws.send(view);
    }
}

function close_WebSocket(){
  console.log("done")
  ws.send("done")
  ws.onmessage = function(evt) {
            console.log(evt.data)
            ws.close()
  }
  audio_context.close();

}

Iне знаете что с ним не так?

...