happy-dom icon indicating copy to clipboard operation
happy-dom copied to clipboard

#475@minor: Adds support for HTMLMediaElement.

Open rudywaltz opened this issue 2 years ago • 4 comments

Resolves https://github.com/capricorn86/happy-dom/issues/484 Resolves https://github.com/capricorn86/happy-dom/issues/475

It's a very basic implementation mostly covering the API (at least what is common between audio and video and widely supported in browsers) timeRanges implementation coming from jsdom as the comment mentioned. I try to implement some basic logic but mostly is missing, I hope this can be good enough as a first step.

References: https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement https://html.spec.whatwg.org/#htmlmediaelement https://github.com/jsdom/jsdom

p.s.: should I need to add HTMLAudioElement and HTMLVideoELement to window.ts and index.ts or the changes is the packages/happy-dom/src/config/ElementTag.ts in enough for use?

rudywaltz avatar Jul 09 '22 21:07 rudywaltz

although those tags extend from HTMLMediaElement, I think we should implement for HTMLVideoElement and HTMLAudioElement before removing or adding these tags in ElementTag.ts.

Of course this is my personal advice, perhaps repo owner's advice is more valuable.

Mas0nShi avatar Jul 10 '22 04:07 Mas0nShi

Hi @Mas0nShi , thanks for the feedback. HTMLAudioElement has a same API as HTMLMediaElement, only mozzilla-specific API is a difference if I understand correctly the documentation. https://html.spec.whatwg.org/multipage/media.html#htmlaudioelement (maybe better doing this here as well? creating an audio element and that is just extending the Media element? 🤔 )

HTMLVideoElement has some widely supported properties/attributes that are not coming from HTMLMediaElement, so yes maybe better implement that as well before adding or removing it from the not implemented list, but still after this, most of the API working in the test. https://html.spec.whatwg.org/multipage/media.html#the-video-element

rudywaltz avatar Jul 10 '22 05:07 rudywaltz

(maybe better doing this here as well? creating an audio element and that is just extending the Media element? 🤔 )

yes, it's my advices, we can add HTMLMediaElement and HTMLVideoElement though identical or incomplete.

Mas0nShi avatar Jul 10 '22 05:07 Mas0nShi

(maybe better doing this here as well? creating an audio element and that is just extending the Media element? 🤔 )

yes, it's my advices, we can add HTMLMediaElement and HTMLVideoElement though identical or incomplete.

done

rudywaltz avatar Jul 10 '22 06:07 rudywaltz

Hi @rudywaltz and @Mas0nShi ! 🙂

Sorry for not looking into this earlier. It has been a lot going on in my private and work life.

I have managed to get the PR build to work and it seems like this PR is failing to build.

I can merge this when the build is successful.

capricorn86 avatar Oct 06 '22 09:10 capricorn86

Hi @Mas0nShi ! 🙂

Sorry for not looking into this earlier. It has been a lot going on in my private and work life.

I have managed to get the PR build to work and it seems like this PR is failing to build.

I can merge this when the build is successful.

capricorn86 avatar Oct 06 '22 09:10 capricorn86

Hi @capricorn86 , thank you for taking care of this repo. Can I ask some hint where is the missing part. I see the error locally as well

 src/window/Window.ts(256,18): error TS2416: Property 'self' in type 'Window' is not assignable to the same property in base type 'IWindow'.
  Type 'this' is not assignable to type 'IWindow'.
    Property 'HTMLAudioElement' is missing in type 'Window' but required in type 'IWindow'.

but I have no idea where is the missing part. I try to follow the DialogElement implementation and I don't find any place where the Audio is missing ):

rudywaltz avatar Oct 06 '22 20:10 rudywaltz

Hi @capricorn86 , thank you for taking care of this repo. Can I ask some hint where is the missing part. I see the error locally as well

 src/window/Window.ts(256,18): error TS2416: Property 'self' in type 'Window' is not assignable to the same property in base type 'IWindow'.
  Type 'this' is not assignable to type 'IWindow'.
    Property 'HTMLAudioElement' is missing in type 'Window' but required in type 'IWindow'.

but I have no idea where is the missing part. I try to follow the DialogElement implementation and I don't find any place where the Audio is missing ):

@rudywaltz I found the error. In Window.ts the property HTMLAudiolement should be renamed to HTMLAudioElement :slightly_smiling_face:

It's failing because the interface is using the name HTMLAudioElement and it doesn't follow the interface correctly.

capricorn86 avatar Oct 06 '22 22:10 capricorn86

It seems like we got a small merge conflict as well. When that and the property is fixed I will merge it :slightly_smiling_face:

capricorn86 avatar Oct 06 '22 22:10 capricorn86

With this last "config resolve commit" the history is not too nice, if you need I can try rebasing and creating a new PR with more flat commit history.

rudywaltz avatar Oct 07 '22 06:10 rudywaltz

@rudywaltz I made a squash 🙂

capricorn86 avatar Oct 07 '22 07:10 capricorn86