Re: [webrtc-pc] Is close() supposed to fire state change events? Connection state change set asynchronously? (#1883)

> So, there is just no signalling telling me that the remote end hung up?

@eskimor There is. Either [use a datachannel](https://jsfiddle.net/jib1/m2gvhjtq/):
```js
const dc1 = pc1.createDataChannel("dummy", {negotiated: true, id: 0});
const dc2 = pc2.createDataChannel("dummy", {negotiated: true, id: 0});
await Promise.all([dc1, dc2].map(dc => new Promise(r => dc.onopen = r)));
pc2.close();
dc1.onclose = () => console.log("close fired"); // close fired
```
Works in Firefox and Chrome 82 (probably 80 as well, addIceCandidate errors look unrelated).
But not Safari. @youennf?

Had data channels always been included by default in WebRTC, then we could have done a simpler API for this, but they're not.

Or you can also [use the newer dtls transport object](https://jsfiddle.net/jib1/q4znf9b5/):
```js
const {sender} = pc1.addTransceiver("audio");
await new Promise(r => pc1.onsignalingstatechange = r);
const {transport} = sender;
await new Promise(r => transport.onstatechange = () => transport.state == "connected"
                                                       && r());
pc2.close();
transport.onstatechange = () => console.log(transport.state); // close
```
...which detects when the dtls connection drops, but that still only works in Chrome atm.

-- 
GitHub Notification of comment by jan-ivar
Please view or discuss this issue at https://github.com/w3c/webrtc-pc/issues/1883#issuecomment-597672134 using your GitHub account

Received on Wednesday, 11 March 2020 14:38:12 UTC