Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
303 views
in Technique[技术] by (71.8m points)

android - 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?

question from:https://stackoverflow.com/questions/65844016/checking-if-a-device-is-connected-to-wifi-or-mobile-data-in-a-pwa

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...