- From: Tomoyuki Shimizu via GitHub <sysbot+gh@w3.org>
- Date: Wed, 20 Jan 2016 07:31:47 +0000
- To: public-secondscreen@w3.org
To see actual behavior of `closing` state, I have made example codes
of WebSocket, like below:
```javascript
window.addEventListener('load', function() {
var state = ['CONNECTING', 'OPEN', 'CLOSING', 'CLOSED'];
var log = document.getElementById('log');
var ws = new WebSocket('wss://websocket-server/path');
ws.addEventListener('open', function() {
log.innerHTML += 'WebSocket: OPEN<br>';
// close WebSocket connection during receiving message from a
server
setTimeout(function() {
log.innerHTML += "WebSocket: close()<br>";
ws.close();
}, 50);
});
ws.addEventListener('message', function() {
log.innerHTML += 'WebSocket: message received (readyState === "' +
state[ws.readyState] + '")<br>';
});
ws.addEventListener('close', function() {
log.innerHTML += 'WebSocket: CLOSED<br>';
});
});
```
This example assumes that the WebSocket server would send a large
message to the client as soon as the connection would have been
established.
[I tried this example](https://labs.othersight.jp/closingtest/), and
several browsers such as Chrome, Firefox, Edge and IE11 showed the
same result like below:
> WebSocket: OPEN
> WebSocket: close()
> WebSocket: CLOSED
This result indicates that WebSocket client in most browsers would
discard messages sent from a server after calling `close()`. In this
result, State of the client became `closed` when the client finished
receiving all messages from the server, i.e. state of the WebSocket
connection had been `closing` until then.
On the other hand, Safari showed a different result like below:
> WebSocket: OPEN
> WebSocket: close()
> WebSocket: message received (readyState === "CLOSING")
> WebSocket: CLOSED
--
GitHub Notification of comment by tomoyukilabs
Please view or discuss this issue at
https://github.com/w3c/presentation-api/issues/240#issuecomment-173118230
using your GitHub account
Received on Wednesday, 20 January 2016 07:31:53 UTC