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')
}
})