-
-
Notifications
You must be signed in to change notification settings - Fork 924
core, avm2, web: Implement Geolocation #13077
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
base: master
Are you sure you want to change the base?
Conversation
PermissionEvent gets sent when user grants or denies permissions to various things (geolocation, camera, etc.). Originally it's only used in AIR mobile apps. This class was generated with ActionScript Event Builder script.
This class is closely related to PermissionEvent and contains only neccesary constants.
It gets sent when the device receives updates from the location sensor installed on the device. This class was generated with ActionScript Event Builder and then modified to add necessery functionality. When the class is created we need to check the incoming values. According to Flash's docs only `altitude` and `heading` fields might be NaN. If the other fields are NaN we simply make them 0.
This class is responsible of dispatching events in response to the device's location sensor. It was generated with ActionScript Event Builder and then modified. Private `init` method is called when a new instance of the class is created. We need to store those objects in a separete place to dispatch events on all of them. Other public native methods connects backend and frontend basically. Some methods are stubbed currently.
We need to create a separate backend to handle geolocation requests. `NullGeolocationBackend` struct always says that the geolocation sensor is not present on the device. `GeolocationInstances` struct is used to store Geolocation class object from AS since we need to send event to all of them. Currently it can store only one instance.
Adds GeolocationBackend and GeolocationInstances to Player struct and UpdateContext. Also adds geolocation_instances to GcRoot since it manipulates AS objects.
These funcs talks to the backend.
Handle GeolocationPermissionChange and GeolocationUpdate events from the platform's backend
Last implementetion led to panic when updating interval after a class gets created
We actually don't need to implement this function because we ask permission right when a Geolocation class is created. Previously the browser could throw several permission prompts.
Thanks so much for contributing! However, I see Ruffle's main function as bringing Flash web games back to the web. Why should we support an AIR API on the web that Flash Player never supported? Are you working with some company that is trying to port their AIR app to the web or something like that? What about calling the browser's geolocation APIs via ExternalInterface? |
It was just my project in my spare time. I've looked at the Ruffle features matrix and decided to implement this functionality. |
Indeed, it's a fact that all of these APIs are AIR-only, and inaccessible for the normal Flash Player. The SDK (and player, though I think they are usually just not compiled into the player at all) hides them via version metadata (like Our current consensus (quickly discussed on Discord moments ago :) ) is that if we do merge this, this will need to be disabled by default and inaccessible (via namespace versioning mechanisms) to SWFs unless somehow an explicit switch "pretend to be an AIR player" is switched. This is because AFAIK we can't easily distinguish an AIR swf from a non-AIR swf. |
(we didn't decide on any specifics here btw. The prerequisite for the hiding mechanism is #12967 .) |
I agree, this should only be available on AIR (which means the web backend should be unnecessary). If we ever do implement AIR APIs, it will likely be gated behind a flag (like lightspark's |
What would prevent air on web? |
We subsequently agreed that an |
Ruffle now has AIR support, which can be used to make these classes visible under AIR only |
I'm excited to contribute to this amazing project! So I decided to implement Geolocation logic that is used by some mobile AIR games and apps. It's not present on desktop Flash Player.
This pull request consists of these parts:
flash.events.PermissionEvent
(when users choices whether to grant permission or not) andflash.permissions.PermissionStatus
that contains related constants.flash.events.GeolocationEvent
that is sent when the device's geolocation changes.flash.sensors.Geolocation
itself. One uses it to set up geolocation stuff in their scripts.Brief explanation
Once a Geolocation class is created we immediately add it to GeolocationInstances struct. It should contain all class instances to dispatch events on all of them. Then the frontend is requested with a permission. When user choose a variant, a PermissionEvent and StatusEvent get sent to geo classes. If a permission is granted, we then start sending GeolocationEvents with the requested interval.
Requesting permission problem
Geolocation class was firstly introduced in AIR 2.5. Firstly it didn't require requesting user permission for geolocation use, since mobile devices back than didn't really care about privacy. That's why most of code examples on the web just add a listener for a geolocation update. If we try this on a modern Android device, we'll see that it doesn't work and it gets stuck waiting forever. Some versions of AIR even throw an error. So to address this issue I decided to request a permission every time a class gets created. Plus all modern browsers and OSs require user permission anyway. It makes my implementation compatible with old and new as3 code.
Resources:
Current state:
At this moment the web implementation works great. I made a simple test swf projects to test this out.
Current todo list: