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

ref(SDPDiffer) Convert to ES6 class. #2577

Merged
merged 7 commits into from
Oct 22, 2024
Merged

ref(SDPDiffer) Convert to ES6 class. #2577

merged 7 commits into from
Oct 22, 2024

Conversation

jallamsetty1
Copy link
Member

@jallamsetty1 jallamsetty1 commented Sep 25, 2024

Make it work directly with unified-plan SDP and add more unit tests.

Please look at the individual commits.

Make it work directly with unified plan SDP that has multiple m-lines and add more unit tests.
Without having to run it through the SDPInterop.toPlanB cycle.
Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments! 😮‍💨

*
* @type {Map<string, TPCSSRCInfo>}
*/
this._ssrcMap = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename this to localSsrcMap ?

|| typeof desc.sdp !== 'string') {
logger.warn('An empty description was passed as an argument');

if (!localSDP || typeof localSDP !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an error? Should a warning be logged?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This technically wouldn't happen since the browser will always produce an SDP for createOffer/createAnswer. The call itself will fail and user kicked out when that happens so I thought it's ok not to display the error here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, let's throw an exception, as if it was an assertion. If the invariant is ever broken, better do it as loud as possible.

modules/RTC/TraceablePeerConnection.js Show resolved Hide resolved
modules/RTC/TraceablePeerConnection.js Show resolved Hide resolved
groupsMap.set(primarySSRC, []);
}
groupsMap.get(primarySSRC).push(group);
if (Array.isArray(ssrcGroups)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check ssrcs with if (ssrcs?.length) { but here we do it differently. I feel we should check consistently since they are both arrays.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An artifact of c+p of the old code, fixed it.

modules/sdp/SDP.js Show resolved Hide resolved
modules/sdp/SDP.js Show resolved Hide resolved

ssrcGroupLines.forEach(line => {
const idx = line.indexOf(' ');
const semantics = line.substr(0, idx).substr(13);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do these 13 and 14 numbers come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

length of 'a=ssrc-group:'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was a better way...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a helper function in SDPUtil for this.

// recurse into the nested arrays
if (!array1[i].equals(array2[i])) {
return false;
if (othersSsrcs.length && !isEqual([ ...mySsrcs ].sort(), [ ...othersSsrcs ].sort())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do Object.keys(mySource.ssrcs).sort() so you don't need to create a copy.

modules/xmpp/JingleSessionPC.js Show resolved Hide resolved
Remove LOCAL_TRACK_SSRC_UPDATED event as the application ignores the event and no additional action needs to be taken when that event is fired.
Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor comments, almost there! Great work Jaya!

|| typeof desc.sdp !== 'string') {
logger.warn('An empty description was passed as an argument');

if (!localSDP || typeof localSDP !== 'string') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, let's throw an exception, as if it was an assertion. If the invariant is ever broken, better do it as loud as possible.

modules/RTC/TraceablePeerConnection.js Show resolved Hide resolved
modules/sdp/LocalSdpMunger.js Show resolved Hide resolved

if (ssrcMap.size) {
for (const [ id, trackSsrcs ] of ssrcMap.entries()) {
if (isEqual([ ...sources ].sort(), [ ...trackSsrcs.ssrcs ].sort())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. In that case it might be better to have a const sortedSources = sources.slice().sort(); to avoid a copy on each loop iteration, which would be a bunch of them in case of many participants, no?

modules/sdp/SDP.js Show resolved Hide resolved
modules/sdp/SDP.js Show resolved Hide resolved

ssrcGroupLines.forEach(line => {
const idx = line.indexOf(' ');
const semantics = line.substr(0, idx).substr(13);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was a better way...

modules/xmpp/JingleSessionPC.js Show resolved Hide resolved

if (ssrcMap.size) {
for (const [ id, trackSsrcs ] of ssrcMap.entries()) {
const sortedSources = sources.slice().sort();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this outside of the loop since it doesn't change within.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

@saghul saghul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥🔥🔥

@jallamsetty1 jallamsetty1 merged commit a7476b1 into master Oct 22, 2024
2 checks passed
@jallamsetty1 jallamsetty1 deleted the ref-sdp branch October 22, 2024 16:37
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

Successfully merging this pull request may close these issues.

2 participants