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

Fix TypeError when calling unbindVideoElement #3043

Merged
merged 5 commits into from
Feb 25, 2025
Merged

Fix TypeError when calling unbindVideoElement #3043

merged 5 commits into from
Feb 25, 2025

Conversation

shi-su
Copy link
Contributor

@shi-su shi-su commented Feb 24, 2025

Issue #: #3042

Description of changes:
Fix TypeError when calling unbindVideoElement

Testing:
Smoke test and verified TypeError is not thrown when calling unbindVideoElement

Can these tested using a demo application? Please provide reproducible step-by-step instructions.

  1. Start a demo meeting with two attendee, start video from one attendee
  2. On the other attendee, open Console and search log line video tile updated and note tileId of the latest tile
  3. In the console this.app.audioVideo.unbindVideoElement(<tileId>)
  4. Verify there is no errors generated

Checklist:

  1. Have you successfully run npm run build:release locally?
    yes

  2. Do you add, modify, or delete public API definitions? If yes, has that been reviewed and approved?
    no

  3. Do you change the wire protocol, e.g. the request method? If yes, has that been reviewed and approved?
    no

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@shi-su shi-su requested a review from a team as a code owner February 24, 2025 19:15
hensmi-amazon
hensmi-amazon previously approved these changes Feb 24, 2025
monitor.bindVideoElement(null);
});

it('should skip unobserve if no element is being beserved', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

typo bserved

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

const videoElementFactory = new NoOpVideoElementFactory();
const videoElement = videoElementFactory.create();
monitor.bindVideoElement(videoElement);
monitor.bindVideoElement(null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need some expect statements for this test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The function is expected to handle these inputs. Added expect no exception to throw

const videoElementFactory = new NoOpVideoElementFactory();
const videoElement = videoElementFactory.create();
expect(() => monitor.bindVideoElement(videoElement)).to.not.throw();
expect(() => monitor.bindVideoElement(null)).to.not.throw();
Copy link
Collaborator

@ziyiz-amzn ziyiz-amzn Feb 24, 2025

Choose a reason for hiding this comment

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

I think it will good to expect this.resizeObserver.observe() and this.resizeObserver.unobserve() to havebeencalled(times) in both tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added boolean to represent if observe or unobserve is called in unit test and expect on them.

return;
}
this.element = newElement;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: if newElement is null, is it supposed to be observed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If newElement it will be handled inside the if (!newElement) section above call unobserve if it was observing an element

if (this.element) {
this.resizeObserver.unobserve(this.element);
}
this.element = newElement;
Copy link
Collaborator

Choose a reason for hiding this comment

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

explicit this.element = null should be good.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this change, makes it a bit easier to read

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed ResizeObserver can observe multiple elements. So I updated the function to unobserve the element being observed if not null, and then observe newElement if not null. Also added a function to skip when newElement equals to the one being observed

ziyiz-amzn
ziyiz-amzn previously approved these changes Feb 24, 2025
@shi-su shi-su merged commit 4fb9f47 into main Feb 25, 2025
11 checks passed
@shi-su shi-su deleted the unbind branch February 25, 2025 00:10
@shi-su shi-su mentioned this pull request Feb 27, 2025
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.

3 participants