simplewebrtc / SimpleWebRTC

Simplest WebRTC ever
Other
4.65k stars 1.19k forks source link

Issue with joining/leaving room and getting list of peers #692

Open Zythyr opened 6 years ago

Zythyr commented 6 years ago

I have been testing SimpleWebRTC for a situation where multiple peers (>2) need to be connected together and communicate directly. Here is my demo code for troubleshooting: https://codepen.io/anon/pen/rvNawx

I have noticed the following issues. I am unsure if these issues are intentional by design or I am using SimpleWebRTC incorrectly:

  1. leftRoomevent is ONLY emitted for the peer that left the room. There is no way for other peers to know if one of their peers has left the room. Is it possible to emit an event for all peers and notify them which peer has left the room?

    1. The output of webrtc.getPeers() is incorrect for the 2nd peer when the room name is the same as the session ID of one of the peers AND when there are 3 ore more peers. Steps to recreate issue:
      • Open 3 tabs with demo code
      • Assign the room name of 1st peer to be the same as 1st peer's session ID and join the room
      • Join the remaining peers with the same room name as 1st peer's session ID
      • Get list of peers. Notice that for the 2nd peer, there are duplicate peers listed
  2. When a peer is connected to room1, then joins room2, the output of webrtc.getPeers() is incorrect for the peer that joined room2. The webrtc.getPeers() outputs the peers of room1 also when the peer is connected to room2. Steps to recreate issue:

    • Open 3 tabs with demo code. Make all peers join room1.
    • Make of the peers join room2.
    • Get list of peers for a peer that is connected to room1 but NOT room2
    • Get list of peers for the peer that WAS connected to room1 but now is connected to room2
    • Notice that for peer in room1, only room1 peers are listed but for peer in room2, all peers included room1 peers are listed
  3. When a peer is already connected to a room tries to connect to the same room again, the event createdPeergets emitted again for the other peers also connected to the room. In addition the output of webrtc.getPeers() shows duplicates for the peer that tries to connect to the already connected room.

  4. How do I correctly use the webrtc.getPeers() function? According to the docs, it says I need to provide a session ID for the argument of getPeers() function. However when I provide a session ID webrtc.getPeers(sessionID), I don't get a list of peers.

xdumaine commented 6 years ago

@Zythyr thanks for your time writing this up. I want to be able to fully read through and review your open changes, I really appreciate them. I'll come back shortly.

Zythyr commented 6 years ago

@xdumaine I wanted to follow up on this issue since I am heavily starting to integrate SimpleWebRTC in my app.

Most critical issue for me is that there is no way to find out when a peer has left the room or got disconnected. leftRoom event is ONLY emitted for the peer that left the room and is NOT announced to all the peers. This makes it difficult to keep track of all the peers in the room.

khanhhaquang commented 6 years ago

Hope you can solve method getPeers() soon.

JakeTrock commented 6 years ago

What is the status on this? I've been trying to use the snippet below to get the number of clients in a room, but for some reason, it only returns zero...

webrtc.getPeers(webrtc.connection.getSessionid()).length