thor_
thor_

Reputation: 35

Checking if a device is connected to wifi or mobile data in a PWA

If the device is connected to wifi I want to send native quality audio, but if it's connected via mobile data I want to send it in a compressed format

If connected to wifi I'd make the client request .wav files, if connected to mobile data I'd make it request .mp3 files

I know applications such as Tidal are capable of detecting whether you're on wifi or using mobile data. Is something like this possible with a PWA or do you need lower level access?

Upvotes: 0

Views: 1307

Answers (1)

PeteLe
PeteLe

Reputation: 1943

The Network Information API will give you this information, but it's not available in all browsers, and it may be inaccurate. Some Wifi connections are slower than mobile (5G), or a Wifi connection may just be a tethered mobile connection.

Instead, I would recommend either giving the user a setting that they can choose, or making a fetch request and timing the result to see the speed and using that to determine your network bandwidth. If you do that though, remember, the user may change connections anywhere in the middle.

Upvotes: 1

Related Questions