0

I am building a peer to peer chat application and on a new peer connection, I have a username_set variable set to 0 so it signals that peer doesn't have username. However, it seems that the peer.on(data, function (data) {}) does not get any data as when I type something it does not display anything. I was wondering what's the issue here as I am new to this.

I am using webrtc-swarm which uses simple-peer as a peer object:

var username_set = 0

swarm.on('peer', function(peer, id) {
    console.log('[a new peer connected]')
    console.log('Set username if you havent and continue chatting')  
    if(username_set === 0){
        console.log('Please set username:')
        peer.on('data', function (data) {
        console.log("data:" + data.toString())
        })
    }
    if(username_set === 1){
        console.log('test successful')
    }        
})
Kate Orlova
  • 3,225
  • 5
  • 11
  • 35

1 Answers1

0

The webrtc-swarm package that you are using is outdated and it seems no one is maintaining it.

The last update was more than 2 years ago, before WebRTC 1.0.

It is therefore certain that this webrtc-swarm package is relying on deprecated WebRTC features. As soon as some features were deprecated with the release of WebRTC 1.0 in 2018, some functionality from the previous spec was removed from browsers.

WebRTC is an evolving technology, not even the current spec is 100% implemented, not even by the main browsers. There is no easy way, no library that will work better than the native implementation or make you spare time. You will almost certainly end up wasting your time with deprecation issues if you start using an open source or free WebRTC library now.

My advice is:

  1. Rely on the WebRTC MDN documentation
  2. Take a look at the Guides and Tutorials from MDN
  3. Use Socket.IO for signaling
  4. Setup a TURN server on a Ubuntu machine.
Daniele Molinari
  • 541
  • 6
  • 29