simple-peer icon indicating copy to clipboard operation
simple-peer copied to clipboard

simple peer js connect event does not trigger

Open ibalaji777 opened this issue 4 years ago • 3 comments

i used below code in my project

<html>
  <body>
    <style>
      #outgoing {
        width: 600px;
        word-wrap: break-word;
        white-space: normal;
      }
    </style>
    <form>
      <textarea id="incoming"></textarea>
      <button type="submit">submit</button>
    </form>
    <pre id="outgoing"></pre>
    <script src="simplepeer.min.js"></script>
    <script>
      const p = new SimplePeer({
        initiator: location.hash === '#1',
        trickle: false
      })

      p.on('error', err => console.log('error', err))

      p.on('signal', data => {
        console.log('SIGNAL', JSON.stringify(data))
        document.querySelector('#outgoing').textContent = JSON.stringify(data)
      })

      document.querySelector('form').addEventListener('submit', ev => {
        ev.preventDefault()
        p.signal(JSON.parse(document.querySelector('#incoming').value))
      })

      p.on('connect', () => {
        console.log('CONNECT')
        p.send('whatever' + Math.random())
      })

      p.on('data', data => {
        console.log('data: ' + data)
      })
    </script>
  </body>
</html>

But this code does not trigger

  p.on('connect', () => {
        console.log('CONNECT')
        p.send('whatever' + Math.random())
      })

ibalaji777 avatar Dec 02 '21 09:12 ibalaji777

Does your console produce any errors? Posting them here would be a start.

jzombie avatar Dec 22 '21 15:12 jzombie

+1

Also interested in this one because I also see thee peer.on('connect') event not triggering by itself and happing to make manual rerenders in order to trigger it and get the event working. It does suppose to work by itself, right??

Mihai-github avatar May 16 '22 18:05 Mihai-github

Not working for me as well

playmono avatar Jun 10 '23 18:06 playmono