Skip to content

Commit

Permalink
addTrack handler
Browse files Browse the repository at this point in the history
  • Loading branch information
vpalmisano committed Dec 29, 2024
1 parent ed3c844 commit 1eeb46b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions scripts/peer-connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ window.RTCPeerConnection = function (conf, options) {
},
options,
)
debug(`created`, { conf, options, pc })

PeerConnections.set(id, pc)

Expand Down Expand Up @@ -296,6 +297,24 @@ window.RTCPeerConnection = function (conf, options) {
}
}

const addTrackNative = pc.addTrack.bind(pc)
pc.addTrack = (...args) => {
debug(`addTrack`, args)
const sender = addTrackNative(...args)
for (const transceiver of pc.getTransceivers()) {
if (['sendonly', 'sendrecv'].includes(transceiver.direction)) {
if (encodedInsertableStreams && timestampInsertableStreams) {
handleTransceiverForInsertableStreams(id, transceiver)
}
handleTransceiverForPlayoutDelayHint(id, transceiver, 'addTrack')
handleTransceiverForJitterBufferTarget(id, transceiver, 'addTrack')

checkSaveStream(transceiver)
}
}
return sender
}

pc.addEventListener('track', async event => {
const { receiver, transceiver } = event
if (receiver?.track) {
Expand Down

0 comments on commit 1eeb46b

Please sign in to comment.