Shared push notifications

32 views
Skip to first unread message

Michiel de Jong

unread,
May 27, 2014, 3:18:49 AM5/27/14
to unhosted
Hi!

On Thursday, after DecentralizeCamp.com, Nick and I had an insightful conversation about how we can implement an irc bot within the remoteStorage+5apps+sockethub platform. An irc bot is just an example of a service which represents you when you are not online; other examples might be a service which alerts you when you are mentioned on Twitter, or when a new post was added to a certain rss feed.

This ties in with my "shared notification" milestone from NLnet. The "shared" here means shared between apps, and the goal is to create a way for applications to "wake up" when they are not in focus, and even when the whole device is on stand-by. For the first situation, alerting the user can be done in two ways:

* change the tab title, adding "(1)" or "(2)" to display how many unread messages are there
* use http://www.w3.org/TR/notifications/ to trigger a user notification at the OS level.

For the second situation, we will use the brand-new https://wiki.mozilla.org/WebAPI/SimplePush which was added to the web platform by Firefox OS.

For generating the pro-active notifications, something needs to run on the server: either as part of the sockethub server, as part of the remoteStorage server, or as a third daemon. The key insight is that a "butler" service (an extra daemon which runs on your server, next to sockethub and your remoteStorage server), can include the modules from our modules repo, and sockethub-client.js, and then doesn't need anything else except to connect the 'message' event from sockethub-client.js to the 'onMessage' handler of the messages module.

We had been wary in the past of introducing an application-specific butler service with more code to maintain, but when we realized that this butler daemon would have only 20 lines of code, and the rest of the code would be shared with all message-oriented unhosted web apps, it was suddenly clear to us that this is the way to go. Some specific details of the plan:

- No changes are needed to sockethub, nor to the remoteStorage server. We simply run the client code for both of them in nodejs, and connect the two clients to each other with <20 lines of code.

- remoteStorage just stores data
- the 'messages' and 'sockethub' modules form part of apps, and of the butler service
- the butler service is just a few lines of server-side code:

````js
    require('remotestorage-node.js');

    require('sockethub-module.js');
    var s = remoteStorage.sockethub.getClient();

    require('feeds-module.js').connect(s);
    require('irc-module.js').connect(s);
    require('email-module.js').connect(s);
    require('xmpp-module.js').connect(s);
    require('twitter-module.js').connect(s);
    require('facebook-module.js').connect(s);
````

- this way, the butler service makes sure sockethub:
  - keeps you logged in to irc and xmpp,
  - checks email regularly, and
  - receives incoming notifications from twitter and facebook.

The next step is adding:

````js
    require('messages-module.js');
    s.on('message', remoteStorage.messages.handleMessage);
````
 
- when a message comes in, it is handled by the messages module. This way, you always have one central history of your messages and notifications, which you own in one place forever.

- whenever an app runs on Firefox OS, it can request a notifications endpoint, and store this URL in the messages module. The butler service will see this URL, and start sending pings there, meaning the phone will wake up the app, and the app can display a notification. Regardless of whether the app is currently not in the open tab, or the browser is currently not open, or even, when the device is on stand-by in your pocket, it will alert you via sound+vibrate when you receive an irc mention, etcetera.
 
- as an extra feature, the app that registers the alert end-point can apply filters and rules to whether or not to alert the user, based on the content of the message. For instance, you could set it to ignore emails that were sent to mailing lists, and only alert you about direct emails to you. This feature can be added to the messages module (or a separate notifications module if we decide that is cleaner), and any app can implement an "edit notification rules" UI which calls this module API to create such rules.
 
- another extra feature would be to add support for proprietary pinging interfaces for Android and iOS.

- in other modules,
  - where you make your own changes yourself, no notification is needed.
  - where you poll another person's changes feed, you can use the sockethub feeds platform to subscribe to it.


This completes the design of the mechanism, let me know if you have any ideas/feedback/comments!

The next step is to actually implement this mechanism in the existing remotestorage.js modules. I'm very excited about this! :)

Michiel de Jong

unread,
Oct 20, 2014, 9:34:49 AM10/20/14
to unho...@googlegroups.com
No comments came on this thread - I'll proceed and implement it now, in the way we discussed it at DecentralizeCamp.

Cheers!
Michiel

Nick Jennings

unread,
Oct 20, 2014, 9:40:18 AM10/20/14
to unhosted
Just an FYI - I've been continuing to improve the modules, both in terms of testing and updating the quality / normalizing between different modules that are very similar. So I think there'll continue to be some changes (some may be breaking) in the coming days/weeks, especially in regards to the credential modules. I'll try to remember to ping you when this happens via github.

--

