Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Message Handling Flow

Václav Luňák edited this page Mar 12, 2020 · 1 revision

Receiving a message

Once a user clicks the subscribe button on the home page, the app (through HomeFragment) subscribes to a Firebase Messaging topic that messages are sent to. FirebaseListener is specified in the manifest as a receiver for these message events, so when a message arrives, its onMessageReceived() function is called and the message data is passed to it.

Once received, the listener displays a notification and starts the PlayerService intent service, passing it the message data. This calls its onHandleIntent() function.

Playing a message

PlayerService first extracts the message data, then moves to the foreground, creating an ongoing notification. It then sends a confirmation message to the server, vibrates the phone, and after a brief delay adds the message to the MorsePlayer queue.

Once play() is called on a MorsePlayer, it goes through every message in its queue, converts each to morse and then plays it with the appropriate multiplier. Each message is played twice.

Confirming a received message

PlayerService contains a companion object that loads the magician.cpp library. This file contains the functions returning the server URLs and the secret magic string. These resources were placed in a separate C++ library as an attempt to hide these resources from users decompiling the app.

Clients send messages to the server through POST requests. Each request body must contain the "magic" parameter with a value equal to the string returned by getMagic(). Warning: Due to how request bodies are created, the magic value shouldn't contain any HTTP special characters.

Request bodies must also contain the "token" parameter, which is unique for each client. Clients receive their token from the server by visiting the URL returned by getTokenUrl(). This is the only time they may omit the "token" parameter from the request body.

Once a client receives a message through Firebase, they send a request to the server on the URL specified by getMessageUrl(), identifying themselves by the magic and their token and sending the received message's ID. This confirmation is then logged to the server's database.

Clone this wiki locally