Workflow: Monitoring Presence by Using the Oracle Radio WebSocket API
Subscribe the WebSocket connection to Radio presence changes and combine the event stream with a current presence snapshot.
Before You Begin
Open an authenticated WebSocket connection for an enabled Radio user. Presence results and updates are limited to Radio users in the authenticated user's Identity Domain.
Get and Monitor Presence
-
Follow Subscribing to Oracle Radio WebSocket Presence Updates to send
SUBSCRIBE_PRESENCE.{ "type": "SUBSCRIBE_PRESENCE" } -
Wait for
PRESENCE_SUBSCRIBED. Record the returned domain when it is present, and begin retaining eachPRESENCE_UPDATEevent in the order that the connection receives it. -
Follow Getting Oracle Radio WebSocket Presence to send
GET_PRESENCE. SupplyuserIdto request one user's presence, or omit it to list online users visible in the Identity Domain.{ "type": "GET_PRESENCE" } -
While the snapshot request is pending, continue retaining
PRESENCE_UPDATEevents. UsePRESENCEas the baseline for one supplied user identifier. UsePRESENCE_LISTas the online-user baseline whenuserIdis omitted. -
After installing the baseline, apply the retained
PRESENCE_UPDATEevents in receive order. Then apply each new event to its matchinguserId. An event can reportonline,offline, oraway. Its optionalchannelis a representative current channel, not a complete membership list. -
For each channel in
affectedChannelsthat your client displays and is authorized to access, refresh the user list withLIST_CHANNEL_USERS. An empty array requires no channel-list refresh. A user can leave one channel while remaining online through another session.
Handle Missing Updates and Reconnects
- If the service returns
ERROR, correct the request or connection state and repeat the applicable operation. - An interval without
PRESENCE_UPDATEcan mean that no visible presence changed. Follow Checking an Oracle Radio WebSocket Connection before treating the absence of updates as a failed connection. - After reconnecting, first repeat Subscribing to Oracle Radio WebSocket Presence Updates and wait for a new
PRESENCE_SUBSCRIBEDconfirmation. Retain updates, repeat Getting Oracle Radio WebSocket Presence for a current baseline, and then apply the retained updates before continuing with new events.