---
You received this message because you are subscribed to the Google Groups "Unhosted Web Apps" group.
To unsubscribe from this group and stop receiving emails from it, send an email to unhosted+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michiel de Jong

unread,
Oct 20, 2014, 9:57:50 AM10/20/14
to unhosted
thanks!

Jon Spriggs

unread,
Oct 20, 2014, 10:58:47 AM10/20/14
to unho...@googlegroups.com
Looking forward to when our Firefox OS Overlords rule us :) You've mentioned using the proprietary Android and iOS protocols, you might also consider whether you can use ServiceWorkers [1][2] for in-browser stuff?

[1] http://www.w3.org/TR/service-workers/
[2] https://jakearchibald.github.io/isserviceworkerready/

--
Jon "The Nice Guy" Spriggs

Sebastian Kippe

unread,
Oct 20, 2014, 2:04:38 PM10/20/14
to unho...@googlegroups.com
Hooray for ServiceWorkers, and also have a look at:
http://www.w3.org/TR/push-api/

Cheers
Basti


On 10/20/2014 07:58 AM, Jon Spriggs wrote:
> Looking forward to when our Firefox OS Overlords rule us :) You've
> mentioned using the proprietary Android and iOS protocols, you might
> also consider whether you can use ServiceWorkers [1][2] for in-browser
> stuff?
>
> [1] http://www.w3.org/TR/service-workers/
> [2] https://jakearchibald.github.io/isserviceworkerready/
>
> --
> Jon "The Nice Guy" Spriggs
>
> On 20 October 2014 14:57, Michiel de Jong <mic...@unhosted.org
> * use http://www.w3.org/TR/__notifications/
> <http://www.w3.org/TR/notifications/> to trigger a user
> notification at the OS level.
>
> For the second situation, we will use the brand-new
> https://wiki.mozilla.org/__WebAPI/SimplePush
> require('remotestorage-node.__js');
>
> require('sockethub-module.js')__;
> var s = remoteStorage.sockethub.__getClient();
>
> require('feeds-module.js').__connect(s);
> require('irc-module.js').__connect(s);
> require('email-module.js').__connect(s);
> require('xmpp-module.js').__connect(s);
> require('twitter-module.js').__connect(s);
> require('facebook-module.js').__connect(s);
> ````
>
> - this way, the butler service makes sure sockethub:
> - keeps you logged in to irc and xmpp,
> - checks email regularly, and
> - receives incoming notifications from twitter and
> facebook.
>
> The next step is adding:
>
> ````js
> require('messages-module.js');
> s.on('message', remoteStorage.messages.__handleMessage);
> ````
> <mailto:unhosted+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
>
> ---
> You received this message because you are subscribed to the
> Google Groups "Unhosted Web Apps" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to unhosted+u...@googlegroups.com
> <mailto:unhosted+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Unhosted Web Apps" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to unhosted+u...@googlegroups.com
> <mailto:unhosted+u...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
>
> ---
> You received this message because you are subscribed to the Google
> Groups "Unhosted Web Apps" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to unhosted+u...@googlegroups.com
> <mailto:unhosted+u...@googlegroups.com>.

Michiel de Jong

unread,
Nov 8, 2014, 8:39:23 AM11/8/14
to unho...@googlegroups.com

OK, I got the butler service working now. I couldn't get it to show a notification on my Firefox OS phone unfortunately, and the video output of gtk-recordmydesktop on ubuntu 14.10 is very hard to watch (it mixes up the bottom-right triangle of every window), but hopefully it's still clear from the commentary what happens in this screencast: https://unhosted.org/downloads/unhosted-shared-notifications.ogv

This uses:
* a sockethub server (running on localhost in this case)
* a remoteStorage server (a 5apps account)
* meute with sockethub-client and remotestorage.js running in node
* a simple butler.js script that requires the right node packages sets the credentials, and calls `meute.bootstrap();`


Thanks a lot to Nick for his work on version 0.11 of remotestorage.js, which refactors it for use on NodeJS, which was an important prerequisite for getting this working.

The code is here: https://github.com/michielbdejong/meute/blob/v0.7.1/butler.js#L50-L54

By the way, this was my last NLNet-sponsored milestone, and my new full-time project is https://indiehosters.net/, which already received a small NLNet grant, and will start crowdfunding very soon!

I'll continue to work on unhosted web apps (as well as on Terms of Service; Didn't Read) in my spare time. Currently I'm working on porting the IndexedDB commit cache from remotestorage.js to Mozilla localForage, so that more people can benefit from it. The next thing I want to add to Meute is multi-backend collaboration, which is a prerequisite for http://opentabs.net/.


Cheers!
Michiel
Reply all
Reply to author
Forward
0 new messages