react-native-youtube-iframe icon indicating copy to clipboard operation
react-native-youtube-iframe copied to clipboard

Moving forward + better web support

Open sreuter opened this issue 10 months ago • 5 comments

Describe the bug The current state of YouTube embedding across ReactNative iOS, Android & Web is pretty sad. Either libraries have bad quality, are incomplete, or are simply not maintained anymore. Of all the ones we checked out, this one is the most promising. Unfortunately, it also doesn't seem to get a lot of love these days anymore tho. And while web support is generally there, non of the external controls or events work. Let's change that!

To Reproduce Steps to reproduce the behavior:

Do some research on all available YouTube embedding libraries + their activity (commits/open issues & replies) .. It's not great.

Expected behavior

As a first proposal, we'd like to suggest removing the dependency on injectJavascript. This, in return, will make this library work for both, native and web.

To give you a first idea, here's a WIP commit: https://github.com/questmate/react-native-youtube-iframe/commit/39074a8029e3e6e12797a22969ac99ce46e4746c

This, combined with the following part changed/added to the iframe.html made things work fine in our limited testing so far.

function sendMessageToRN(msg) {
  (window.ReactNativeWebView || window.parent).postMessage(
    JSON.stringify(msg),
    "http://localhost:19006"
  );
}
window.addEventListener("message", (message) => {
  console.log("Received Message in iFrame", message);
  const { eventType, data } = JSON.parse(message.data);
  console.log("Received Message in iFrame parsed:", eventType, data);
  switch (eventType) {
    case "getVideoUrl":
      sendMessageToRN({
        eventType: "getVideoUrl",
        data: player.getVideoUrl(),
      });
      break;
  }
});

@LonelyCpp Any thoughts on this? Maybe there was a good reason for not simply relying on postMessage & onMessage and instead working with injectJavascript? Also, do you have any interest in work resuming on the library, or would you instead recommend forking it or starting from scratch?

Screenshots N/A

Smartphone (please complete the following information): N/A

Additional context N/A

sreuter avatar Aug 02 '23 13:08 sreuter

Heya @sreuter, I'd love to help :)

post messages as an alternate to injectJs sounds fine on initial impressions.

LonelyCpp avatar Aug 02 '23 16:08 LonelyCpp

Awesome, we'll push a bit further on this then and hopefully have a first PR up and ready soon :)

sreuter avatar Aug 02 '23 17:08 sreuter

@sreuter @LonelyCpp how is the situation on this? I'd like to contribute, for example adding progress event

giona69 avatar Sep 11 '23 13:09 giona69

@LonelyCpp @sreuter any update about this?

bhyoo99 avatar Feb 15 '24 06:02 bhyoo99

@sreuter @LonelyCpp how can we help you on this challenge? im need this feature too. I have an app working in all platforms, but in web this lib not work.

junioroga avatar Feb 22 '24 14:02 junioroga

Consider using react-youtube for web, it seems it provides similar functionality, but works on Web with all bells and whistles. Even the interface is very similar.

kirill-konshin avatar May 17 '24 01:05 kirill-konshin