Add connection state handler
This commit is contained in:
parent
e573d57419
commit
31e5f635d1
1 changed files with 11 additions and 3 deletions
|
@ -230,7 +230,7 @@ class RTCPeer extends Peer {
|
|||
this._peerId = peerId;
|
||||
this._peer = new RTCPeerConnection(RTCPeer.config);
|
||||
this._peer.onicecandidate = e => this._onIceCandidate(e);
|
||||
this._peer.onconnectionstatechange = e => console.log('RTC: state changed:', this._peer.connectionState);
|
||||
this._peer.onconnectionstatechange = e => this._onConnectionStateChange(e);
|
||||
}
|
||||
|
||||
if (isCaller) {
|
||||
|
@ -293,6 +293,14 @@ class RTCPeer extends Peer {
|
|||
this._start(this._peerId, true); // reopen the channel
|
||||
}
|
||||
|
||||
_onConnectionStateChange(e) {
|
||||
console.log('RTC: state changed:', this._peer.connectionState);
|
||||
switch (this._peer.connectionState) {
|
||||
'disconnected': this._onChannelClosed();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
_send(message) {
|
||||
this._channel.send(message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue