Skip to content

Commit

Permalink
fix: replace track not matching trackid
Browse files Browse the repository at this point in the history
add viewonly client mode
  • Loading branch information
tyohan committed Sep 9, 2024
1 parent 320af70 commit af5714a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
24 changes: 23 additions & 1 deletion packages/room/peer/peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {

if (stop) {
this._stopTrack(videoTrack)
localStream.mediaStream.removeTrack(videoTrack)
return
}

Expand Down Expand Up @@ -382,7 +383,8 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
for (const transceiver of this._peerConnection.getTransceivers()) {
if (
transceiver.sender.track &&
transceiver.sender.track.kind === newTrack.kind
transceiver.sender.track.kind === newTrack.kind &&
transceiver.sender.track.id === newTrack.id
) {
try {
await transceiver.sender.replaceTrack(newTrack)
Expand Down Expand Up @@ -553,6 +555,7 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {

if (senderTrack.kind === track.kind && senderTrack.id === track.id) {
senderTrack.stop()
track.stop()
}
}
}
Expand Down Expand Up @@ -940,6 +943,25 @@ export const createPeer = ({ api, createStream, event, streams, config }) => {
}
}

/**
* startViewOnly will add a video and audio transceiver to the peer connection
* in order to allow the peer to receive video and audio from the remote peer
* and will start the negotiation process
*/
startViewOnly = async () => {
if (!this._peerConnection) return

this._peerConnection.addTransceiver('video', {
direction: 'sendrecv',
})

this._peerConnection.addTransceiver('audio', {
direction: 'sendrecv',
})

this.negotiate()
}

/**
* @param {RTCPeerConnectionIceEvent} event
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/stream/connection/connection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import camelcaseKeys from 'camelcase-keys'
import { Internal } from '../../internal/index.js'

const { webrtc } = Internal
Expand Down Expand Up @@ -114,7 +113,6 @@ const connection = (() => {

/**
* Open the client connnection
*
* @param {MediaObject} mediaObject - The media object consists of the ID of the stream, media video element and media stream object
*/
const open = async (mediaObject) => {
Expand Down

0 comments on commit af5714a

Please sign in to comment.