feross / feross/simple-peer

replaceTraks only works for the second/third participant

Open
#864 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.8k
Forks
983
PR merge metrics
No merged PRs in 30d

Description

In the room, one of the participants share the screen or changes the camera source, everything works if the second or third participant does it, but if the first one connected does it, then the video freezes for the other participants.
I use replaceTraks.
```
replaceTracks(track: MediaStreamTrack) {
this.meetingParticipants.forEach((participant) => {
if (participant.connection) {
participant.connection.replaceTrack(
participant.connection.streams[0].getVideoTracks()[0],
track,
participant.connection.streams[0]
)
}
})
}
```
share screen function:
```
toogleScreenSharingHandler = () => {
if (!this.isScreenSharing) {
this.rootStore.meetingStore.enableVideo()
navigator.mediaDevices.getDisplayMedia().then((stream) => {
const videoTracks = this.stream.getVideoTracks()[0]
if (videoTracks) {
videoTracks.enabled = false
}
this.screenSharingstream = stream
this.isScreenSharing = true
this.camDisabled = true
const screenTrack = stream.getTracks()[0]
this.rootStore.meetingStore.replaceTracks(screenTrack)
screenTrack.onended = () => {
this.isScreenSharing = false
const videoTracks = this.stream.getVideoTracks()[0]
if (videoTracks) {
videoTracks.enabled = false
this.rootStore.meetingStore.disableVideo()
}
}
})
return
}
if (this.isScreenSharing) {
this.isScreenSharing = false
this.screenSharingstream.getVideoTracks().forEach((track) => track.stop())
this.rootStore.meetingStore.disableVideo()
}
}
```

simple-peer v9.11.0, node v16.13.1, npm v8.3.0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.