mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.
https://pannellum.org/
MIT License
4.16k stars 712 forks source link

Add support for Sensor APIs #971

Open mpetroff opened 3 years ago

mpetroff commented 3 years ago

Browsers no longer allow DeviceMotionEvent / DeviceOrientationEvent access from a cross-origin <iframe>, so device orientation control can no longer be used in this situation. Implement support for the newer Sensor APIs, which allow for permissions to be specified on the <iframe>, to fix this.

strarsis commented 2 years ago

Could this be used as a server-side workaround? https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Feature-Policy/gyroscope

mpetroff commented 2 years ago

No, that header is only for the Sensor APIs. It just provides an alternative (that only works with Chrome) to specifying the permission on the <iframe>.

VivekBhimani commented 2 years ago

No, that header is only for the Sensor APIs. It just provides an alternative (that only works with Chrome) to specifying the permission on the <iframe>.

Only the gyro button requires SSL.

ludwigseibt commented 1 year ago

Hey, thanks for your work on Pannellum!

Is support for deviceorientation now entirely deprecated? Not only when using the standalone iframe but also when using the javascript API it seems to not work anymore.

Firefox on Android gives a warning, but still works: "Use of the orientation sensor is deprecated.".

Chrome on Android does not work and throws an error: Uncaught ReferenceError: DeviceMotionEvent is not defined at Ra (pannellum.js:85:483) Same goes for Safari and Chrome on Ipad.

Edit: Looks like Chrome on Android just needed a deployed website with https and doesnt work locally. On Ipad it still fails though.

ludwigseibt commented 1 year ago

I can see that there have been a number of fixes related to orientation that are not in the latest release yet. I will try this with the newest master version.

mpetroff commented 1 year ago

All browsers require HTTPS for any sort of sensor input these days. As for iPads, there's some discussion about this in #1093 and a fix in the master branch. Essentially, I don't know of any way to check for device orientation support without resorting to a user-agent check, and the iPad and macOS versions of Safari report the same user agent; I worked around this by assuming a Mac user agent to by an iPad if it has touch input support.

ludwigseibt commented 1 year ago

Thanks for the clarification. I got it to work by not letting the panoramas autoload. I feel like it would be helpful to mention in the documentation that when both autoload and orientationonbydefault are enabled it wont work on iPad as the permission for the sensor cant be requested.

mpetroff commented 1 year ago

@ludwigseibt That's a good suggestion. I just added a note about it in 73b6d162383bdba829bd00fee6283b425382e5aa (and it isn't limited to just the iPad).