Nat*_*dly 17 javascript safari webkit websocket
似乎Safari 10.1中的WebSocket API具有可以缓冲的最大量的二进制数据,然后发送的下一条消息会收到错误"WebSocket连接到...失败:无法发送WebSocket帧".
然后Safari使用代码1006(CLOSE_ABNORMAL)关闭连接.
的WebSockets都应该报告的bufferedAmount -但Safari浏览器始终报告0,直到后出现错误并关闭连接.
我尝试在每条消息之间执行100ms的setTimeout,这似乎适用于小块数据的情况,但是当我发送结束JSON消息时,它似乎很脆弱且大块仍然会出错,即使延迟时间较长.
您可以在此处看到错误 - "播放示例"按钮在Safari 10.03中可用,但在10.1中出错.(处理WebSocket连接的代码.)
关于如何解决这个问题的任何想法?或者甚至是限制是什么?我知道Safari是开源的,但我不知道在哪里看.
更新:这是一个更简单的例子:
// this fails in Safari 10.1 but works in 10.03 (and other browsers)
var ws = new WebSocket('wss://echo.websocket.org');
ws.onerror = function(evt) {
// Not sure why, but error events seem to have no useful information
// The console, however, will have the following error:
// WebSocket connection to 'wss://echo.websocket.org/' failed: Failed to send WebSocket frame.
console.log("WebSocket error - see console for message");
}
ws.onclose = function(evt) {
console.log(`WebSocket closed with code: ${evt.code}, reason: ${evt.reason}`);
}
ws.onopen = function() {
console.log('sending first binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
// this gets the error
console.log('sending second binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
console.log('sending third binary message');
ws.send(new Uint8Array(23085));
console.log('bufferedAmount is ' + ws.bufferedAmount);
ws.close();
}
Run Code Online (Sandbox Code Playgroud)
https://jsfiddle.net/yta2mjuf/2/
第二条消息在关闭连接时出错,在第三条消息之后bufferedAmount是23093.