Managing State Transitions in Native Applications
To improve iOS and Android player's experience across application transitions, such as background to foreground or Wi-Fi to cellular networks, follow the steps outlined below.
The 2024 iOS and Android SDKs have improvements to help simplify handling state and token management.
Deprecate Custom Transition Management
Deprecate any code that is handling background/foreground transitions (calling pcast stop/shutdown) and allow
the SDK to manage these transitions.
The SDK should manage these transitions even in cases where network switches occur (e.g., between Wi-Fi and cellular)
when the app is in the background.
Token Management
The SDK should handle state transitions and resume stream playout if the token is still valid (assuming there is an active stream publishing).
If the token is expired, the client app must re-join the channel with a new valid token.
To handle authentication and the channel subscriber callback, implement both of the following:
getObservableAuthenticationStatus
and a function on subscriberCallback
.
getObservableAuthenticationStatus
The client will need to observe the observable getObservableAuthenticationStatus
and if the value
changes to unauthenticated react by retrieving a new valid token as documented for
iOS and
Android.
subscriberCallback Function
For the case of the channel subscriber, there should be a function set on the subscriberCallback
, and
the SDK will call that when the token is not valid for the subscription (in most cases, will be due to
expiration) as documented for iOS and
Android.
The view channel subscribe callback status that may be returned and recommended actions by the client application. These are documented for iOS and Android, and are shown in the table below for convenience.
Status Code | Description & Recommended Action |
---|---|
PhenixRequestStatusOk = 200 | Success - No further action required |
PhenixRequestStatusNoStreamPlaying = 299 | No stream available to subscribe to - Check stream is publishing or wait for presenter to join |
PhenixRequestStatusBadRequest = 400 | Missing or invalid arguments - Re-join with fixed parameters/new data |
PhenixRequestStatusUnauthorized = 401 | New token required - Re-join with new valid token |
PhenixRequestStatusConflict = 409 | Request conflicts with the current state of the resource - Log error for further investigation |
PhenixRequestStatusGone = 410 | Resource referenced is no longer available - Log error for further investigation |
PhenixRequestStatusNotInitialized = 412 | PCast not initialized - Dispose and re-initialize SDK |
PhenixRequestStatusNotStarted = 417 | PCast not started - Dispose and re-initialize SDK |
PhenixRequestStatusRateLimited = 429 | Request was rejected due to current load - Retry with exponential back-off strategy |
PhenixRequestStatusUpgradeRequired = 499 | Upgrade is required - Log error for further investigation |
PhenixRequestStatusFailed = 500 | General error - Retry. If fails 3x, log error for further investigation |
PhenixRequestStatusCapacity = 503 | Capacity error - Retry with exponential back-off strategy |
PhenixRequestStatusTimeout = 504 | Timeout error - Retry. If fails 3x, log error for further investigation |
PhenixRequestStatusNotReady = 599 | Resource is not ready yet - Retry with exponential back-off strategy |
Other Subscription Issues
Unrecoverable Error
All other issues should be handled by the unrecoverable error callback, as defined for iOS and Android. If an unrecoverable error is returned, unfortunately the app will need a complete fresh restart (dispose & re-initialize the SDK) to recover.
Extended Backgrounding
For players that have backgrounded the app for extended durations, the app should be fully reinitialized (dispose & re-initialize the SDK) for best results.