Tuesday, 14 March 2017

Why simple peer does not work in nodeJS?

Im trying to use this example on this github https://github.com/feross/simple-peer

var Peer = require('simple-peer')
var p = new Peer({ initiator: location.hash === '#1', trickle: false })

p.on('error', function (err) { console.log('error', err) })

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

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

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

p.on('data', function (data) {
  console.log('data: ' + data)
})

But when i try to execute this code, i have an error: ReferenceError: location is not defined :(

and when I try to delete all the arguments in the brackets like this just to test:

var p = new Peer()

I have an other error: Error: No WebRTC support: Specify opts.wrtc option in this environment

But... How to fix those error to make it work ?



via Tagada

No comments:

Post a Comment