CloudServices/Presence: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Adding some initial clarifying language wrt scope of service, intended customer, etc. WIll refine w/ Tarek more now. :))
 
(40 intermediate revisions by 4 users not shown)
Line 5: Line 5:
=''Presence''=
=''Presence''=


==Service Overview==
==Overview==


Mozilla Presence is a proposed Cloud Service conceived by the Cloud Services team's [[https://phonebook.mozilla.org/#search/tarek Tarek Ziade]] for FirefoxOS.  
Presence is a proposed Cloud Service that tracks a Firefox OS device's Internet connectivity status as ''online'', ''offline'' or ''unavailable'' by the device's Firefox Account. A Firefox OS Web App may request permission on behalf of its publisher to read status. Once approved, the publisher may poll the Presence service and, once the device is back online, push messages to the Web App.


Mozilla Presence tracks Internet connectivity status as online or offline for each Firefox Account user's Firefox OS devices. Firefox OS Web Apps may request permission to access this status information on behalf of their publisher, who may then in turn poll the Mozilla Presence service and thus push (using SimplePush) timely messages to the Web App.  
See [[#Architecture Overview]] for more details.


'''User Stories'''
==Project Contacts==
As a FirefoxOS Web App user, I want my....
 
''Principal Point of Contact'' - <i>Tarek Ziade</i> <i>tziade@mozilla.com</i>
 
 
* ''IRC'' - #<i>presence-wg</i>
* ''Group Email'' - https://mail.mozilla.org/listinfo/wg-presence
 
===Team===
 
==== Cloud Services ====
 
 
* <i>Tarek Ziade</i> <i>tziade@mozilla.com</i>
* <i>Ben Bangert</i> <i>bbangert@mozilla.com</i>
* <i>Robert Lord</i> <i>rlord@mozilla.com</i>
* Firefox Account Engineer - TBD
 
==== Firefox OS ====
 
* <i>Fabrice Desré</i> <i>fabrice@mozilla.com</i>


'''Publisher Stories'''
==Presence on other Mobile Platforms==
As a FirefoxOS Web App publisher, I want...


'''FirefoxOS Team Contacts'''
===Presence on iOS===
TBD


==Architectural Overview==
In iOS >= 7.x, applications that want to provide a presence feature can
keep a socket opened in the background even if the application is not
running anymore in the foreground.


There  are two levels of presence:
The feature is called setKeepAliveTimeout (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setKeepAliveTimeout:handler:)
and will give the app the ability to register a handler that
will be called periodically to check on the socket connection. Only approved VOIP apps are
allowed by Apple to always keep a socket alive and not be terminated. Apple
is very discerning about which apps get to use this functionality.


1/ app-level presence
The handler has a limited time to do it (max 10 seconds) but
this is enough to handle presence for the user by interacting with a
server.
 
The Apple Push Notification Service https://en.wikipedia.org/wiki/Apple_Push_Notification_Service
is also often used by applications to keep a connection opened on a
server to receive push notifications. That's comparable to the Simple Push
service Mozilla has added in Firefox OS.


* online: you are connected in the app, and using it
Therefore, building an application with device-level presence on an iOS device
* offline: you are disconnected from the app
is doable but requires the publisher to maintain one or several connections per user
opened all the time and very few applications qualify for VOIP status.


2/ device-level presence.
=== Presence on Android ===


* online : you are using your FXOS phone or your desktop browser
Like iOS, Android provides features to run some services in the background,
* offline: you are not on your FXOS phone or your browser
see http://developer.android.com/guide/components/services.html


Sometimes you might be online in 1/ or 2/ and not wishing other users to know about it. And you also might want to appear online for app B but not for app C.
However, the service can be killed when the memory becomes low, and
if TCP/IP is used it can be hard to have a reliable service.


1/ is solved by every application. they all have their ad-hoc system, their social graph, rosters, contacts, etc. Large social networks don't care as much about 2/ because they would prefer you to use *only* their application for talking to your friends. By solving 2/, we can enable non-dominant social/communication applications to get useful presence information they can act on.
Google also provides a "Google Cloud Messaging" (GCM) service - http://developer.android.com/google/gcm/index.html
That provides similar features than Simple Push, to push notifications to users.


Mozilla Presence acts as a <b>trusted intermediary between the user's device (solving 2/) and the applications the user has allowed to see their presence, as well as a short-lived notification system for applications to engage available users</b>.
There's also a new feature called GCM Cloud Connection Server - (CSS)
http://developer.android.com/google/gcm/ccs.html - that allows applications to communicate
with the device via XMPP and on the client side "Intent Services".
The app and the devices interact with CSS, which relays the messages back and forth.


[[File:PresenceOverview.jpg]]
There's a full example on that page, of a Python server interacting with the GCM service
to interact with users.  


Channel communication overview:
The architecture is quite similar to what we want to build with Mozilla Presence
since GCM acts as an intermediary between the app server and the device.


[[File:MPChannels.jpg]]
However, CSS is a neutral messaging relay and does not keep track of users online
status. It sends back and forth what the server and the device have pushed in the pipe.


==Project Contacts==
So it's still up to the app to leverage this service to keep track of connected
''Principal Point of Contact'' - <i>Tarek Ziadé</i> <i>tarek@mozilla.com</i>
devices to get device-level presence.


''IRC'' - #<i>presence-wg</i>
'''if we decide not to build presence, maybe we would just need to build that relay to make sure we offer FFOS apps the ability to implement presence the right way, like what Google provides on Android'''


''Mailing list'' - [https://mail.mozilla.org/listinfo/wg-presence https://mail.mozilla.org/pipermail/wg-presence/] - wg-presence@mozilla.org
XXX stuff to dig: can we use CSS with BOSH or with websockets


==Goals==
==Goals==


Desktop/phone UI for users to:
Phone UI for users to:
* see at a glance and manage what applications they granted presence access to.
* see at a glance and manage what applications they granted presence access to.
* see lively notifications and act on them or ignore them.
* see lively notifications and act on them or ignore them.
* manage how much idling is considered to be 'online' vs. 'away' vs. 'offline'
* manage how much idling is considered to be 'online' vs. 'away' vs. 'offline'
* set custom status updates


Mozilla Cloud Services run system that:
Mozilla Cloud Services run system that:
Line 68: Line 108:


The project will be a success if an application registered with Mozilla Cloud Services is able to reach out to users that are "online" (active on their phone or desktop but with the app not running) via Mozilla Presence.
The project will be a success if an application registered with Mozilla Cloud Services is able to reach out to users that are "online" (active on their phone or desktop but with the app not running) via Mozilla Presence.
== Terminology ==
;AppDeveloper : A developer that creates applications which may or may not have server-backed resources.
;AppService : An Internet-accessible server that an application talks to. For example, Facebook's locally installed application talks to Facebook's API server to get data. The Facebook API server in that case is the AppService as it acts as a service to the application.
;Application : A website application that might run locally on a device with or without needing to talk to an AppService.
;FxAID : A Firefox Accounts user ID.
;Device Presence Channel : A channel of communications between a phone/browser device and Mozilla Presence that carries live notifications from Presence and presence data to Presence.
;AppService Presence Channel : A channel of communication between Mozilla Presence and an AppService that carries presence updates for users sharing their presence with the AppService and live notifications from the AppService to be delivered to a PUID.
; LiveNotification : A live notification is an alert requiring a response within a set period of time (5 seconds up to several minutes) before its considered 'missed' and stored on the device separately to indicate it can no longer be acknowledged. A response is considered acknowledgement and switches the user to the appropriate application to act on the LiveNotification.
; Presence : For our purposes the definition of presence definined by XMPP also applies, but in our case 'contacts' happen to be AppServices that the presence is broadcast to. See http://xmpp.org/rfcs/rfc6121.html#presence-fundamentals
;PUID : A Presence Unique Identifier. Every AppService authorized by a user to see presence updates will be assigned a PUID that it should store and associate with the user (who may or may not be logged into the application).


==Use Cases==
==Use Cases==


=== Chat Room (=IRC Channel) ===
See [https://wiki.mozilla.org/CloudServices/Presence/UseCases Detailed Use Cases].


A chat room app let people talk with each other on the same web page. You connect to the system using Persona and you avatar appears on the page to other users.  You can add contacts in that app.
==Requirements==
* <i>List of requirements</i>


People see you messages in realtime. It's built using whatever chat technology (BOSH/XMPP, plain websockets)
==Get Involved==


Before Mozilla Presence:


* a user appears as present (or busy or idling etc..) in the chat room when she's connected to the app and uses it
== Documents so far ==
* a user that is not currently using the app (perhaps because FFOS killed that app due to constrained device resouces) appears offline.  
[https://etherpad.mozilla.org/ServicesPresence Services Presence Etherpad]
* if the application wants to reach an offline user, it does not really know if the user is offline at the device level or just the app level.


With Mozilla Presence
[https://id.etherpad.mozilla.org/presence Identity Presence Etherpad]


* a user runs the Presence service and let it know when he's offline/online at the device level (desktop browser: a social API sidebar, FXOS: some background service)
[https://etherpad.mozilla.org/presence-meeting Presence Meeting Wiki]
* the user set permissions: "yes the chat app can get my presence updates"
* the user then can use the chat app independantly from the presence thing - or not having it running at some point at all
* the chat app interacts with the presence server: it gets a stream of presence update from the presence server only if the user authorized it
* the chat app can notify a user that another user pinged him in the room


Resources:
== Meetings ==
We try to meet every Thursday at 10:00 Pacific Time


* '''Demo''' (without the app permission dance yet):  https://vimeo.com/79394330
For mozilla employees, we meet in the "Services" vidyo room, and use IRC channel #presence-wg (irc.mozilla.org)
* '''Prototype repo''' https://github.com/mozilla-services/presence-chatroom


=== Facebook ===
For participants outside of mozilla, you can call into the meeting using the following numbers:
* Phone (US/Intl): 650 903 0800 x92 Conf: 98616#
* Phone (Toronto): 416 848 3114 x92 Conf: 98616#
* Phone (US): 800 707 2533 (pin 369) Conf: 98616#


Jeff wants to appear online on Facebook (he's already determined on Facebook who can see him, etc).
Please mute yourself with '* 1' upon joining to prevent needless noise and feedback. You can unmute yourself with '* 1' again to speak.  


He's already installed the Facebook app on his FFOS phone, he goes to the Settings and touch, "Authorize Presence",
=== Meeting Notes ===
his screen loads a doorhanger (provided by Mozilla Presence) asking if he wants to authorize the app.


Jeff clicks "Yes" on the doorhanger page, and the Facebook app waits while Facebook recieves the redirect, stores
https://etherpad.mozilla.org/presence-meeting-20140311
his UID, and closes the doorhanger (and likely needs to do something else to register this with the device so that
it will appear in the Presence Settings page).


The next day, Jeff wakes up, and goes to check his e-mail on his phone. Upon seeing his idle drop, the phone's
[[Services/Roadmaps/Presence/Meetings/notes_20131014]]
simple-push client (which is always running) includes an 'O' in its next PING to simplepush to indicate the user
is now online. Mozilla Presence gets notified of this and acts on it to batch the status change to Facebook. The
batch of updates goes to Facebook including Jeff's, so Facebook knows that Jeff is now online, and updates its
database indicating this.


Jeff's friend Marsha goes to Facebook to see if any of her friends are online. Marsha sees that Jeff is now online
[[Services/Roadmaps/Presence/Meetings/notes_20131031]]
and sends a chat request. Facebook uses SimplePush to notify Jeff of the chat request. Jeff sees the chat request


=== AppMaker ===
https://etherpad.mozilla.org/presence-2013-11-26


Sue has signed up to be an appmaker tutor -- Bob is a new appmaker teacher, and is stuck in a workshop, Bob wants to know which of the tutors are available to help w/ a togetherJS session
=Design=


Sue is an appmaker expert.  She previously authorized AppMaker to see her Online Presence - as Jeff did in with
==Points of Contact==
Facebook in the previous story. She also configured her notifications so any message coming from AppMaker
when she's online would display a message on her screen and let her start the app.


Bob is building a cool new application with his class in AppMaker and would like some input from someone.  Appmaker maintains a mapping of which helpers are appropriate for which users (e.g. by language skills). He's currently working in AppMaker from his FFOS Phone and sees that Sue is online.
Services Engineers:


Bob clicks on Sue's name in his contact lists and hit "invite Sue for peer design session".  
* <i>Ben Bangert</i> <i>bbangert@mozilla.com</i>
AppMaker sends a notification to Sue using the Simple Push service.
* <i>Tarek Ziadé</i> <i>tarek@mozilla.com</i>


Sues gets the notification instantly on her phone via her simple-push client and joins Bob on the
==Architecture Overview==
design page.


AppMaker uses Together.js so Bob and Sue can interact live on the page.
There are two levels of presence:


=== Support ===
1/ app-level presence


(This is about a tentative and unnamed Firefox OS support tool.)
* online: you are connected in the app, and using it
* offline: you are disconnected from the app


Maria is a Mozillian who wants to helpful to other Firefox OS users.  She signs up with a support application (an application that Mozilla creates).  She indicates what she knows about, and what languages she speaks.
2/ device-level presence.  


Javier wants to activate developer mode on his phone, but can't find the right setting.  He goes into '''Help &gt; Live Support'''.  The phone sends a request to the support app: someone wants support with Settings in es-MX.  The application looks in its database of contributors to see who has the appropriate expertise (and language) to help him, and who is online.  Among the pool of possible people it selects Maria, and pings her to see if she can provide support.  If she doesn't respond then another person is selected from the pool (or maybe many people are asked at once), and if someone else helps Javier then Maria is notified that her help is no longer needed.
* online : you are using your FXOS phone or your desktop browser
* offline: you are not on your FXOS phone or your browser


Note that Maria would be participating under an alias specific to the support application (though not anonymous), and she will not be fielding support requests all the time (e.g., she may not provide support at work, only after hours).
Sometimes you might be online in 1/ or 2/ and not wishing other users to know about it. And you also might want to appear online for app B but not for app C.


=== Wikipedia ===
1/ is solved by every application. they all have their ad-hoc system, their social graph, rosters, contacts, etc. Large social networks don't care as much about 2/ because they would prefer you to use *only* their application for talking to your friends. By solving 2/, we can enable non-dominant social/communication applications to get useful presence information they can act on.


(This comes from conversations about TogetherJS and Wikipedia)
Mozilla Presence acts as a <b>trusted intermediary between the user's device (solving 2/) and the applications the user has allowed to see their presence, as well as a short-lived notification system for applications to engage available users</b>.


Some questions that might be nice to answer with a presence service:
[[File:PresenceOverview.jpg]]


* Is there someone actively working on this page (or its related Talk/etc pages) right now?
Channel communication overview:
* Is there someone ready to offer X help at this moment?  (X examples: editing help, template authoring, mediate disputes)
* Given a community of interest (people interested in baseball, admins, etc):
** Who is around?
** What are they doing?  (E.g., editing pages, hanging out in a discussion, etc; each person would opt in to publicizing this information to other people.)


=== Talkilla ===
[[File:MPChannels.jpg]]


XXX
== Terminology ==


=== Chatspace ===
;AppDeveloper : A developer that creates applications which may or may not have server-backed resources.


Jen is building https://github.com/mozilla/chatspaces - we should investigate how presence fits there
;AppService : An Internet-accessible server that an application talks to. For example, Facebook's locally installed application talks to Facebook's API server to get data. The Facebook API server in that case is the AppService as it acts as a service to the application.


=== SUMO ===
;Application : A website application that might run locally on a device with or without needing to talk to an AppService.


XXX See with Lloyd about the user story there (sumo experts summoned etc)
;FxAID : A Firefox Accounts user ID.


==FAQ==
;Device Presence Channel : A channel of communications between a phone/browser device and Mozilla Presence that carries live notifications from Presence and presence data to Presence.


To help people get up to speed faster and prevent backtracking, commonly asked questions by those getting involved are listed here with an answer.
;AppService Presence Channel : A channel of communication between Mozilla Presence and an AppService that carries presence updates for users sharing their presence with the AppService and live notifications from the AppService to be delivered to a PUID.


=== Is this going to use XMPP? ===
; LiveNotification : A live notification is an alert requiring a response within a set period of time (5 seconds up to several minutes) before its considered 'missed' and stored on the device separately to indicate it can no longer be acknowledged. A response is considered acknowledgement and switches the user to the appropriate application to act on the LiveNotification.


It quite possibly will! However, its useful to remember that Mozilla Presence is in very early stages at this moment. Worrying about the exact implementation is a detail that we're not addressing yet as we build some prototypes to test ideas out and prove the overall concept is worthwhile.
; Presence : For our purposes the definition of presence definined by XMPP also applies, but in our case 'contacts' happen to be AppServices that the presence is broadcast to. See http://xmpp.org/rfcs/rfc6121.html#presence-fundamentals


=== Shouldn't Mozilla have a way for me to see my contacts online? ===
;PUID : A Presence Unique Identifier. Every AppService authorized by a user to see presence updates will be assigned a PUID that it should store and associate with the user (who may or may not be logged into the application).


Nowadays, peoples' personal connections are spread across multiple online services (Facebook, Google+, Skype, etc). These services usually already have done the work of ensuring both people want to see each other's presence and have ways to facilitate a conversation. All they need is a way to be aware of a users presence when their app might be closed or suspended (on a phone). By serving as the underlying plumbing notifying AppService's when users are online, Mozilla Presence avoids having to try and change users expectations about where their 'friends' are and can facilitate new social interaction applications that need presence data.
== API Reference/Documentation ==


==Requirements==
The Presence service has several functions:
* <i>List of requirements</i>


==Get Involved==
# '''Device Channel to Mozilla Presence''' - let a '''user''' update her online status and set a custom status message
# '''Applications registration''' - let a '''developer''' register an application
# '''Applications permissions''' - let a '''user''' manage applications access to their presence
# '''Status updates''' - let an '''application''' receive status updates
# '''Live Notifications''' - let an '''application''' send a live notification and a user receive it.


=== 1. Device Channel to Mozilla Presence ===


== Documents so far ==
Mozilla Presence provides a secured web socket endpoint at '''wss://presence.services.mozilla.com/presence''' for
[https://etherpad.mozilla.org/ServicesPresence Services Presence Etherpad]
devices to connect to.
 
[https://id.etherpad.mozilla.org/presence Identity Presence Etherpad]


== Meetings ==
The user may connect to the socket using a valid FxA (which will entail a BrowserID Assertion per FxaSSO), and send status updates.
We try to meet every Thursday at 10:00 Pacific Time


For mozilla employees, we meet in the "Services" vidyo room, and use IRC channel #presence-wg (irc.mozilla.org)
The data must be sent in JSON and is based on a simple protocol where a first request must be made to create a new session.
Each subsequent request is a status update. The server or the user can disconnect from the socket at any time and for
any reason. In that case the session is lost and a new session must be initiated.


For participants outside of mozilla, you can call into the meeting using the following numbers:
==== Session Request ====
* Phone (US/Intl): 650 903 0800 x92 Conf: 98616#
* Phone (Toronto): 416 848 3114 x92 Conf: 98616#
* Phone (US): 800 707 2533 (pin 369) Conf: 98616#


Please mute yourself with '* 1' upon joining to prevent needless noise and feedback. You can unmute yourself with '* 1' again to speak.
Example of a session request:


=== Meeting Notes ===
    {'type': 'connect',
    'application_ids': [421, 492, 9592, 391],
    'assertion': 'valid persona assertion'}


[[Services/Roadmaps/Presence/Meetings/notes_20131014]]
where:
* '''assertion''' is a valid persona assertion
* '''type''' is the type of request. in that case "connect"
* '''application_ids''' is the list of applications IDs presence updates should be sent to.


[[Services/Roadmaps/Presence/Meetings/notes_20131031]]
The '''application_ids''' field is used because Mozilla Presence does not retain a list of applications
authorized to see updates. This data is kept only on the phone. As a result, the device must
indicate what application ID's presence data should be sent to when connecting.


=Design=
The server validates the assertion by sending it to a persona/fxaccount verifier,
and if valid, creates a unique session id and sends it back to the cient.


==Points of Contact==
Example:
  {'result': true, 'session_id': '61539351-1f02-4b62-a136-205000ece41a'}


Services Engineers:
In case there's an issue, like an invalid assertion, the server will send back a
request with a result flag set to false, an '''errno''' field with
an error code (to be documented) - and an error message in the '''reason''' field.


* <i>Ben Bangert</i> <i>bbangert@mozilla.com</i>
Example:
* <i>Tarek Ziadé</i> <i>tarek@mozilla.com</i>


Repository: https://github.com/mozilla-services/presence
  {'result': false, 'errno': 34, 'reason': 'Invalid assertion'}




== General Overview ==
==== Status Update Request ====


The Presence service has several functions:
Once the session is set, the client can send status updates.


# let a user update her online status
Example:
# let a developer register an application
# let a user manages applications permissions
# let an application receive status updates
# let an application send a live notification and a user receive it.


=== 1. Online status updates ===
    {'type': 'status',
    'session_id': '61539351-1f02-4b62-a136-205000ece41a'
    'status': 'online'}


Mozilla Presence provides a web socket endpoint at '''ws://presence.services.mozilla.com/presence'''
where:
* '''session_id''' the session ID
* '''type''' is the type of request. in that case "status"
* '''status''' the presence status. The value must be one of "online", "offline", "unavailable".


The user may connect to the socket using a valid Persona assertion, and send status updates. The data must be sent in JSON.
In case the device wants to send a status update to a specific subset
of applications, it can use the 'application_ids' key on a status update
request, it will override the value set on a visibility call, just for
that call.


Example:
Example:


     {'email': 'tarek@mozilla.com',
     {'type': 'status',
     'assertion': 'valid persona assertion',
     'session_id': '61539351-1f02-4b62-a136-205000ece41a'
     'status': 'online'}
    'application_ids': [421, 391],
 
     'status': 'offline'}
The status value must be one of "online", "offline" or "unavailable"


For every status received, the server sends back an ACK message.
For every status request received, the server sends back an ACK message.


Example:
Example:
   
   
   {'result': 'OK'}
   {'result': true}


In case of an error, the server may send back an extra 'errno' field with an error code (codes to be documented)
In case of an error, the server will send back an extra 'errno' field with an  
and an optional 'error' message.
error code (codes to be documented) and an optional 'reason' message.


Example:
Example:


   {'result': 'KO', 'errno': 34, 'error': 'Invalid assertion'}
   {'result': false, 'errno': 34, 'reason': 'Assertion expired'}


The user can send as many updates as it wants, but the server can ask it to slow down with a specific  
The error codes have to be documented, but in case the errno value is
error code  (codes to be documented)
a negative value, the session is lost and the client has to recreate a new one.
 
The user can send as many updates as it wants, but the server can ask it to  
slow down with a specific error code  (codes to be documented)


The server or the user can disconnect from the socket at any time and for any reason.
The server or the user can disconnect from the socket at any time and for any reason.
Line 304: Line 326:


Mozilla Presence provides a web page at '''https://presence.mozilla.com/myapps'''
Mozilla Presence provides a web page at '''https://presence.mozilla.com/myapps'''
where an application developer can connect by logging with her persona account.  
where an application developer can connect by logging in with her persona account.  


Once logged in, the developer can fill a
Once logged in, the developer can fill a
Line 344: Line 366:
Example:
Example:


   {'key': 'XXX'}
   {'key': 'e3b0c44298fc1c149afbf4c8....996fb92427ae41e4649b934ca495991b7852b855'}


Once connected, the application will receive status updated as they happen,  
Once connected, the application will receive status updated as they happen,  
in the form of a list. Each element is composed of an e-mail and a status.
in the form of a list. Each element is composed of an uid and a status.


Example:
Example:
Line 390: Line 412:
The redirect flow looks like this:
The redirect flow looks like this:
[[File:WPAuthInteraction.jpg]]
[[File:WPAuthInteraction.jpg]]
=== 4. Presence Sidebar ===
XXX the one risk we have prototyping with Social Sidebar is that we design something that works great for desktop use, but is not a good UX for a phone
Mozilla Presence provides a Social API sidebar with the following features:
* a Persona login/logout button
* three buttons to set her status. [online/offline/unavailable].
* a list of authorised applications with a [deactivate/revoke] button for each one of them.
This sidebar can be activated by the user to manage her presence - the side bar
will open a web socket on ws://presence.services.mozilla.com/presence to send
status updates.


=== 5. Status updates ===
=== 5. Status updates ===


When Mozilla Presence gets a status update from someone, it looks up all the  
When Mozilla Presence gets a status update from someone, it looks up all the  
registered applications and sends to the one that are activated the updates.
registered applications and sends to the one that are activated to see the updates.


Since statuses are fetched via a web socket at ws://<node>.presence.mozilla.com/<appid>, each application gets its own messaging queue that is dequeued when the application is connected via the web socket. A status message is dropped from the queue if not  
Since statuses are fetched via a web socket at ws://<node>.presence.mozilla.com/<appid>, each application gets its own messaging queue that is dequeued when the application is connected via the web socket. A status message is dropped from the queue if not  
Line 415: Line 423:
=== 6. Live notifications ===
=== 6. Live notifications ===


XXX encryption ?
Live notifications are a way for applications to reach out online users that are not active in the application.
It can be used to give the opportunity to the user to react when something is happening in the application.


Live notifications are a way for applications to reach out online users that
Examples:
are not active in the application.


Like status updates, live notifications are done via '''ws://presence.services.mozilla.com/presence'''.
* ChatRoom: Your nick was used in a message sent to the room.
* ChatRoom: Someone wants you to join the room.


The application sends a notification to Mozilla Presence via a POST request
 
containing :
AppService sends a notifications to Mozilla Presence via a POST request :


   POST https://<node>.presence.mozilla.com/<appid>/notification
   POST https://<node>.presence.mozilla.com/<appid>/notification
    
    
   {'UID': 'userid',
   [{'UID': 'userid',
     'message': '<message>',
     'message': '<message>',
     'url': '<url>'}
     'action': '<url>'},
    ...
  ]
 
AppService can send notifications by batches.
 
Details:
 
* ''userid'': the user ID provided by the presence system.
* ''message'': a message to display to the user. Limited to 512 chars.
* ''action'': an action that will happen on the device if the user agrees - it can be an url to visit or an application to run. Limited to 512 chars.
 
Mozilla Presence pushes the message into a FIFO queue. There's one queue per user id + app id combination, and its size
is limited to 100 items. When the queue is full, the oldest item is dropped before the new item is added.
For each item, it appends in the mapping the ''appid'' value.
 
Once the message is stored, the service sends back an ack message to AppService, with the
current size of the queue:
 
  {'result': 'OK',
    'queue_size': <size>}
 
Receiving the ack is a guarantee that the message was stored on the server, but
is not a guarantee that it was delivered to the user.


Each user gets its own messaging queue and the message will be discarded after 5 minutes if not consumed by the user.
If the user is connected to Mozilla Presence via the Presence daemon, it gets all
the items from the queue and the queue is purged.


If the user is connected on '''ws://presence.services.mozilla.com/presence''' - the messages will be dequeued and pushed there.
The Presence daemon on the device is responsible to dispatch the messages to
the different applications:


* '''on desktop''', it displays a notification with the url contained in the action for the user to click
* '''on mobile''', it displays a notification with a link to run the app XXX


XXX implementation of desktop UI, see https://developer.mozilla.org/en-US/docs/Social_API/Widgets#Notification_Panels
The application has no feedback on whether a notification was seen by the user.
 
==FAQ==
 
To help people get up to speed faster and prevent backtracking, commonly asked questions by those getting involved are listed here with an answer.


=== Is this going to use XMPP? ===


The presence channel to AppServices will have an XMPP option. It's useful to remember that Mozilla Presence is in very early stages at this moment. Worrying about the exact implementation is a detail that we're not addressing yet as we build some prototypes to test ideas out and prove the overall concept is worthwhile.


<!--
=== Shouldn't Mozilla have a way for me to see my contacts online? ===
==API Reference/Documentation==
=== Data Schema ===
<i>How will data be stored</i>
=== API ===
<i>How to call the data</i>
==== <i>method</i> <i>URI</i> ====
<i>description</i>


Arguments <i>argument descriptions</i>
Nowadays, peoples' personal connections are spread across multiple online services (Facebook, Google+, Skype, etc). These services usually already have done the work of ensuring both people want to see each other's presence and have ways to facilitate a conversation. All they need is a way to be aware of a users presence when their app might be closed or suspended (on a phone). By serving as the underlying plumbing notifying AppService's when users are online, Mozilla Presence avoids having to try and change users expectations about where their 'friends' are and can facilitate new social interaction applications that need presence data.
Returns: <i>returned contents</i>
-->


==Platform Requirements==
==Platform Requirements==
Line 462: Line 495:


==Code Repository==
==Code Repository==
<i>Links to the published code bases</i>
 
Repository: https://github.com/mozilla-services/presence
 
Diagrams: https://github.com/mozilla-services/presence-graffles
 
==Release Schedule==
==Release Schedule==
<i>Predicted code delivery dates</i>
 
===Prototype===
 
Server-side implementation:
 
* Allows AppServices to send LiveNotifications
* Sends AppServices presence stanzas
* Holds WebSocket connection to devices
* Sends LiveNotifications to devices
* Allows a device when connecting to toggle what AppServices should have presence stanzas relayed
 
Client-side implementation:
 
* Settings screen to manage
** Applications that can use Presence (On/Off toggles)
** Online - Away - Offline sliders to set how much idle is away vs. offline
** Custom status message
** Custom away message (if additional info should accompany it)
* LiveNotifications pop-up with Accept/Dismiss button
* Background service that sends pings, accepts LiveNotifications
 
===Production V.1===
 
Everything in the Prototype, designed for scale, in addition:
 
* Possibly a QUIC-derived UDP-based device-presence channel
* XMPP interface for AppServices <-> Presence
* FxA Integration for device user (Requires https://wiki.mozilla.org/Identity/Firefox_Accounts/SSO)
* Developer Registration page to acquire Presence Application ID, linked to from the Developer page in Marketplace


=QA=
=QA=

Latest revision as of 18:50, 11 March 2014

Last updated: 2014/03/11
Draft-template-image.png THIS PAGE IS A WORKING DRAFT Pencil-emoji U270F-gray.png
The page may be difficult to navigate, and some information on its subject might be incomplete and/or evolving rapidly.
If you have any questions or ideas, please add them as a new topic on the discussion page.

Presence

Overview

Presence is a proposed Cloud Service that tracks a Firefox OS device's Internet connectivity status as online, offline or unavailable by the device's Firefox Account. A Firefox OS Web App may request permission on behalf of its publisher to read status. Once approved, the publisher may poll the Presence service and, once the device is back online, push messages to the Web App.

See #Architecture Overview for more details.

Project Contacts

Principal Point of Contact - Tarek Ziade tziade@mozilla.com


Team

Cloud Services

  • Tarek Ziade tziade@mozilla.com
  • Ben Bangert bbangert@mozilla.com
  • Robert Lord rlord@mozilla.com
  • Firefox Account Engineer - TBD

Firefox OS

  • Fabrice Desré fabrice@mozilla.com

Presence on other Mobile Platforms

Presence on iOS

In iOS >= 7.x, applications that want to provide a presence feature can keep a socket opened in the background even if the application is not running anymore in the foreground.

The feature is called setKeepAliveTimeout (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplication_Class/Reference/Reference.html#//apple_ref/occ/instm/UIApplication/setKeepAliveTimeout:handler:) and will give the app the ability to register a handler that will be called periodically to check on the socket connection. Only approved VOIP apps are allowed by Apple to always keep a socket alive and not be terminated. Apple is very discerning about which apps get to use this functionality.

The handler has a limited time to do it (max 10 seconds) but this is enough to handle presence for the user by interacting with a server.

The Apple Push Notification Service https://en.wikipedia.org/wiki/Apple_Push_Notification_Service is also often used by applications to keep a connection opened on a server to receive push notifications. That's comparable to the Simple Push service Mozilla has added in Firefox OS.

Therefore, building an application with device-level presence on an iOS device is doable but requires the publisher to maintain one or several connections per user opened all the time and very few applications qualify for VOIP status.

Presence on Android

Like iOS, Android provides features to run some services in the background, see http://developer.android.com/guide/components/services.html

However, the service can be killed when the memory becomes low, and if TCP/IP is used it can be hard to have a reliable service.

Google also provides a "Google Cloud Messaging" (GCM) service - http://developer.android.com/google/gcm/index.html That provides similar features than Simple Push, to push notifications to users.

There's also a new feature called GCM Cloud Connection Server - (CSS) http://developer.android.com/google/gcm/ccs.html - that allows applications to communicate with the device via XMPP and on the client side "Intent Services". The app and the devices interact with CSS, which relays the messages back and forth.

There's a full example on that page, of a Python server interacting with the GCM service to interact with users.

The architecture is quite similar to what we want to build with Mozilla Presence since GCM acts as an intermediary between the app server and the device.

However, CSS is a neutral messaging relay and does not keep track of users online status. It sends back and forth what the server and the device have pushed in the pipe.

So it's still up to the app to leverage this service to keep track of connected devices to get device-level presence.

if we decide not to build presence, maybe we would just need to build that relay to make sure we offer FFOS apps the ability to implement presence the right way, like what Google provides on Android

XXX stuff to dig: can we use CSS with BOSH or with websockets

Goals

Phone UI for users to:

  • see at a glance and manage what applications they granted presence access to.
  • see lively notifications and act on them or ignore them.
  • manage how much idling is considered to be 'online' vs. 'away' vs. 'offline'
  • set custom status updates

Mozilla Cloud Services run system that:

  • allows a user to authorize an AppService access to the users presence
  • sends notifications to the users device that they can act on
  • sends user presence updates to authorized AppServices

Note: Lively notifications are different than SimplePush style Notifications in that they can require immediate action else they'll become stale, like a missed phone call.

The project will be a success if an application registered with Mozilla Cloud Services is able to reach out to users that are "online" (active on their phone or desktop but with the app not running) via Mozilla Presence.

Use Cases

See Detailed Use Cases.

Requirements

  • List of requirements

Get Involved

Documents so far

Services Presence Etherpad

Identity Presence Etherpad

Presence Meeting Wiki

Meetings

We try to meet every Thursday at 10:00 Pacific Time

For mozilla employees, we meet in the "Services" vidyo room, and use IRC channel #presence-wg (irc.mozilla.org)

For participants outside of mozilla, you can call into the meeting using the following numbers:

  • Phone (US/Intl): 650 903 0800 x92 Conf: 98616#
  • Phone (Toronto): 416 848 3114 x92 Conf: 98616#
  • Phone (US): 800 707 2533 (pin 369) Conf: 98616#

Please mute yourself with '* 1' upon joining to prevent needless noise and feedback. You can unmute yourself with '* 1' again to speak.

Meeting Notes

https://etherpad.mozilla.org/presence-meeting-20140311

Services/Roadmaps/Presence/Meetings/notes_20131014

Services/Roadmaps/Presence/Meetings/notes_20131031

https://etherpad.mozilla.org/presence-2013-11-26

Design

Points of Contact

Services Engineers:

  • Ben Bangert bbangert@mozilla.com
  • Tarek Ziadé tarek@mozilla.com

Architecture Overview

There are two levels of presence:

1/ app-level presence

  • online: you are connected in the app, and using it
  • offline: you are disconnected from the app

2/ device-level presence.

  • online : you are using your FXOS phone or your desktop browser
  • offline: you are not on your FXOS phone or your browser

Sometimes you might be online in 1/ or 2/ and not wishing other users to know about it. And you also might want to appear online for app B but not for app C.

1/ is solved by every application. they all have their ad-hoc system, their social graph, rosters, contacts, etc. Large social networks don't care as much about 2/ because they would prefer you to use *only* their application for talking to your friends. By solving 2/, we can enable non-dominant social/communication applications to get useful presence information they can act on.

Mozilla Presence acts as a trusted intermediary between the user's device (solving 2/) and the applications the user has allowed to see their presence, as well as a short-lived notification system for applications to engage available users.

PresenceOverview.jpg

Channel communication overview:

MPChannels.jpg

Terminology

AppDeveloper
A developer that creates applications which may or may not have server-backed resources.
AppService
An Internet-accessible server that an application talks to. For example, Facebook's locally installed application talks to Facebook's API server to get data. The Facebook API server in that case is the AppService as it acts as a service to the application.
Application
A website application that might run locally on a device with or without needing to talk to an AppService.
FxAID
A Firefox Accounts user ID.
Device Presence Channel
A channel of communications between a phone/browser device and Mozilla Presence that carries live notifications from Presence and presence data to Presence.
AppService Presence Channel
A channel of communication between Mozilla Presence and an AppService that carries presence updates for users sharing their presence with the AppService and live notifications from the AppService to be delivered to a PUID.
LiveNotification
A live notification is an alert requiring a response within a set period of time (5 seconds up to several minutes) before its considered 'missed' and stored on the device separately to indicate it can no longer be acknowledged. A response is considered acknowledgement and switches the user to the appropriate application to act on the LiveNotification.
Presence
For our purposes the definition of presence definined by XMPP also applies, but in our case 'contacts' happen to be AppServices that the presence is broadcast to. See http://xmpp.org/rfcs/rfc6121.html#presence-fundamentals
PUID
A Presence Unique Identifier. Every AppService authorized by a user to see presence updates will be assigned a PUID that it should store and associate with the user (who may or may not be logged into the application).

API Reference/Documentation

The Presence service has several functions:

  1. Device Channel to Mozilla Presence - let a user update her online status and set a custom status message
  2. Applications registration - let a developer register an application
  3. Applications permissions - let a user manage applications access to their presence
  4. Status updates - let an application receive status updates
  5. Live Notifications - let an application send a live notification and a user receive it.

1. Device Channel to Mozilla Presence

Mozilla Presence provides a secured web socket endpoint at wss://presence.services.mozilla.com/presence for devices to connect to.

The user may connect to the socket using a valid FxA (which will entail a BrowserID Assertion per FxaSSO), and send status updates.

The data must be sent in JSON and is based on a simple protocol where a first request must be made to create a new session. Each subsequent request is a status update. The server or the user can disconnect from the socket at any time and for any reason. In that case the session is lost and a new session must be initiated.

Session Request

Example of a session request:

   {'type': 'connect',
    'application_ids': [421, 492, 9592, 391],
    'assertion': 'valid persona assertion'}

where:

  • assertion is a valid persona assertion
  • type is the type of request. in that case "connect"
  • application_ids is the list of applications IDs presence updates should be sent to.

The application_ids field is used because Mozilla Presence does not retain a list of applications authorized to see updates. This data is kept only on the phone. As a result, the device must indicate what application ID's presence data should be sent to when connecting.

The server validates the assertion by sending it to a persona/fxaccount verifier, and if valid, creates a unique session id and sends it back to the cient.

Example:

  {'result': true, 'session_id': '61539351-1f02-4b62-a136-205000ece41a'}

In case there's an issue, like an invalid assertion, the server will send back a request with a result flag set to false, an errno field with an error code (to be documented) - and an error message in the reason field.

Example:

  {'result': false, 'errno': 34, 'reason': 'Invalid assertion'}


Status Update Request

Once the session is set, the client can send status updates.

Example:

   {'type': 'status',
    'session_id': '61539351-1f02-4b62-a136-205000ece41a'
    'status': 'online'}

where:

  • session_id the session ID
  • type is the type of request. in that case "status"
  • status the presence status. The value must be one of "online", "offline", "unavailable".

In case the device wants to send a status update to a specific subset of applications, it can use the 'application_ids' key on a status update request, it will override the value set on a visibility call, just for that call.

Example:

   {'type': 'status',
    'session_id': '61539351-1f02-4b62-a136-205000ece41a'
    'application_ids': [421, 391],
    'status': 'offline'}

For every status request received, the server sends back an ACK message.

Example:

  {'result': true}

In case of an error, the server will send back an extra 'errno' field with an error code (codes to be documented) and an optional 'reason' message.

Example:

  {'result': false, 'errno': 34, 'reason': 'Assertion expired'}

The error codes have to be documented, but in case the errno value is a negative value, the session is lost and the client has to recreate a new one.

The user can send as many updates as it wants, but the server can ask it to slow down with a specific error code (codes to be documented)

The server or the user can disconnect from the socket at any time and for any reason. The number of socket connections is limited to one connection per device and per email.

2. Applications registration

An App developer can register a new application into Mozilla Presence

An application is defined by:

  • a domain
  • an email
  • a name
  • a description

Registering a new application is done in 3 steps

  1. validation of the domain ownership
  2. attribution of a unique application ID
  3. activation of presence notifications

Domain Ownership Validation

Mozilla Presence provides a web page at https://presence.mozilla.com/myapps where an application developer can connect by logging in with her persona account.

Once logged in, the developer can fill a form with a domain, name and description of the application to register.

Mozilla Presence generates a unique key of 1024 characters, the developer needs to place in this URL: http://<domain>/__presence in a plain/text file that can be reached pubicly.

Once the key is placed, the developer can hit a Verify button. Mozilla Presence will then visit http://<domain>/__presence to verify that the domain is owned by the developer.

Application ID

Once the domain has been verified, Mozilla Presence generates a unique id for the application, and displays an entry point the developer will need to visit to get status updates.

The entry point is in the form of ws://<node>.presence.mozilla.com/<appid> and is a web socket the developer's application may connect to, in order to receive status updates.


Activation of presence notifications

To activate the status update stream, the app developer needs to visit https://presence.mozilla.com/myapps and click on the Activate button located besides the application name (a developer may have several apps.)

By clicking on Activate, an API key is generated for the application and displayed besides the application. An API key is a string of 1024 chars.

This API key has to be used by the application in order to get status updates.

Getting status updates is done by connecting to the websocket located at ws://<node>.presence.mozilla.com/<appid> with the API key.

Example:

 {'key': 'e3b0c44298fc1c149afbf4c8....996fb92427ae41e4649b934ca495991b7852b855'}

Once connected, the application will receive status updated as they happen, in the form of a list. Each element is composed of an uid and a status.

Example:

 [{'UID': 2123131, 'status': 'online'},
  {'UID': 12345, 'status': 'offline'}
 ]

Where UID is a user identifier as described in the next section.

3. Applications permissions

Granting presence access requires user interaction to indicate to Mozilla Presence that the user wants an AppService to see their presence information. In the event that the user might have multiple identities or profiles on a single AppService, a user-meaningful string should be included in the authorization request to Mozilla Presence.

Here's what a users interaction with an application to grant it presence might look like: WPPhoneOverview.jpg

The following steps occur in this flow:

  1. User clicks Authorize button
  2. User acknowledges the AppService they're granting and allows it
  3. User is redirected back to the AppService

Technical Details

The page URL the Authorize buttons posts to is:

https://<node>.presence.mozilla.com/<appid>/grant?redirect=<url>&id=<userstring>

Where <node> and <appid> are values known by the registered application, <url> is the url to redirect back to, and <userstring> is the user-meaningful string indicating that should usually be their login name (or something short and meaningful to distinguish multiple identities on a single AppService if applicable).

In the example above, the user Marge happens to be logged into BeerChat as 'Fred', so this identifier is attached during authorization so that when Marge manages her Presence she can see that she appears online as Fred to BeerChat.

The user is expected to already be signed into their Firefox Account in this example, otherwise they will need to first login to Prsence before seeing the authorization page.

Authorizing the AppService performs a POST on https://<node>.presence.mozilla.com/<appid> containing the redirect url and the answer.

If user has accepted, Mozilla Presence generates a unique ID (PUID) to identify the user in the context of the application.

The user then is redirected back to <url> with an encoded PUID in a <Presence-UID> header.

The application is responsible to store the PUID and associate it with the user.

The redirect flow looks like this: WPAuthInteraction.jpg

5. Status updates

When Mozilla Presence gets a status update from someone, it looks up all the registered applications and sends to the one that are activated to see the updates.

Since statuses are fetched via a web socket at ws://<node>.presence.mozilla.com/<appid>, each application gets its own messaging queue that is dequeued when the application is connected via the web socket. A status message is dropped from the queue if not consumed within an hour.

6. Live notifications

Live notifications are a way for applications to reach out online users that are not active in the application. It can be used to give the opportunity to the user to react when something is happening in the application.

Examples:

  • ChatRoom: Your nick was used in a message sent to the room.
  • ChatRoom: Someone wants you to join the room.


AppService sends a notifications to Mozilla Presence via a POST request :

  POST https://<node>.presence.mozilla.com/<appid>/notification
  
  [{'UID': 'userid',
   'message': '<message>',
   'action': '<url>'},
   ...
  ]

AppService can send notifications by batches.

Details:

  • userid: the user ID provided by the presence system.
  • message: a message to display to the user. Limited to 512 chars.
  • action: an action that will happen on the device if the user agrees - it can be an url to visit or an application to run. Limited to 512 chars.

Mozilla Presence pushes the message into a FIFO queue. There's one queue per user id + app id combination, and its size is limited to 100 items. When the queue is full, the oldest item is dropped before the new item is added. For each item, it appends in the mapping the appid value.

Once the message is stored, the service sends back an ack message to AppService, with the current size of the queue:

  {'result': 'OK',
   'queue_size': <size>}

Receiving the ack is a guarantee that the message was stored on the server, but is not a guarantee that it was delivered to the user.

If the user is connected to Mozilla Presence via the Presence daemon, it gets all the items from the queue and the queue is purged.

The Presence daemon on the device is responsible to dispatch the messages to the different applications:

  • on desktop, it displays a notification with the url contained in the action for the user to click
  • on mobile, it displays a notification with a link to run the app XXX

The application has no feedback on whether a notification was seen by the user.

FAQ

To help people get up to speed faster and prevent backtracking, commonly asked questions by those getting involved are listed here with an answer.

Is this going to use XMPP?

The presence channel to AppServices will have an XMPP option. It's useful to remember that Mozilla Presence is in very early stages at this moment. Worrying about the exact implementation is a detail that we're not addressing yet as we build some prototypes to test ideas out and prove the overall concept is worthwhile.

Shouldn't Mozilla have a way for me to see my contacts online?

Nowadays, peoples' personal connections are spread across multiple online services (Facebook, Google+, Skype, etc). These services usually already have done the work of ensuring both people want to see each other's presence and have ways to facilitate a conversation. All they need is a way to be aware of a users presence when their app might be closed or suspended (on a phone). By serving as the underlying plumbing notifying AppService's when users are online, Mozilla Presence avoids having to try and change users expectations about where their 'friends' are and can facilitate new social interaction applications that need presence data.

Platform Requirements

What are the things this needs (OS, language, databases, etc.)?

XXX explain here how simple push is running on the different platforms - Firefox OS : built-in, what about Desktop ? a separate service that wakes up Firefox ?

Libraries Required

List of external project dependencies. (Stuff that's not pulled in via the installation script)

Code Repository

Repository: https://github.com/mozilla-services/presence

Diagrams: https://github.com/mozilla-services/presence-graffles

Release Schedule

Prototype

Server-side implementation:

  • Allows AppServices to send LiveNotifications
  • Sends AppServices presence stanzas
  • Holds WebSocket connection to devices
  • Sends LiveNotifications to devices
  • Allows a device when connecting to toggle what AppServices should have presence stanzas relayed

Client-side implementation:

  • Settings screen to manage
    • Applications that can use Presence (On/Off toggles)
    • Online - Away - Offline sliders to set how much idle is away vs. offline
    • Custom status message
    • Custom away message (if additional info should accompany it)
  • LiveNotifications pop-up with Accept/Dismiss button
  • Background service that sends pings, accepts LiveNotifications

Production V.1

Everything in the Prototype, designed for scale, in addition:

  • Possibly a QUIC-derived UDP-based device-presence channel
  • XMPP interface for AppServices <-> Presence
  • FxA Integration for device user (Requires https://wiki.mozilla.org/Identity/Firefox_Accounts/SSO)
  • Developer Registration page to acquire Presence Application ID, linked to from the Developer page in Marketplace

QA

Points of Contact

Engineer - Name contact@info

Test Framework

Security and Privacy

Fill out the security & privacy bug template: https://bugzilla.mozilla.org/form.moz-project-review (https://wiki.mozilla.org/Websites/Kick-Off_Form)

For security reviews, there's: https://wiki.mozilla.org/Security/ReviewProcess

Points of Contact

Questionnaire Answers

1.1 Goal of Feature

2. Potential Threat Vectors and Mitigation Points

Review Status

Bugzilla Tracking # - see https://wiki.mozilla.org/Security/Reviews

Issues and Resolutions

Operations

Points of Contact

Deployment Architecture

Bugzilla Tracking # -

Escalation Paths

Lifespan Support Plans

Logging and Metrics

Points of Contact

Tracking Element Definitions

Data Retention Plans

Dashboard URL

Customer Support

Points of Contact

Sumo Tags

Review Meeting