Presence Has Shipped

– Identifying users who are active within your application, and may need help from your staff– Identifying users who are available to chat– Providing tools for users to flag their availability to chat

Presence addresses three questions:

1/ Is a user online?2/ Is the user available, busy or away?3/ When was the user last online?

How does it work?

Presence takes two inputs:

1/ Connection: Is the app connected to Layer’s Services2/ Status: A string sent by a client indicating the user’s status

Any change to these values should be quickly reflected in any application that is listening for changes to presence data. This data is currently available only through the Client APIs (iOS, Android and Web clients). The status has the following values:

Available: The user is connected and their status is set to available. This is the default status.

Busy: The user is connected and their status is set to busy

Away: The user is connected and their status is set to away

Invisible: The user is connected and have set their status to Invisible (Shows to this user as Invisible, and to all other users as being Offline)

Offline: The user is not connected

Who can see Presence

Layer provides a model and APIs for controlling which users follow which other users. Any user that you follow is a user for whom you will receive updates that change their Identity object. As status is a part of Identity, any changes to status can be seen by all users who follow that identity. If the person you follow wants to see your status back, they can follow you back. Layer currently assumes that any users in a conversation together are implicitly following one another, allowing them to each see one another’s status.

Understanding Status

Status values of “away” and “busy” at this time has no defined meaning to Layer. There is no automated detection that sets your status to “away” or “busy”; each app can decide for itself what sort of patterns of activity/lack of activity justify setting these status values. For example, your client might automatically set the user to “busy” before starting a phone call.

Any solution for automatically setting a user to “away” is typically only needed for web, and not for mobile clients. Why is that? Most mobile devices change apps or go to sleep after sufficient time has passed, and in so doing, will update the user to no longer being online.

Web browsers and mobile apps have fundamental differences in what it means to be put into the background. Best practice for a typical mobile app developer whose app has been put into the background is to minimize the system resources used in the background. Depending on the mobile client, a backgrounded app may flag you as offline within a few minutes of being moved to the background. On the web however, a tab that is in the background may still visible, and even if hidden may still be generating desktop notifications to announce new messages. What this means for presence is that a web user who leaves a tab open remains available, and can remain available for weeks to come.

Presence is a tool; and how best to use that tool for your business will depend a great deal on what you want presence to mean for your application. As such, Layer Clients do not have a hard coded concept of when to flag a user as Away. Are you away if the app is in the background? If the app hasn’t seen any user interface events in a while? If the app has desktop notifications perhaps the user never needs to be flagged as being away as they are always a popup and a click away from seeing new messages.

For your first iteration with presence, you may simplify things by limiting your application to using Available and Offline as the only statuses. Evolution of how you use presence will need to start factoring in what you want to achieve; “busy”, “away” and “invisible” are status values that you can set within your client to help achieve those goals.

Learn More

Take a look at our documentation for more information on how to integrate Presence into your Layer application. We can’t wait to see what you build with it.