commit 31e5f635d19a69ebe719194aeb8465368e9f672d
parent e573d5741979fa48fdbfebed4f3cedd7f82f9ea5
Author: RobinLinus <robinlinus@users.noreply.github.com>
Date: Fri, 21 Sep 2018 19:24:01 +0200
Add connection state handler
Diffstat:
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/client/scripts/network.js b/client/scripts/network.js
@@ -18,7 +18,7 @@ class ServerConnection {
clearTimeout(this._reconnectTimer);
}
- _isConnected(){
+ _isConnected() {
return this._socket && this._socket.readyState === this._socket.OPEN;
}
@@ -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) {
@@ -288,11 +288,19 @@ class RTCPeer extends Peer {
}
_onChannelClosed() {
- console.log('RTC: channel closed ', this._peerId);
+ console.log('RTC: channel closed', this._peerId);
if (!this.isCaller) return;
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);
}