Skip to main content

Project Setup

Install dependencies

Swift Package Manager

Once you have your Swift package set up, adding Alamofire as a dependency is as simple as adding it to the dependencies value of your Package.swift.

dependencies: [
.package(url: "https://github.com/swarm-cloud/SwarmCloudKit.git", branch: "main")
]

Carthage

Add the dependencies to the Cartfile:

binary "https://cdn.swarmcloud.net/apple/SwarmCloudKit.json" ~> 3.6.0
binary "https://cdn.swarmcloud.net/apple/Datachannel.json" ~> 1.0.232

Then run:

carthage update --use-xcframeworks --cache-builds

This will build each one or download a pre-compiled XCFramework.


In your application target's General settings tab, under Frameworks, Libraries, and Embedded Content, drag and drop each XCFramework you want to use from the ***Carthage/Build*** folder.

CocoaPods

To install dependencies into your Xcode project using CocoaPods, specify it in your Podfile:

target 'TargetName' do
# Uncomment the next line if you're using Swift
# use_frameworks!
pod 'SwarmCloudKit', '~> 3.0'
end

Then, run the following command:

$ pod install

Manually

Download Pre-compiled XCFramework

Copy the framework

Unzip the files, then drag and drop SwarmCloudKit.xcframework and datachannel_wrapper.xcframework into your Xcode project on your application target's General settings tab, under Frameworks, Libraries, and Embedded Content.

Integration

Include

Import SwarmCloudKit in AppDelegate.m:

import SwarmCloudKit

Initialize P2pEngine

Initialize P2pEngine in AppDelegate.m:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let config = P2pConfig(
trackerZone: .Europe // Set HongKong or USA if you changed zone
)
P2pEngine.setup(token: YOUR_TOKEN, config: config) // replace with your own token
return true
}

YOUR_TOKEN represents your Customer ID; replace it with the token obtained from your console; click here for more information.

Usage

When initializing an AVPlayer (or any other video player) instance, pass the URL through the P2P Engine before passing it to the player:

let parsedUrl = P2pEngine.shared.parseStreamUrl("https://your_stream.m3u8")
_player = AVPlayer.init(url: URL(string: parsedUrl)!)

That's it! The SDK should now be integrated into your app.

tip

For macOS development:


Xcode enables sandboxing by default on new applications. Ensure your application's entitlements allow incoming and outgoing connections by checking the respective checkboxes in the Network section.

Demo

A complete example project can be found here

Troubleshooting Steps when P2P doesn't work

See here