-
-
Notifications
You must be signed in to change notification settings - Fork 538
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
base: master
Are you sure you want to change the base?
Fix piped.ts (connector) #4691
Conversation
Fixed piped connector by ditching querySelector, which often returned null. Util.getAttrFromSelectors is now used instead
Sorry for the double quotes
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.
Thanks for the contribution!
Looks like there are some linting issues with this change though :/
Added missing semicolons
last edit for this pr I hope
Hopefully fixed linting problem
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; |
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.
Would using the ?.
operator be a more concice way of expressing this work?
Connector.getCurrentTime = () => (document.querySelector('.shaka-video') as HTMLVideoElement)?.currentTime;
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.
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
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.
I think we can handle undefined as per the base implementation.
public getCurrentTime: () => number | null | undefined;
But also happy to leave it as is 👍
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.
Looks like there is one linting issue to fix which prettier . --check
should show.
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.
I'd really like to fix it but I have no clue on how to do that...
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.
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); |
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.
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); |
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.
const videoEl = (document.querySelector('.shaka-video') as HTMLVideoElement); | |
const videoEl = document.querySelector('.shaka-video') as HTMLVideoElement; |
Fixed piped connector
by ditching querySelector, which often returned null. Util.getAttrFromSelectors is now used insteadUPDATE: 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)