iOS SDK Overview - PhenixRTS Docs
iOS SDK Overview
The iOS SDK is part of the Phenix Apple SDK. Its APIs are split into two main categories: Express and Low-Level.
We recommend that you start with the Express API as this:
- Simplifies integration
- Automatically recovers from stream failures
- Handles edge cases such as network reconnects
If you find that the Express API doesn't work for you, take a look at our Lower Level API.
The current release of the Phenix iOS SDK supports a token-based workflow and a wide variety of other features.
Setup
The Phenix SDK is provided as
General
Refer to this article for details on managing state transitions.
Debugging
In order to identify issues it can be helpful to see what is happening at the Phenix SDK level. Phenix logs are disabled by default in the Xcode console. To enable them, set the following environment variable:
Name: PHENIX_LOGGING_CONSOLE_LOG_LEVEL Value: Debug
To reduce output, you can change the value to Info or Warn for instance. You will only be able to view these logs when either running in the simulator or with a device attached to Xcode.
You can also retrieve the Phenix SDK logs programmatically using the collectLogMessages PCast™ API.
import PhenixSdk
let pcast: PhenixPCast = ... // previously obtained
pcast.collectLogMessages({ (pcast: PhenixPCast?, status: PhenixRequestStatus, messages: String?) in
guard let messages = messages, status == .ok else {
// Handle error
return
}
let messagesArray = messages.components(separatedBy: "\n")
for message in messagesArray {
// Do something with 'message'
}
})
Notes:
messagesstring contains the most recent as well as initial logs (since your app started)- Each log entry in the string is separated by a newline
- Log entries are stored chronologically, newest logs last
Observable
Observe value changes. Important differences for Phenix SDK observables:
- There is always an initial value (which can be
nilfor some objects) - Only if observed value changes will subscribers get notified
PhenixObservable
| Name | Signature | Returns | Description |
|---|---|---|---|
| subscribe | (onChanged) | PhenixDisposable | See Subscribe to an Observable |
| getValue | () | varies | See Get Observable Value |
| setValue | (value) | void | See Set Observable Value |
Subscribe to an Observable
Receive a notification every time the observable value changes.
@import PhenixSdk;
PhenixObservable<NSString*>* observable = ...; // previously obtained
id<PhenixDisposable> subscription =
[observable subscribe:^(PhenixObservableChange<NSString*>* change) {\
NSString* newStringValue = change.value;\
// Do something with newStringValue\
}];
// Releasing subscription will cancel it:
subscription = nil;
Get Observable Value
Synchronous method allowing retrieval of currently set value. Thread safe.
@import PhenixSdk;
PhenixObservable<NSNumber*>* roleObservable = ...; // previously obtained
PhenixMemberRole role = (PhenixMemberRole)[roleObservable getValue].intValue;
PhenixObservable<NSString*>* stringObservable = ...; // previously obtained
NSString* stringValue = [stringObservable getValue];
Set Observable Value
Change the observable value. This will trigger notifications on all subscribers.
@import PhenixSdk;
PhenixObservable<NSNumber*>* roleObservable = ...; // previously obtained
[roleObservable setValue:[NSNumber numberWithInt:PhenixMemberRolePresenter]];
PhenixObservable<NSString*>* stringObservable = ...; // previously obtained
[stringObservable setValue:@"new value"];
Override Playout Delay
Example Code for overriding the playout delay via a PhenixMediaStream object
import PhenixSdk
class SomeClass {
private var currentRendererPlayoutDelayOverride: PhenixDisposable?
private var currentRenderer: PhenixRenderer?
private func setPlayoutDelayOverrideFor10Seconds() {
let mediaStream: PhenixMediaStream = ...
self.currentRenderer = mediaStream.createRenderer()
let playoutDelay: TimeInterval = 0.9
self.currentRendererPlayoutDelayOverride = self.currentRenderer?.overridePlayoutDelay(playoutDelay)
DispatchQueue.main.asyncAfter(deadline: .now() + 10) {
self.currentRendererPlayoutDelayOverride = nil
}
}
}
The playout delay represents the amount of time by which audio and video are delayed when content is rendered by a subscriber. It is necessary to handle network-related fluctuations.
Parameters
| Name | Type | Description |
|---|---|---|
| desiredPlayoutDelay (required) | TimeInterval | Desired playout delay |
Returns
| Type | Description |
|---|---|
| PhenixDisposable | Ensures override is kept in effect |