Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99

Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1169

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176

Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 1176
8000 core, avm2, web: Implement Geolocation by michaelwright235 · Pull Request #13077 · ruffle-rs/ruffle · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content

Conversation

michaelwright235
Copy link

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:

  1. Geolocation related events. All of the implemented AS classes are AS3.
  • flash.events.PermissionEvent (when users choices whether to grant permission or not) and flash.permissions.PermissionStatus that contains related constants.
  • flash.events.GeolocationEvent that is sent when the device's geolocation changes.
  1. flash.sensors.Geolocation itself. One uses it to set up geolocation stuff in their scripts.
  2. New geolocation backend. We need a separate backend to handle geolocation requests. NullGeolocationBackend is also included, it tells that device doesn't have a geo sensor.
  3. Implementation of geolocation backend for web.

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:

  • Make GeolocationInstances struct accept multiple instances of Geolocation class. Currently only the last created one will receive events. I didn't quite figure out how to deal with garbage collection stuff, so this struct needs to be rewritten.

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.
@n0samu
Copy link
Member
n0samu commented Sep 5, 2023

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?

@michaelwright235
Copy link
Author

It was just my project in my spare time. I've looked at the Ruffle features matrix and decided to implement this functionality.
Existing AIR apps for Android and iPhone become obsolete as well. For instance installing old android AIR app may simply fail because one could only produce only arm-v7 apks (arm-v8 was added only long after AIR was bought by Harman), some phones now don't them anymore. Running an app produced with AIR 2-ish will certainly fail on newer Android versions (checked it myself). iOS is even worse if we talk about API compatibility. In my opinion, supporting AIR apps will help preserving those kind of apps, plus extracting the inner swf from them is super easy.
Hmm, I didn't think of using ExternalInterface.

@adrian17
Copy link
Collaborator
adrian17 commented Sep 5, 2023

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 [API("668")]) in the .SWC files.
Further, we can't "just" make them accessible to normal SWFs (all the privacy, permissions and "why Adobe didn't want this API on web in the first place" questions aside), because some AS3 libraries check for API presence as a sort of feature detection, and us pretending to be AIR can break content that wasn't intended to be embedded in non-AIR contexts. Similarly (not applicable here, just a trivia), adding AIR-only fields or methods to classes can also affect class inheritance validation for non-AIR content.

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.

@adrian17
Copy link
Collaborator
adrian17 commented Sep 5, 2023

unless somehow an explicit switch "pretend to be an AIR player" is switched.

(we didn't decide on any specifics here btw. The prerequisite for the hiding mechanism is #12967 .)

@Lord-McSweeney
Copy link
Collaborator

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 --air), which would probably only be available on desktop Ruffle.

@Aaron1011
Copy link
Member

What would prevent air on web?

@n0samu
Copy link
Member
n0samu commented Sep 6, 2023

We subsequently agreed that an air configuration option, if implemented, should be available on both desktop and web.

@Dinnerbone
Copy link
Contributor

With #14159 and #14166 we are now bringing in AIR support!

@Aaron1011
Copy link
Member

Ruffle now has AIR support, which can be used to make these classes visible under AIR only

@danielhjacobs danielhjacobs added the waiting-on-author Waiting on the PR author to make the requested changes label Mar 5, 2024
@danielhjacobs danielhjacobs added A-avm2 Area: AVM2 (ActionScript 3) A-web Area: Web & Extensions T-compat Type: Compatibility with Flash Player labels Sep 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-avm2 Area: AVM2 (ActionScript 3) A-web Area: Web & Extensions air Adobe AIR T-compat Type: Compatibility with Flash Player waiting-on-author Waiting on the PR author to make the requested changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

0