Firekast

firekast.io empowers live video streaming in few lines of code.

It’s easy, 100% documented and needs no video knowledge.

Prerequisites

Min iOS Deployment target: 8.0

Installation

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

use_frameworks!

target 'Your Target Name' do
  # First time install may be long, so please be patient :)
  # Set the same version name X.Y.Z. for both Firekast and VideoCore pod. Here 1.3.3.
  pod 'Firekast', :podspec => 'http://firekast.io/sdk/ios/v1.3.3/Firekast.podspec'
  pod 'VideoCore', :git => 'https://github.com/Firekast-io/VideoCore.git', :tag => 'fk-1.3.3'
end

Usage

Initialization

  1. Sign up and create an app on Firekast Dashboard.
  2. In your app Info.plist specify the reason for your app to access the device’s camera NSCameraUsageDescription and microphone NSMicrophoneUsageDescription.
  3. In your AppDelegate initialize the SDK with your Firekast app credentials.
// Swift
import Firekast

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Firekast.initialize(clientKey: "%ACCOUNT%", applicationId: "%APP%")
    return true
}
// Objective-C
#import "Firekast/Firekast-Swift.h"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [Firekast initializeWithClientKey:@"%ACCOUNT%" applicationId:@"%APP%"];
    return YES;
}

Live streaming

In your view controller, initialize a Firekast FKStreamer and call showCamera to start and display the device’s camera. To live stream you need first to request for a stream (requestStream), then call startStreaming whenever you are ready.

Call stopStreaming to… stop streaming 🤠. Remember to call this function in viewWillDisappear in case you user leaves the screen while streaming.

To access camera feature (flash, switch front/back, microphone) use the FKCamera object returned by calling showCamera.

@IBOutlet weak var container: UIView!
var streamer: FKStreamer!
var camera: FKCamera!

override func viewDidLoad() {
    super.viewDidLoad()

    streamer = FKStreamer(usecase: .portrait)
    camera = streamer.showCamera(.front, in: container)
}
streamer.requestStream { (stream, error) in
    guard let stream = stream {
        print("Request stream failed: \(error!)")
        return
    }
    self.streamer.startStreaming(on: stream, delegate: self)
}
streamer.stopStreaming()
// MARK: - FKStreamer Delegate
func streamer(_ streamer: FKStreamer, willStart stream: FKStream?, unless error: NSError?) {}
func streamer(_ streamer: FKStreamer, didBecomeLive stream: FKStream) {}
func streamer(_ streamer: FKStreamer, didStop stream: FKStream?, error: NSError?) {}
func streamer(_ streamer: FKStreamer, networkQualityDidUpdate rating: Float) {}

Push your live to other live streaming platforms simultaneously

Firekast allows to push your live stream to several Live Streaming Platform, such as Facebook or Youtube, simultaneously.

Defines the list of live streaming platforms where you want to push your live and request for a stream.

let media = [
        LiveStreamingPlatform.facebook(accessToken: "your-fb-access-token"),
        LiveStreamingPlatform.youtube(accessToken: "your-yt-access-token", title: "My Live with firekast.io")
]

streamer.requestStream(outputs: media) { (stream, error) in
    <#code#>
}

Play a stream

In your view controller, initialize a Firekast Player and display it by calling show. Then call play with the id of the stream you want to watch.

Call stop if needed.

@IBOutlet weak var container: UIView!
var player: Player!

override func viewDidLoad() {
    super.viewDidLoad()

    player = Player()
    player.show(in: container)
}
player.play(streamId: "dot38gxkr2zkt9m18", delegate: self)
player.stop()
// MARK: - FKPlayer Delegate
func player(_ player: FKPlayer, willPlay stream: FKStream?, unless error: NSError?) {}
func player(_ player: FKPlayer, stateDidChanged state: Player.State) {} // optional
func player(_ player: FKPlayer, videoDurationIsAvailable duration: TimeInterval) {} // optional

Errors

Errors are carried under NSError with domain: NSString.FKErrorDomain. More details are available in userInfo depending on the code:

  • NSNumber.FKErrorOriginApiCode
    • NSString.FKErrorApiCodeKey
    • NSString.FKErrorApiMessageKey
    • NSLocalizedDescriptionKey
  • NSNumber.FKErrorOriginNetworkCode
    • NSLocalizedDescriptionKey
  • NSNumber.FKErrorOriginBadUsageCode
    • NSLocalizedDescriptionKey

For convenience, in Swift, you can call fk() method to convert NSError into FKError.

Troubleshooting

Objective-C project

  • When running the app, you got the error dyld: Library not loaded. To solve this, set Always Embed Swift Standard Libraries to Yes in project Build Settings. Full error could look like : dyld: Library not loaded: @rpath/libswiftAVFoundation.dylib Referenced from: /Users/frouo/Library/Developer/CoreSimulator/Devices/CC67A36F-82AD-4081-8CE9-3C9E9D21F528/data/Containers/Bundle/Application/DF262573-6487-42E5-9F96-AADDF8F5671D/Firekast Demo ObjectiveC.app/Frameworks/Firekast.framework/Firekast Reason: image not found

Release Notes

v1.3.3

Build with Swift 4.2 (Xcode 10).

New:

  • Distribute your application on the App Store with both automatic signing and Include bitcode for iOS content option enabled.
  • Framework includes bitcode

v1.3.1

Build with Swift 4.2 (Xcode 10).

New:

v1.3.0

Build with Swift 4.2 (Xcode 10).

New:

  • Support Swift 4.2
  • FKPlayer supports controlStyle and scaleMode options

v1.2.2

Build with Swift 4.1.2 (Xcode 9.4.1).

New:

  • Call capture() on camera to get a snapshot of the camera preview

v1.2.1

Build with Swift 4.1.2 (Xcode 9.4.1).

Fixes:

  • Optimizes streaming for portrait or orientation

v1.2.0

Build with Swift 4.1.2 (Xcode 9.4.1).

What’s new:

  • Objective-C retro-compatible
  • FKError replaced by NSError for Objective-C retro-compatibility
  • NSError extension method: fk() to convert NSError into FKError

v1.1.1

Built with Swift 4.1 (Xcode 9.3).

What’s new:

  • Minor fixes

v1.1.0

Built with Swift 4.0.3 (Xcode 9.2).

What’s new:

  • 100% documented.
  • Refactoring, Streamer and Player, functions and parameters should be more straight forward.
  • Live stream on Facebook and/or Youtube and Firekast simultaneous. See LiveStreamingPlatform.
  • Use camera features by enabling torch, microphone, choosing your device’s camera. See Camera.

v1.0.0

Built with Swift 3.1

First release of FirekastStreamer and FirekastPlayer to stream and play video with its streamId.