Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upHow do you manually add webrtc peer? #1574
Closed
Comments
This comment has been minimized.
This comment has been minimized.
|
Figure it out by myself. For any references, this is what i did to connect all tabs to eachother let bc = new BroadcastChannel('foo1')
function onTorrent (torrent) {
// Adding myself to the mix
let initiator = true
let me = new simplePeer({ initiator })
let peerId = client.peerId
me.id = peerId
torrent.addPeer(me)
bc.onmessage = evt => {
var { sdp, initiator, peerId } = evt.data
if (initiator) {
let otherPeer = new WebTorrent.simplePeer()
otherPeer.id = peerId
torrent.addPeer(otherPeer)
otherPeer.signal(sdp)
otherPeer.on('signal', sdp => {
bc.postMessage({ sdp, initiator: false, peerId })
})
} else if (sdp.type === 'answer') {
torrent._peers[peerId].conn.signal(sdp)
}
}
me.on('signal', sdp => {
bc.postMessage({ sdp, initiator, peerId })
initiator = false
})
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
What version of WebTorrent?
0.103.0
I'm trying to connect two torrent clients within the same LAN.
To achieve this I'm using my own communication layer so no tracker, ip:port or DHT should be used.
So I want to use the WebRTC instead of TCP
In the source i found this:
webtorrent/lib/torrent.js
Lines 747 to 750 in 5b7c5ee
I guess that is what i want to use. So to start simple I'm just trying to figure out how to do this using the same browser tab.
So here something along the line at what I'm trying to do:
I know i also have to do the signaling myself. I think i need a bit of help with that also
It certainly would have help if there was something like
torrent.createWebRTCPeer(opts)that took care of other things like adding the peer to the torrent setting a timeout, setting peerID...