feross/yt-player

don't clobber an existing onYouTubeIframeAPIReady callback

mreinstein opened this issue · 5 comments

@feross great module! Love the simplicity of it.

The only issue I see right now is related to my particular use case: My code runs as a 3rd party library in someone else's website. It's possible that the hosting site already has a onYouTubeIframeAPIReady function declared. Would you be open to a PR which does something like this?

if (typeof window.onYouTubeIframeAPIReady !== 'function') {
      window.onYouTubeIframeAPIReady = () => {
        while (loadIframeAPICallbacks.length) {
          const loadCb = loadIframeAPICallbacks.shift()
          loadCb(null, window.YT)
        }
   }
} else {
   const previous = window.onYouTubeIframeAPIReady
   window.onYouTubeIframeAPIReady = () => {
     if (previous) {
        previous()
     }
     loadCb(null, window.YT)
   }
}

@mreinstein Sorry for the delay here! Yes, I'd happily accept a PR that supports your use case.

Was this ever implemented?

I have code that accomplishes this (similar to the snippet I pasted in the issue description) but. I don't think I ever got around to sending a PR for this

@feross let me know if you have any issues etc., happy to modify the PR as needed.

This was released in 3.5.0