#how integrate Video

16 messages ยท Page 1 of 1 (latest)

severe marsh
#

<script src="https://fast.wistia.com/player.js" async></script><script src="https://fast.wistia.com/embed/ajtj2xpipw.js" async type="module"></script><style>wistia-player[media-id='ajtj2xpipw']:not(:defined) { background: center / contain no-repeat url('https://fast.wistia.com/embed/medias/ajtj2xpipw/swatch'); display: block; filter: blur(5px); padding-top:56.25%; }</style> <wistia-player media-id="ajtj2xpipw" wistia-popover="true"></wistia-player>

How integrate this video script on qwik best way ???

severe marsh
#

import {
  component$,
  useStyles$,
  useVisibleTask$,
  useSignal,
  $,
} from '@builder.io/qwik'
import styles from './video.css?inline'
import {wrapper} from './container.css'
export default component$(() => {

  const open = useSignal<boolean>(false)

  useVisibleTask$(() => {
    if (!document.querySelector('script[src*="wistia.com/player.js"]')) {
      const script = document.createElement('script')
      script.src = 'https://fast.wistia.com/player.js'
      script.async = true
      document.head.appendChild(script)
    }
  })

  useStyles$(styles)
  const toggleOpen = $(() => {
    open.value = true
  })

  return (
    <div
      onClick$={toggleOpen}
      class={open.value ? wrapper.open : wrapper.closed}>
      {open.value && <wistia-player media-id="ajtj2xpipw" />}
    </div>
  )
})

Do you have better idea ?

unique spindle
#

Hmm, their docs say that you should use the E-v1 script https://docs.wistia.com/docs/all-about-e-v1

Anyway, you can check for typeof Wistia !== 'undefined'

Also, this won't work on SSR. Your player could be as simple as

import { component$ } from '@builder.io/qwik';

export default component$(() => {
  return <div>
    <script async src="https://fast.wistia.com/assets/external/E-v1.js" />
    <wistia-player media-id="ajtj2xpipw" />
  </div>;
});
Wistia

If you've used Wistia embeds, read our Help Center, or worked with our Champs, you might've heard the name "E-v1" or "E-v1.js". What is this mystery script, and why is it so important? Read on as we pull back the curtain on the Wistia JavaScript Library.

#

Don't worry about having the script tag multiple times, it will only download it once and the overhead is minimal

#

also, I'd just hide the player instead of not rendering it. That way it will be fast when opened.

oh and you really don't have to put toggleOpen in a separate variable, just onClick$={() => open.value = true} is fine

#
Qwik

No hydration, auto lazy-loading, edge-optimized, and fun ๐ŸŽ‰!

#

(@severe marsh )

severe marsh
#

It's just that I wanted to trick lighthouse and load js only when clicking or hovering the div

unique spindle
severe marsh
unique spindle
severe marsh
#

great didn't see

#

Whiy not using useRessource ?

#

to fetch the link ?