Broadcast events in Firefox OS - events

I am wondering if there is a way for a Firefox OS app to broadcast an event to all other apps and for the interested apps to hook on that event and trigger a corresponding action.
An example of use case I have in mind: the Camera app broadcasts the event "picture taken" and another app hooks on this event and take some action on the new picture that has been taken (for example, uploads it to a server).

There's not currently a web API in Firefox OS to broadcast events to all open and/or interested apps.
For your particular use-case of apps being notified when a new photo is taken by Camera, the best approach is probably to open DeviceStorage for "pictures" and listen to "change" events.
Documentation for this is at:
https://developer.mozilla.org/en-US/docs/Web/API/DeviceStorage
Alternatives exist but are more restricted functionally, and available in fewer releases and contexts:
The system can broadcast messages, but only certified apps can listen. https://developer.mozilla.org/en-US/docs/Web/API/Navigator.mozSetMessageHandler
The InterAppCommunication API allows web applications to message one or more other apps, but in a more tightly coupled way than a general broadcast. However this API is not yet standardized, and is only available to certified apps. https://bugzilla.mozilla.org/show_bug.cgi?id=876397
Access to system preferences is coming soon for non-certified apps, and maybe could be used to do this, but that's a hacky way of accomplishing messaging and data sharing. https://developer.mozilla.org/en-US/docs/Web/API/SettingsManager
Note: For every example here, your app would have to be running for it to work. There's no mechanism for waking an app up when a specific action or event occurs. Web Activities is the closest API for event-specific app loading. Timers API is for non-specific app loading.

From this article[1]:
App authors can build an app that will handle one or more activities. That means that the app will be callable by another app to perform some specific actions defined by the activity. For example, let's pretend we want to build a photo manager. It could be used by another application to pick a photo. As an activity handler our app will become part of the other application's workflow.
[1] https://developer.mozilla.org/en-US/docs/Web/API/Web_Activities

Related

Creating realtime alerts for stock quotes

I want to create a realtime stock alert app where users can subscribe to specific stock instrument with target price. Once that target price hit, The subscribed user will be notified over the app.
A good example of such platform is Tradingview.com
For stock API's I will be receiving realtime stock quotes from My API vendor over.
As far my knowledge is concern, I'm looking at this app as Web socket OR MQTT pub/sub platform where users can subscribe to that specific instrument topic and get notified once stock price is hit.
But my knowledge is limited when it comes to thousands of users subscribing to thousands of alerts.
What technologies must be going at the backend for such kind of apps ? What must be the data flow ?
Bit late answer to this, I was working on something similar with all custom NodeJS server and instruments you want to subscribe on. It is very simple server and you can find it here https://github.com/markosole/yahoo-node-streamer
I am working on desktop App built on top of Electron which is used for subscribing to instruments, monitoring multiple instruments and creating visual and sound alerts for every instrument individually. I have not release Electron app source to the public yet.
Creating mobile app will be harder as it would require backround data and best bet would be using Flutter and Google Firestore to send alerts. Well this is very top level.. I will eventually make flutter app and share it on Github
Overlooking the fact that there are literally thousands of apps out there that do all of this already....
Your best bet might be to do one of two things:
1) Just send out the stock price and let the client app figure out the alert, or
2) Have a back-end system that just sends out the alert to the specific customer when their price point is reached.
Option 1 is something that MQTT could easily do. Option 2 could be done using MQTT, but its something of an overkill IMHO. MQTT is built for applications where one node is publishing data, and many nodes are subscribing to that data -- hence Option 1 is more in line with what MQTT was built for.

Why do i need GCM or APN?

