Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Old clients get isolated #2

Open
kifhan opened this issue May 21, 2017 · 8 comments
Open

Old clients get isolated #2

kifhan opened this issue May 21, 2017 · 8 comments
Labels

Comments

@kifhan
Copy link

kifhan commented May 21, 2017

screenshot_2017-05-21_15-38-15
right one is newer client, others are clients that connect together few hours ago.
old 2 clients are still can co-operate work.

I guess it is signal server problem?

@kifhan
Copy link
Author

kifhan commented May 26, 2017

Uncaught Error: Ice connection failed.
at Peer._onIceConnectionStateChange (multihack.js:27486)
at RTCPeerConnection.Peer.self._pc.oniceconnectionstatechange (multihack.js:27134)

And this happens randomly. Those two are relevant I thing.
What are the reasons of ICE failure? - Stackoverflow

I've checked on chrome://webrtc-internals/ and found message below which I didn't get involved.
5/26/2017, 12:41:47 PM iceconnectionstatechange => disconnected

I think we should do something with this RTCPeerConnection.oniceconnectionstatechange.

In Simple-peer, any event like disconnected, failed, closed happens, it destroy connection.

Peer.prototype._onIceConnectionStateChange = function () {
  var self = this
  if (self.destroyed) return
  var iceGatheringState = self._pc.iceGatheringState
  var iceConnectionState = self._pc.iceConnectionState
  self._debug('iceConnectionStateChange %s %s', iceGatheringState, iceConnectionState)
  self.emit('iceConnectionStateChange', iceGatheringState, iceConnectionState)
  if (iceConnectionState === 'connected' || iceConnectionState === 'completed') {
    clearTimeout(self._reconnectTimeout)
    self._pcReady = true
    self._maybeReady()
  }
  if (iceConnectionState === 'disconnected') {
    if (self.reconnectTimer) {
      // If user has set `opt.reconnectTimer`, allow time for ICE to attempt a reconnect
      clearTimeout(self._reconnectTimeout)
      self._reconnectTimeout = setTimeout(function () {
        self._destroy()
      }, self.reconnectTimer)
    } else {
      self._destroy()
    }
  }
  if (iceConnectionState === 'failed') {
    self._destroy(new Error('Ice connection failed.'))
  }
  if (iceConnectionState === 'closed') {
    self._destroy()
  }
}

So when this happened, show the modal to user to be able to refresh the page.

@kifhan
Copy link
Author

kifhan commented May 26, 2017

Oh, maybe this could be the solution.

on y-multihack

  self._client = new SimpleSignalClient(self._socket, {
    room: self.room,
    reconnectTimer: 100
  })

I'd tested it, and it seems work fine.
But ice connection fail event, I need to keep watch it to how to deal with it.

@t-mullen t-mullen added the bug label May 27, 2017
@t-mullen
Copy link
Member

So adding a reconnect timer fixes the issue? That would make sense if ICE is only disconnecting for a short time.

@kifhan
Copy link
Author

kifhan commented May 29, 2017

Yes, disconnecting ICE is regularly happens and reconnectTimer can fix this.
But connection failed is rarely happens and I don't know what cause this yet.

@kifhan
Copy link
Author

kifhan commented Jun 6, 2017

I assume ICE connection failed happens because of NAT.

Found this from simple-peer page

connection does not work on some networks?
If a direct connection fails, in particular, because of NAT traversal and/or firewalls, WebRTC ICE uses an intermediary (relay) TURN server. In other words, ICE will first use STUN with UDP to directly connect peers and, if that fails, will fall back to a TURN relay server.
In order to use a TURN server, you must specify the config option to the SimplePeer constructor. See the API docs above.

And someone had same issue.
feross/simple-peer#181 (comment)

I think I will make TURN server on my own. Before that, let me drop the link here. ;)
TURN-server-installation-guide

** maybe we could use exist websocket instead TURN server to relay client who uses NAT and/or firewall.

@t-mullen
Copy link
Member

t-mullen commented Jun 6, 2017

I should just use the websocket fallback on WebRTC failure. That's basically what a TURN server does anyhow.

@kifhan
Copy link
Author

kifhan commented Jun 6, 2017

@t-mullen
Copy link
Member

t-mullen commented Jun 6, 2017

I'd like to avoid using 3rd party services. If a business ever decides to use this, security will be a concern.

A 3rd party TURN could be a server option though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants