daily-co / daily-js

https://docs.daily.co/reference/daily-js
BSD 2-Clause "Simplified" License
103 stars 33 forks source link

[FEATURE-REQUEST] pattern for enabling same code across react-native and web? #217

Closed chr4ss12 closed 11 months ago

chr4ss12 commented 1 year ago

It is unclear to me at this point if it is possible to use only one library (@daily-co/daily-js) and use the same code for both platforms (react-native and react);

I am going to say no, as otherwise there would be no point in @daily-co/react-native-daily-js library,

my other question is, are you guys going to try and keep the interfaces/API of both libraries the same? I am thinking of creating a shared library that can be both used by the web(react) and mobile app(react-native), essentially my plan is to take the code for this:

https://github.com/daily-demos/party-line/blob/main/react/src/CallProvider.jsx

and turn it into library.

If react-native includes the library, it will have to override @daily-co/daily-js with the react native version, as such:

"overrides": {
  "dependency": {
    "@daily-co/daily-js": "npm:@daily-co/react-native-daily-js"
  }
}

I've got no idea if this is any good idea, but essentially this would cut down my development / maintenance time half

filipi87 commented 1 year ago

Hi @chr4ss12 ,

react-native-daily-js is just a wrapper for daily-js, as you can see in our source code available at: https://github.com/daily-co/react-native-daily-js

When you import react-native-daily-js, in addition to all the code provided by daily-js, we offer some additional features specifically for React Native. For example, we provide the same WebRTC API that is normally available by default in web browsers. Additionally, we include other methods necessary for managing audio devices.

Since react-native-daily-js is essentially a wrapper for daily-js, the interfaces and APIs remain the same for both libraries. However, in some cases, we override the types provided by daily-js and only include in the TypeScript definition those methods and events that are also supported by React Native.

Considering this, I recommend using react-native-daily-js as a dependency in your React Native projects and daily-js in your web projects.

mattieruth commented 11 months ago

I believe this is resolved. Feel free to re-open if otherwise.