Why can't the individual app servers directly send notification to their mobile apps ? What is the benefit of having a centralized notification platform ?
From this thread, GCM is a service that helps developers send data from servers to their Android applications on Android devices. Same with APN which is a service for app developers to propagate information to iOS (and, indirectly, watchOS), tvOS, and macOS devices.
You may check these threads:
Why it is preferred to use GCM for push notifications?
Let's say you have 50 applications on your phone that do not use GCM. Each app developer decides it is appropriate to poll their respective backend once a minute.
Since these are all separate applications, each call will likely not happen at the same time as another api call. The biggest kill to battery is when the radio within an android device has to turn back on after being off to make an API call, so multiple calls happening with blocks of time in between drains battery faster (read this article on the radio state machine to better understand why this is https://developer.android.com/training/efficient-downloads/efficient-network-access.html)
In addition, each application will be hitting a separate endpoint. Each time you make an API call, you have to go through the connect process for a given server. With batched api requests or HTTP 2.0, multiple calls going to the same server can be optimized by not having to re-do a handshake or the connect process.
What are some advantages of push notifications?
Wide reach across internet users.
High conversion rates.
Real-time communication.
Push Notifications Explained
Hope this helps!

Thunderbird: How to access the calendar?

I'm planning to develop a tool (running on the Windows PC) which allows comparing and merging calendar events between different calendars. My mobile device and my Lightning calendar should be supported.
The idea is to write an App for my mobile device connecting to the tool via TCP or UDP so the tool is able to modify the mobile device's calendar by sending commands to the App.
Unfortunately I'm not aware on how I can access the Thunderbird Lightning calendar with my tool.
Question 1: (Possibility 1)
Is it possible to access the Thunderbird (Lightning) calendar read/write from another application (e.g. by directly accessing the SQLite archive) in a safe way?
"In a safe way" means: No risk that the calendar format changes in the next Lightning release and writing events will destroy it!
Question 2: (Possibility 2)
Is there a possibility to access the Lightning calendar data from another Thunderbird plug-in?
(I was searching about this in Google for 2 hours and found nothing!)
Is it possible to create a "permanent" TCP connection from a Thunderbird plug-in (running some operations in the background)?
I would advise against option 1, but if you must then you can check the version table to see if the storage version has changed. This doesn't happen very often. As for accessing calendar data, you can reach the calendar manager and events as follows:
Components.utils.import("resource://calendar/modules/calUtils.jsm");
let calmgr = cal.getCalendarManager();
let calendars = calmgr.getCalendars({});
let mycal = calendars[0]; // pick one
The calendar in mycal will follow the calICalendar interface, which you can read about here. The most important methods are addItem, modifyItem, deleteItem, getItem and getItems.
As for creating a permanent connection from within Thunderbird, it is probably best to use web sockets, which you should be able to use from any DOM window. It might make sense to create your own e.g. with an iframe.

How to build real time notifications in a distributed project?

I wonder to know which technique and tools I should use to have the ability to send real time notifications to users. Specifically if I build a messaging system.
I can see that modern social networks can send notifications about new messages almost immediately. Even when the user 'A' from one country writes a message to the user 'B' in another country you can see that the user 'A' writes a message and you immediately see it (even if those users live in different continents).
I tried to figure out how it is possible and find any information about this but without success.
The only thing I found out is the technique when we use a Redis or RabbitMQ server with several servers which acts like publishers and subscribers. Our API servers receive new messages then they push a new message in the queue then subscribers receives the messages and if they have an open WebSocket with the recipient they push this message in the WebSocket and a client receives the message.
But it really won't work if you have a distributed project and your clients are connected to the nearest servers in the nearest data center.
The question is: what technologies/techniques/anything we should use to be able to build notifications in a distributed project?
If you develop your distributed app/system using web technologies, you can consider building what is referred to as a Progressive Web App. With PWAs you can add push notifications in a relatively easy way. You could start with a PWA approach, and then decide later on if developing a native app as well (i.e. iOS or Android) would be necessary.
There are many resources to learn and guide you in developing progressive web apps. Check the references I mentioned above, and you can do this codelab as a starting point.

What is the best solution for real-time bi-directional communication between a web application running on a mobile phone and a server?

I'm looking at having thousands of simultaneous connections from mobile phones to the server whereby anytime a user interacts with his cell phone, the data is sent and logged by the server. Also, anytime the server has new information for that user, the server can push that information without a browser refresh. I am wondering what is more stable and how you would build this?
A good real-time framework or infrastructure will have numerous APIs that should let you connect any device, no matter the technology, to the real-time server e.g. an iOS client library for iPhone and iPad, a JavaScript client library for numerous platforms including normal and mobile web, an Android compatible Java library and so on.
An interesting idea might be to choose which ever framework or real-time service suits your needs best and then using something like PhoneGap. But, as #rt2088 says, it depends if you need the notification app to be running as a service on the phone or as a standalone application.
The choice will also depend on whether you want to install, host, maintain and manage the scaling of your own real-time services or not. If not, there are a number of services out there who you could use so you can concentrate on building your application. If you do want to manage your own infrastructure then the Comet Maturity guide could be a good start. It's a little out of date but is still probably the best reference available.
the ability to push new content the
user based on his GPS location which
is "pinged" to our server. Based on
that, we deliver local content. What
frameworks are you talking about?
There are a number of real-time frameworks available at the moment. Some are hosted services and others require installation on your own hardware. The majority of them will come with a bunch of libraries in different technologies that make it easier to get up and running with them e.g. a JavaScript library that wraps the WebSocket object and also manages fallback for web browsers that don't support WebSockets.
I've just created a Real-Time Technologies Guide in which I've listed all the real-time technologies that I could think of and provided a bunch of tags associated with each.
wouldn't a javascript client library
cover all platforms if it is a web
appilcation?
If the application is a web application then yes, a JavaScript library would be all you need for the client application. The server side libraries that you require would depend on the real-time technology you choose.
Best solution to achieve this is to use the WebSocket communication. It is bidirectional asynchronous communication. Currently every browser supports this new standard and plenty of code snippets available. You just have to google it. There are many server and client side frameworks. choose the one best suits to your requirement.
The details of the WebSocket specification is available at -
Websocket specification
Do you need notification when user uses mobile browser of handset or the mobile handset itself (performing non-browser tasks)? Based on that, the framework to record user activity can be selected.

Resources