Page MenuHomePhabricator

Implement CommServicesAuthMetadataEmitter native event emitter on Android
ClosedPublic

Authored by marcin on Dec 14 2023, 4:58 AM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Nov 27, 4:34 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Unknown Object (File)
Thu, Nov 21, 4:30 AM
Subscribers

Details

Summary

This differential implements CommServicesAuthMetadataEmitter on Android in such a way that it callable from C++.

Test Plan
  1. Apply this patch: https://gist.github.com/marcinwasowicz/7f04bd592dd4a800adbc96b720e200b7. It creates js code to subscribe for auth metadata events and sends this event from C++ upon each draft update (contents of the event are just dummy strings).
  2. Build Android app.
  3. Ensure that each time you write one letter you can see console.log with dummy auth metadata in native yarn dev terminal.

Diff Detail

Repository
rCOMM Comm
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

Rebase to update commit message

Same as for iOS diff:

React native requires that event emitter is an instance of a class. On the other hand in order to smoothly call this object from Rust we need static method. Therefore I decided to use Singleton pattern for Rust <-> C++ interop. Object that is available to for C++ and Rust is set when the first JS listener subscribes and is removed when the last listener unsubscribes. This way we ensure that Rust/C++ won't try to send event if value under sharedInstance might be invalid. All calls that access or mutate sharedInstance are synchronized on class level.

For this differential important files are: CommServicesAuthMetadataEmitter.cpp and CommServicesAuthMetadataEmitter.java. Other files are pure boilerplate necessary to expose module to JS.

Reviewers can quickly and easily familiarise themselves with event emitter implementation on Android by reading the docs: https://reactnative.dev/docs/native-modules-android#sending-events-to-javascript

Harbormaster returned this revision to the author for changes because remote builds failed.Dec 14 2023, 7:19 AM
Harbormaster failed remote builds in B25073: Diff 34638!

Use commServicesAccessToken instead of accessToken to match JS-types.

This revision is now accepted and ready to land.Dec 15 2023, 2:57 AM
  1. Refactor to remove deviceID emission.
  2. Rebase before landing.