-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added web support #68
base: master
Are you sure you want to change the base?
Conversation
Any feedback here? |
Hi @mwoelk! Sorry I've not responded to this yet, that looks like a good start but I think there's a few things that should be done before inclusion in the plugin.
If you're able to take one or both of those tasks on that'd be wonderful, otherwise I can try to get to it but it probably won't be for at least a week or two. |
Hey @rmtmckenzie,
Testing with https://sensor-js.xyz/demo.html shows that using DeviceMotionEvent.accelerationIncludingGravity seems to be available on most devices BUT signs between chrome and safari seem to vary but might be fixed with some device checking. |
Awesome, thanks for that, that looks great, although what you did wasn't working on my (admittedly very old although running 15.8) iphone due to it not supporting window.screen.orientation 🙄 . I pushed a fix for that that falls back to the deprecated window.orientation. Is the DeviceOrientationEvent coming through on https://sensor-js.xyz/demo.html on your redmi phone? I'm wondering if maybe you weren't seeing it using your code because it's not running over https. I've run it through an https tunnel and it seems to be working on my pixel3a, pixel6a, and samsung tablet as well as the iphone now. I think in the case where the sensor data isn't available I would prefer an outright error to be thrown rather than falling back to the window orientation and for the error to be documented as well as handled in the OrientationReader (it could do the falling-back to a non-sensor orientation there but it would still allow people who explicitly need the sensor orientation to be notified that it isn't possible using the more direct API). Also, if it's just the case of the That's all my time for today but I'll try to take a look at this again in the next couple days; if you're able to confirm what's going on with your phone and possibly do those changes to the fallback + debugprint then I'll get it all committed and if not I'll try to do the fallback changes then. |
Hey @rmtmckenzie, Sadly on my redmi, the DeviceOrientationEvent is available in chrome but when listening to it it gets fired only once with alpha, beta and gamma being null. Following the specs a device should null the values it can't provide. Same result for me on https://sensor-js.xyz/demo.html. And I ran everything over https (built for web in release and debug and just uploaded to my server). On my iPhone everything works fine and even using the Sensor in the Chrome DevTools on desktop worked well. Funny. I initially had put in some debugPrints but wasn't sure how you would handle logging/debugging and removed it afterwards. I guess a way to provide feedback (e.g. sensor not available / permission on iOS not given / non-https context would be great). Regarding the fallback I guess it makes sense to wrap them in custom errors (could be re-used across platforms e.g. SensorNotAvailableException, SensorPermissionNotGrantedException, etc.) and throw these into the stream to be handled in the reader. Regarding the reader I would add a default-false boolean property For those interested in handling errors themselves, I see three options:
What do you think? In my opinion it could be beneficial to have all three :) |
I've been busy moving the last while, sorry about that. That's annoying re: the redmi but I guess it is what it is. Strange that it can't provide the event, I'm quite sure that the device itself would have an accelerometer but I guess if the driver doesn't expose the standard API for chrome to consume that could explain it. I think for I think for the reader the I would actually recommend making Hmm. Actually, now that sealed classes exist, that might be a good way to do it too although it would entail a breaking change. But it would make the API better as it would be possible to have this:
What do you think about that? It'd be a cleaner way to handle errors on the native side too tbh. I'd be willing to a version bump & API change if we did that as well as the sensor-parameter enum change. |
Added support for flutter web.
Currently when using this plugin directly on web it just crashes. Instead of checking for web use I thought it would be better to open a PR and make this plugin compatible with web as well:
Logic based on https://developer.mozilla.org/en-US/docs/Web/API/Screen/orientation
See also: https://caniuse.com/screen-orientation
If browser support is not given, then we fall back to the provided
defaultOrientation
.Looking forward to your feedback/suggestions.