react-native-google-cast / react-native-google-cast

React Native wrapper for the Google Cast SDK
https://react-native-google-cast.github.io
MIT License
659 stars 254 forks source link

Devices lost after backgrounding app + double devices (Android) #547

Open jim-lub opened 1 month ago

jim-lub commented 1 month ago

Describe the bug

  1. CastButton, useDevices or discoveryManager.getDevices always show/return each device twice.
  2. After backgrounding the app, and then foregrounding it, all devices are lost when using useDevices or discoveryManager.getDevices. a. CastButton has no problem showing the devices and connecting to them after backgrounding the app. b. useDevices still shows the old devices, but they are not connectable. After hot reloading the app, the devices are lost. c. discoveryManager.getDevices returns an empty array of devices.

To Reproduce I have created a very minimal example to reproduce the issue. All issues are present in the example on the main screen (code available in app/(tabs)/index.tsx). All examples presented show double devices on app start, but only the useDevices and discoveryManager.getDevices issues (where no devices are found) are present after backgrounding the app once.

  1. CastButton is used to show the devices and connect to them.
  2. useDevices is used to show the devices and sessionManager is used to connect to them.
  3. discoveryManager.getDevices is used to fetch the devices.

repo: https://github.com/jim-lub/experimental-googlecast

Expected behavior I expect each device to be shown only once and to be discoverable and connectable after backgrounding the app.

Device:

Checklist:

petrbela commented 1 month ago

Thanks for the detailed write-up. I'm not sure when I'll have time to investigate as I'm on holiday. Maybe towards the end of the month. If you manage to fix the issue please create a pull request :)

pierrelouergagnon commented 1 month ago

I had the same issue. @jim-lub in your android/build.gradle change the castFrameworkVersion from + to 21.1.0. The later versions are not working properly with RNGC for know.

jim-lub commented 1 month ago

@petrbela No worries at all, enjoy your holiday! Unfortunately, we're unable to dedicate more time to investigating the issue or working on a fix at the moment.

@pierrelouergagnon Thank you so much for the suggested fix. Pinning the version does indeed seem to resolve the issues we've been experiencing.

jim-lub commented 1 month ago

After pinning the version we still encountered one of the issues mentioned, where no cast devices are visible after backgrounding and foregrounding the app. This occurred specifically on a Samsung Galaxy S20 FE and a Samsung Galaxy S24. Interestingly, the issue seems to be resolved on all our non-Samsung devices.

@pierrelouergagnon Do you recognize this issue or have any thoughts on what might be causing it? Any further suggestions would be greatly appreciated!