Reputation: 1
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 ?
Upvotes: 0
Views: 3448
Reputation: 474
After running this .js file, both peers will establish the connection between them and can start communication but on server not in browser.
Upvotes: 0
Reputation: 115
It is now supported by specifying wrtc: wrtc
when you're initiating the connection. Source: https://www.npmjs.com/package/simple-peer#in-node
var wrtc = require('wrtc');
var peer = new SimplePeer({ initiator: true, wrtc: wrtc })
Upvotes: 2
Reputation: 419
You are starting example in nodejs (on server), and there is no window.location on server. You need to start this example from client (browser). There is no need for server for p2p (only for initial connection data exchange)
Upvotes: 0