subins2000 / p2pt

Simple WebRTC Peer 2 Peer connections using WebTorrent trackers as the signalling server. Use WebTorrent trackers for any kind of WebRTC app ! 🔥 Make WebRTC apps fast & easy ! 🚀⭐
https://WebDrop.Space
MIT License
559 stars 52 forks source link

addTrack to peer connection #49

Open Weedshaker opened 2 years ago

Weedshaker commented 2 years ago

Hello,

I read the comment on Issue: https://github.com/subins2000/p2pt/issues/29 and then tried to add a video track to the connection analog the description from here: https://webrtc.org/getting-started/remote-streams . The first issue was to get the peerConnection, which I managed to do with a hook at:

this._pc = new (this._wrtc.RTCPeerConnection)(this.config)

else I could only grab the peerConnection at:

p2pt.on('peerconnect', peer => peer._pc)

which according to the https://webrtc.org/getting-started/remote-streams here would be too late but I am not certain. Anyhow, in a further step I add the video and audio tracks:

p2pt.on('track', event => console.log('p2ptTrack', event)) pc.addEventListener('track', event => console.log('pcTrack', event)) // https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia navigator.mediaDevices.getUserMedia({ audio: true, // We want an audio track video: true // And we want a video track }) .then(localStream => { // https://webrtc.org/getting-started/remote-streams localStream.getTracks().forEach(track => pc.addTrack(track, localStream)) })

I was not able to get any 'track' event. Even when I did overwrite or hook within:

this._pc.ontrack = event => { this._onTrack(event) }

Does anyone have a solution for this problem?