I use WebSocket to stream audio file's chunks. I defined a handler for the Socket.onmessage event and I defined an AudioContext. The problem is I lose chunks when I decode audio data. Here is my handler:
var socket = new WebSocket('ws://127.0.0.1:8080');
socket.binaryType = 'arraybuffer';
socket.onmessage = function(msg) {
console.log('received'); // printed 29 times
audioctx.decodeAudioData(msg.data, function(buffer) {
console.log('decoded'); // printed 1 time
});
};
I think it's linked to the asynchronism of the callback function but I don't know how to fix it.