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 piped.ts (connector) #4691

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

Tamarindo94
Copy link

@Tamarindo94 Tamarindo94 commented May 8, 2024

Fixed piped connector by ditching querySelector, which often returned null. Util.getAttrFromSelectors is now used instead

UPDATE: Util.getAttrFromSelectors wasn't the correct solution - querySelector is still used, but now the connector avoids trying to access properties on null objects that are querySelected before the video is added to the DOM (which was the reason for the connector crashing)

Fixed piped connector by ditching querySelector, which often returned null. Util.getAttrFromSelectors is now used instead
@inverse inverse added patch-change For patch changes fixed-connector for PRs that fix a connector labels May 8, 2024
Sorry for the double quotes
Copy link
Member

@inverse inverse left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution!

Looks like there are some linting issues with this change though :/

@Tamarindo94
Copy link
Author

Hope it's ok now

(document.querySelector('.shaka-video') as HTMLVideoElement).duration;
Connector.getCurrentTime = () => {
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement);
return videoEl ? videoEl.currentTime : null;
Copy link
Member

Choose a reason for hiding this comment

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

Would using the ?. operator be a more concice way of expressing this work?

Connector.getCurrentTime = () => (document.querySelector('.shaka-video') as HTMLVideoElement)?.currentTime;

Copy link
Author

Choose a reason for hiding this comment

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

It should be, yes. I wasn't sure whether the ?. operator was discouraged by the project guidelines so I opted for the more verbose version. The only difference is that, with the ?. operator, undefined will be returned if querySelector doesn't find the element, while the verbose version explicitly returns null in such case, and I don't know if that makes a difference to the core. If it doesn't, they should be functionally equivalent

Copy link
Member

Choose a reason for hiding this comment

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

I think we can handle undefined as per the base implementation.

public getCurrentTime: () => number | null | undefined;

But also happy to leave it as is 👍

Copy link
Member

@inverse inverse May 20, 2024

Choose a reason for hiding this comment

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

Looks like there is one linting issue to fix which prettier . --check should show.

Copy link
Author

Choose a reason for hiding this comment

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

I'd really like to fix it but I have no clue on how to do that...

Copy link
Member

Choose a reason for hiding this comment

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

If you run npx prettier . --write it should fix the issues automatically

Connector.getCurrentTime = () =>
(document.querySelector('.shaka-video') as HTMLVideoElement).currentTime;
Connector.getCurrentTime = () => {
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement);
const videoEl = document.querySelector('.shaka-video') as HTMLVideoElement;

Connector.getDuration = () =>
(document.querySelector('.shaka-video') as HTMLVideoElement).duration;
Connector.getDuration = () => {
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement);
const videoEl = document.querySelector('.shaka-video') as HTMLVideoElement;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-connector for PRs that fix a connector patch-change For patch changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants