Simple-peer: .on("signal") fires even though {initiator: false} (version 9.1.0 and higher)

Created on 11 Oct 2018  路  3Comments  路  Source: feross/simple-peer

In version 9.1.0 and higher, .on("signal") fires, even though the initiator is set to false. This does not happen in version 9.0.0.

Minimal example with 9.1.0 (same behavior as 9.1.1 and 9.1.2)

HTML:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>DEBUG 9.1.0</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div>
        <form>
            <input type="button" id="connect" disabled value="Connect"></button>
        </form>
    </div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/simple-peer/9.1.0/simplepeer.min.js"></script>
<script src="debug.js"></script>

</html>

debug.js:

  window.onload = () => {
    const SimplePeer = window.SimplePeer
    const connectButton = document.getElementById("connect")
    connectButton.disabled = false
    connectButton.onclick = connectClicked
  }

  const connectClicked = event => {
    event.preventDefault()
    navigator.mediaDevices
      .getUserMedia({ video: true, audio: true })
      .then(function(stream) {
        console.debug("Got user media")
        peer = new SimplePeer({ initiator: false, stream: stream })
        peer.on("signal", data => {
          // Peer wants to send signalling data
          console.debug(`Send Signal message: ${data}`)
        })
      })
      .catch(function(err) {
        console.error(`Could not get user media or other error in setup, ${err}`)
      })
  }

Current behavior:

  • You get a "Send signal message" log line on the console

Needed behavior:

  • You don't get a "Send signal message" log line, indicating that signal has not fired

If you change the version to 9.0.0, the behavior is correct. However, I couldn't find a changelog (but I'll proceed with that for now as a workaround)

bug

All 3 comments

That signal message informs the other peer that negotiation is required. We should skip sending it on the first negotiation though.

Thx! Yes, I was thinking it should not fire at all when it's not the negotiator :)

I'm just going by the docs btw, https://github.com/feross/simple-peer/blob/master/README.md#events, meaning the on(signal) event. Just to be sure, is this behavior still documented as it should be?

Other than that, I managed to get my application together with the workaround release as of now, in about half a day. It's a very nice library to use!

The behaviour will be as documented after that PR merges ^

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexmarion picture alexmarion  路  4Comments

riddle28 picture riddle28  路  3Comments

feross picture feross  路  3Comments

saagarbethi picture saagarbethi  路  4Comments

idlatest picture idlatest  路  4Comments