Skip to content

Conversation

@mattadatta
Copy link

@RocketChat/ReactNative

New feature request + potential implementation: DDP-based websocket push notifications on Android.

A use-case I have for the Rocket.Chat React Native client (specifically on Android for now) is using a private Rocket.Chat server on a WAN-access-restricted network (thus cutting off communication with Google's FCM servers). It would be nice to be able to get push notifications while in this kind of environment, while doing our best to adhere to Android's background scheduling limitations.

This PR contains a potential implementation of that feature, with tests on-device working well, but I'd like input from the community on how it should be best implemented.

To complete this feature, I took the following steps:

  1. Took the Android DDP websocket code contained within the original Rocket.Chat Android client and migrated it to the React Native client.
  2. Created a JobService in Android that inspects the SharedPreferences object the JS uses to log in to establish a DDP connection to the server, subscribing to various endpoints to be notified of various room messages
  3. The JobService stores the websocket connection within the application process, periodically checking to make sure the socket connection is still alive (as well as providing BroadcastReceivers that listen for particular events to fire the service up again)
  4. Constructs new notifications based on data received from the websocket, supplying the necessary data so that the notification can also open the app

Additionally, I have modified a bit of the JS source to enable / disable this websocket push notification service manually in the settings panel.

I would definitely appreciate some feedback from the community about any caveats/pitfalls when trying to reimplement this feature in this manner. I'm sure there are some things I'm missing in regards to making this a perfect 1-to-1 re-implementation of push notifications, and the DDP client code I've got in there currently also feels a bit awkward (I only imported it directly into the project to make upgrading its dependencies easier)

@CLAassistant
Copy link

CLAassistant commented Jun 18, 2020

CLA assistant check
All committers have signed the CLA.

@diegolmello
Copy link
Member

@mattadatta Cool!
I have to take a look yet, but it seems to be something that could be added to our F-Droid build, which is under development here.

@GOVINDDIXIT what's your take on this PR? How are you going to handle push notifications without FCM?

@GOVINDDIXIT
Copy link
Contributor

@mattadatta Cool!
I have to take a look yet, but it seems to be something that could be added to our F-Droid build, which is under development here.

@GOVINDDIXIT what's your take on this PR? How are you going to handle push notifications without FCM?

Yes the notification support will definitely gonna break in fdroid build, looks this can be helpful for it. Will definitely try to have it once this work is available. Thanks @mattadatta

@diegolmello
Copy link
Member

We're going to reevaluate this in the future, in case we think on improving our gateway solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants