aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
748 stars 128 forks source link

React Native Support #84

Closed davidroeca closed 6 years ago

davidroeca commented 6 years ago

@aadsm this PR adds a "working" example with react-native.

I've been able to use the tag reader in my react-native app with the following manual steps:

  1. Install the package with build2/ as built.
  2. Within build2/, remove NodeFileReader.js and all references to NodeFileReader in jsmediatags.js.

This PR should be ready to merge once the following is handled or at least considered:

  1. Check the buffer dependency and consider if this is worth adding.
  2. Figure out conditional dependency resolution between node/react-native. I'm currently using optionalPeerDependencies and not sure if there is a better approach.
  3. Consider a way to share common code and distribute separate packages within this repo based on environment (e.g. jsmediatags, jsmediatags-node, jsmediatags-rn)--this approach probably handles 1 and 2; could consider webpack too.
  4. Figure out a good testing strategy and write a few tests.

See issue #82

aadsm commented 6 years ago

Thank you for this! I'll probably only be able to look into this on Saturday.

davidroeca commented 6 years ago

@aadsm thanks, no rush!

I figured out how to ignore specific modules for the react-native bundler by adding the following to package.json:

{
  ...
  "dependencies": {
    ...
  },
  "react-native": {
    "fs": false
  },
  ...
}

Completely undocumented, but found out that functionality on SO.

Also apparently checking that the global navigator is set, and checking that navigator.product === "ReactNative" is the way to check for react-native at runtime.

So the issues I've listed above should be non-issues and this should (hopefully) not break a browser or nodejs build.

Still need to look into testing though, at the very least a few mocks.

aadsm commented 6 years ago

I’m slightly concerned about the undocumented features. Let me ask the React Native team tomorrow to see what’s their advice.

davidroeca commented 6 years ago

Makes sense, looking forward to their input. I also realize that this worked well with my application ignoring the node_modules/jsmediatags/build2/NodeFileReader.js in .babelrc. With that line removed, the react-native bundler still fails.

Edit: Adding an additional line "./NodeFileReader.js": false fixes this. Isn't the most elegant though.

aadsm commented 6 years ago

hey! finally found some time to look into this.

davidroeca commented 6 years ago

@aadsm sorry for the late reply!

aadsm commented 6 years ago

Hi @davidroeca,

Sorry for the delay, I’ve been a bit back and forth with the RN team and yeah, they don’t recommend using undocumented features. However, your changes seem simple enough to understand or fix in the future if needed and I prefer to have this than no support at all for RN in the library.

Thank you so much for this!

aadsm commented 6 years ago

Would you be willing to write a blog post (or something) about using jsmediatags with React Native?