Skip to content

Commit

Permalink
Update to 1.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
airtime-jenkins committed Aug 5, 2022
1 parent 25d79fb commit d8e780b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 21 deletions.
27 changes: 27 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "AirtimeMedia",
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "AirtimeMedia",
targets: ["AirtimeMedia", "Bakersfield"]),
],
dependencies: [],
targets: [
.binaryTarget(
name: "AirtimeMedia",
url: "https://airtime-eng-asilomar-libs.s3-accelerate.amazonaws.com/jobs/airtimemedia/asilomar/release%252F1.4/6/AirtimeMedia.xcframework.zip",
checksum: "5a9f5873192881e329597b3a17cb80c0d48e45fe3f185c03c866aba017046863"
),
.binaryTarget(
name: "Bakersfield",
url: "https://airtime-eng-asilomar-libs.s3-accelerate.amazonaws.com/jobs/airtimemedia/asilomar/release%252F1.4/6/Bakersfield.xcframework.zip",
checksum: "49b4e005064bc797c2901582efa3a66d4bf0db0fd6f9bfe5b82c415403eabd37"
),
]
)
86 changes: 65 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@

# ✨ Airtime Media SDK - Early Access ✨
# ✨ Airtime Media SDK ✨

## Installation

1. Open an Xcode Project that you would like to add real-time capabilities to.
2. Select `File->Add Packages...`.
3. At the bottom of the Package Manager window, select `Add Local...`.
4. Select the directory containing the accompanying `Package.swift` and then select `Add Package`.
5. Under the `Link Binary with Libraries` build phase of your app target, add the `AirtimeMedia` library.
6. In order to publish through `LocalStream`'s, you need to provide a microphone usage description in your Info.plist
3. In the search bar, put in the URL for this repository (https://github.com/airtimemedia/AirtimeMedia-iOS)
4. Select the dependency rule that matches the version you want to use (i.e. if you want to use version 1.4.3, put in "Exact Version" as your dependency rule and enter 1.4.3 in the version box).
5. Select the project you want to add the package to.
6. Press "Add Package".
7. That's it! The Framework should be automatically linked to the project you selected.

## Limitations

- Builds for ARM iOS and x86 Simulator.
- Bitcode must be **disabled**

## Usage
Please consult the included `AirtimeMedia.doccarchive` for further details on the precise public API, e.g. `open AirtimeMedia.doccarchive/`.

### Creating a session access token
A session access token is the literal key for joining a channel. Using your Airtime provided secret application token, you can use the following `curl` command to generate a session access token:
To see specific API details, you can right click on any AirtimeMedia member within XCode and select "Jump to Definition".

### Creating a session auth token
A session auth token (SAT) is the literal key for joining a channel. Using your Airtime provided secret application token, you can use the following `curl` command to generate a session access token:
```
curl -X POST -H "authorization: Bearer <secret application token>" -H "Content-Type: application/json" -d '{"token_lifetime":86400, "user_id":"<Your Unique User ID>", "channel_id":"<The channel ID to join>","services":{"media":{"publishers_limit":10,"allow_publish_audio":true}}}' https://yosemite.prod.airtime.com:443/session_access
```

You then provide the generated token to the Channel as an initialization parameter. Note that the token will only work for joining a Channel with the specific `channel_id` specified in the token, and the `user_id` of the token must be unique.
This will most likely be done by your backend service.

Your application will then request the SAT from your backend service and it will be provided to the Channel as an initialization parameter. Note that the token will only work for joining a Channel with the specific `channel_id` specified in the token, and the `user_id` of the token should be unique.

### Creating a channel
The `AirtimeMedia` module exposes a singleton, `Engine.sharedInstance` that is the top level object to interact with the SDK. It can produce `Channel` objects.

A `Channel` object is your connection to a real time voice call. You can think of “joining” a `Channel` as an act similar to tuning into a radio frequency on a walkie-talkie. Instead of a radio frequency, a `Channel` tunes into a channel ID.

Once you create a channel through the `Engine`'s `joinChannel` function, you must retain the resulting object to stay connected. The channel will not be able to receive remote streams until the `start` method is called.
Once you create a channel through the `Engine`'s `joinChannel` function, you must retain the resulting object to stay connected. The channel will not be able to receive remote streams until the `join` method is called.
```Swift
// Swift
import AirtimeMedia

let token = "The token you generated"
let token = "The SAT token from your backend"

// Keep this object around!
let channel = Engine.sharedInstance.createChannel(token: token)
let channel = Engine.sharedInstance.createChannel(sessionAuthToken: token)
// Check if the channel was successfully created
guard let channel = channel else { fatalError() } // Handle error case

Expand All @@ -53,10 +56,10 @@ channelStorage.channel = channel
// Objective-C
@import AirtimeMedia

NSString *token = @"The token you generated";
NSString *token = @"The SAT token from your backend";

// Keep this object around!
ATMChannel *channel = [ATMEngine.sharedInstance createChannelWithToken:token];
ATMChannel *channel = [ATMEngine.sharedInstance createChannelWithSessionAuthToken:token];

// Check if the channel was successfully created
if (channel == nil) {
Expand All @@ -71,8 +74,42 @@ channelStorage.channel = channel;
```
### Leaving a Channel
A Channel is left when all references to the Channel go out of scope, or if the `leave()` method is called on the Channel. `leave()` can be called on the Channel even before the Channel is joined. Once a Channel is left, it and all its streams will be terminated permanently, rendering the Channel object invalid and disposable.
A Channel is terminated when all references to the Channel go out of scope, if an unrecoverable error occurs on the Channel, or if the `leave()` method is called on the Channel. `leave()` can be called on the Channel even before the Channel is joined. Once a Channel is left, it and all its streams will be terminated permanently, rendering the Channel object invalid and disposable.
### Updating a Channel's Session Auth Token
A session auth token has a set expiration time and parameters. You must replace the Channel's SAT through its `sessionAuthToken` property before expiration or if you want to change user permissions. You will receive an interval-repeated notification from a joined Channel when it's SAT is nearing expiration.
```Swift
import AirtimeMedia
let channel: Channel
NotificationCenter.default.addObserver(self,
selector: #selector(channelSATNearingExpiry(_:)),
name: ChannelNotification.sessionAuthTokenNearingExpiry,
object: channel)
@objc func channelSATNearingExpiry(_ notif: NSNotification) {
let token = getNewAuthToken()
channel.sessionAuthToken = token
}
```
```objectivec
// Objective-C
@import AirtimeMedia

ATMChannel *channel;

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(channelSATNearingExpiry:)
name:ATMChannelNotification.sessionAuthTokenNearingExpiry
object:channel];

- (void)channelSATNearingExpiry:(NSNotification *)notif {
NSString *token = getNewAuthToken();
channel.sessionAuthToken = token;
}
```
### Receiving streams
While you are connected to a channel, you will be receiving remote streams automatically. These streams will appear in the `remoteStreams` property on your `Channel` object. To be notified about when streams are added and removed from this connected streams set, you can subscribe to the provided notifications.
```Swift
Expand Down Expand Up @@ -106,7 +143,7 @@ ATMChannel *channel;
name:ATMChannelNotification.remoteStreamWasRemoved
object:channel];
```
The notification's object will always be the channel whose `remoteStreams` set changed, and the `Notification` object parameter' `userInfo` dictionary will contain the specific remote stream that was added or removed.
The notification's object will always be the channel whose `remoteStreams` set changed, and the `Notification` object's `userInfo` dictionary will contain the specific remote stream that was added or removed.
```Swift
// Swift
Expand Down Expand Up @@ -176,7 +213,7 @@ ATMRemoteStream *remoteStream;
}
}
```
If a remote stream is terminated, you can check the termination reason on the `terminationCause` property of the `RemoteStream`. Once a remote stream is terminated, it will never revive, the `RemoteStream` object will no longer be valid, and the object will be removed from the corresponding `Channel`'s `remoteStreams` set property. Thus, if you no longer hold any strong references to the `RemoteStream` object, it will be destroyed.
If a remote stream is terminated, you can check the termination reason on the `terminationCause` property of the `RemoteStream`. Once a remote stream is terminated, it will never revive, the `RemoteStream` object will no longer be valid, and the object will be removed from the corresponding `Channel`'s `remoteStreams` set property. Thus, if you no longer hold any strong references to the `RemoteStream` object after that point, it will be destroyed.
#### Mute state
There are two properties that track a RemoteStream's mute state: `remoteAudioMuted` and `localAudioMuted`. The `remoteAudioMuted` property specifically represents whether the remote user has muted their stream or if the stream was administratively muted, whereas the `localAudioMuted` property represents whether or not the audio is muted only on the receiving end of the stream. You can observe changes to these properties with the `RemoteStreamNotification.remoteAudioMuteStateDidChange` and `RemoteStreamNotification.localAudioMuteStateDidChange` notifications.
Expand All @@ -189,8 +226,9 @@ The `voiceActivity` property of the RemoteStream indicates whether or not there
### Local streams
To send your own local audio to other channel members, you will need to make a `LocalStream`.
After starting, a `LocalStream` can be muted or unmuted. Muting is an asynchronous operation. To unmute a stream, behind the scenes we must verify with a server that the User has permission to unmute themself. On the other hand, a stream can always be muted immediately.
After starting, a `LocalStream` can be muted or unmuted. Muting is an asynchronous operation. To **unmute** a stream, behind the scenes we must verify with a server that the user has permission to unmute themself. On the other hand, a stream can always be **muted** immediately.
Notifications for a `LocalStream`'s mute state, voice activity, and connection state can all be observed. The notification names are found on the `LocalStreamNotification` class.
```Swift
// Swift
Expand All @@ -204,9 +242,12 @@ guard let localStream = localStream else { fatalError() } // Handle error case
// Start the local stream
localStream.start()
// Mute/unmute the audio
// Mute the audio
localStream.muteAudio(true)
// Unmute the audio
localStream.muteAudio(false)
// The local stream can be optionally retained or otherwise it can be accessed from the channel.
// When you wish to stop sending local audio, stop the local stream
Expand All @@ -229,9 +270,12 @@ if (localStream == nil) {
// Start the local stream
[localStream start];

// Mute/unmute the audio
// Mute the audio
[localStream muteAudio:YES];

// Unmute the audio
[localStream muteAudio:NO];

// The local stream can be optionally retained or otherwise it can be accessed from the channel.

// When you wish to stop sending local audio, stop the local stream
Expand Down

0 comments on commit d8e780b

Please sign in to comment.