Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addTrack to peer connection #49

Open
Weedshaker opened this issue Aug 18, 2022 · 1 comment
Open

addTrack to peer connection #49

Weedshaker opened this issue Aug 18, 2022 · 1 comment

Comments

@Weedshaker
Copy link

Hello,

I read the comment on Issue: #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?

@dragonman225
Copy link

dragonman225 commented Jan 9, 2025

I was testing video call with P2PT today and encounter the same issue — unable to get any track event on a peer.

P2PT uses bittorrent-tracker's WebSocketTracker for finding peers and connecting to them, and WebSocketTracker depends on simple-peer for handling WebRTC.

I did some research and found that in bittorrent-tracker's WebSocketTracker, simple-peer's signal event is handled only once (code), just for establishing the initial connection with a data channel. This causes the required WebRTC renegotiation after adding video tracks to fail (can't exchange offer and answer with new config again through signaling, MDN). Therefore, no track is send to peers and there is no track event.

To solve this issue, I think we need to modify the WebSocketTracker to keep signaling active. We might need to fork it as well. By looking the latest version's code, the developers of bittorrent-tracker seem to focus more on the performance of WebTorrent use case. They even have switched to @thaunknown/simple-peer/lite.js, which removes all media related features from the original simple-peer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants