-
Notifications
You must be signed in to change notification settings - Fork 173
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
Add fallback for addTrack
if addTransceiver
is not supported by a device
#403
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ca39ec9
wip
lukasIO 26a33fd
move sender logic into RTCEngine
lukasIO 6178a9f
renaming, make methods private
lukasIO e9cdd44
remove debug config
lukasIO 2708e88
address comments
lukasIO 7fed69b
remove unused code
lukasIO 97b14d1
changeset
lukasIO File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,6 @@ import { | |
ScreenSharePresets, | ||
TrackPublishOptions, | ||
VideoCaptureOptions, | ||
VideoCodec, | ||
} from '../track/options'; | ||
import { Track } from '../track/Track'; | ||
import { constraintsForOptions, mergeDefaultOptions } from '../track/utils'; | ||
|
@@ -556,15 +555,6 @@ export default class LocalParticipant extends Participant { | |
if (encodings) { | ||
transceiverInit.sendEncodings = encodings; | ||
} | ||
// addTransceiver for react-native is async. web is synchronous, but await won't effect it. | ||
const transceiver = await this.engine.publisher.pc.addTransceiver( | ||
track.mediaStreamTrack, | ||
transceiverInit, | ||
); | ||
if (track.kind === Track.Kind.Video && opts.videoCodec) { | ||
this.setPreferredCodec(transceiver, track.kind, opts.videoCodec); | ||
track.codec = opts.videoCodec; | ||
} | ||
|
||
if (track.codec === 'av1' && encodings && encodings[0]?.maxBitrate) { | ||
this.engine.publisher.setTrackCodecBitrate( | ||
|
@@ -577,7 +567,7 @@ export default class LocalParticipant extends Participant { | |
this.engine.negotiate(); | ||
|
||
// store RTPSender | ||
track.sender = transceiver.sender; | ||
track.sender = await this.engine.createSender(track, opts, encodings); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will need to happen before |
||
if (track instanceof LocalVideoTrack) { | ||
track.startMonitor(this.engine.client); | ||
} else if (track instanceof LocalAudioTrack) { | ||
|
@@ -652,20 +642,11 @@ export default class LocalParticipant extends Participant { | |
|
||
const ti = await this.engine.addTrack(req); | ||
|
||
if (!this.engine.publisher) { | ||
throw new UnexpectedConnectionState('publisher is closed'); | ||
} | ||
const transceiverInit: RTCRtpTransceiverInit = { direction: 'sendonly' }; | ||
if (encodings) { | ||
transceiverInit.sendEncodings = encodings; | ||
} | ||
// addTransceiver for react-native is async. web is synchronous, but await won't effect it. | ||
const transceiver = await this.engine.publisher.pc.addTransceiver( | ||
simulcastTrack.mediaStreamTrack, | ||
transceiverInit, | ||
); | ||
this.setPreferredCodec(transceiver, track.kind, videoCodec); | ||
track.setSimulcastTrackSender(videoCodec, transceiver.sender); | ||
await this.engine.createSimulcastSender(track, simulcastTrack, opts, encodings); | ||
|
||
this.engine.negotiate(); | ||
log.debug(`published ${videoCodec} for track ${track.sid}`, { encodings, trackInfo: ti }); | ||
|
@@ -1000,50 +981,6 @@ export default class LocalParticipant extends Participant { | |
return publication; | ||
} | ||
|
||
private setPreferredCodec( | ||
transceiver: RTCRtpTransceiver, | ||
kind: Track.Kind, | ||
videoCodec: VideoCodec, | ||
) { | ||
if (!('getCapabilities' in RTCRtpSender)) { | ||
return; | ||
} | ||
const cap = RTCRtpSender.getCapabilities(kind); | ||
if (!cap) return; | ||
log.debug('get capabilities', cap); | ||
const matched: RTCRtpCodecCapability[] = []; | ||
const partialMatched: RTCRtpCodecCapability[] = []; | ||
const unmatched: RTCRtpCodecCapability[] = []; | ||
cap.codecs.forEach((c) => { | ||
const codec = c.mimeType.toLowerCase(); | ||
if (codec === 'audio/opus') { | ||
matched.push(c); | ||
return; | ||
} | ||
const matchesVideoCodec = codec === `video/${videoCodec}`; | ||
if (!matchesVideoCodec) { | ||
unmatched.push(c); | ||
return; | ||
} | ||
// for h264 codecs that have sdpFmtpLine available, use only if the | ||
// profile-level-id is 42e01f for cross-browser compatibility | ||
if (videoCodec === 'h264') { | ||
if (c.sdpFmtpLine && c.sdpFmtpLine.includes('profile-level-id=42e01f')) { | ||
matched.push(c); | ||
} else { | ||
partialMatched.push(c); | ||
} | ||
return; | ||
} | ||
|
||
matched.push(c); | ||
}); | ||
|
||
if ('setCodecPreferences' in transceiver) { | ||
transceiver.setCodecPreferences(matched.concat(partialMatched, unmatched)); | ||
} | ||
} | ||
|
||
/** @internal */ | ||
publishedTracksInfo(): TrackPublishedResponse[] { | ||
const infos: TrackPublishedResponse[] = []; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch to our logger?