FLCastManager

public protocol FLCastManager

FLCastManager is a singleton responsible for setting up a custom channel for communication with a Cast session.

Usage

  • Before communicating with a Cast session, the sender application must create a GCKCastContext instance:
DispatchQueue.main.async {
    let criteria = GCKDiscoveryCriteria(applicationID: castReceiverId)
    let gckOptions = GCKCastOptions(discoveryCriteria: criteria)
    gckOptions.physicalVolumeButtonsWillControlDeviceVolume = true
    GCKCastContext.setSharedInstanceWith(gckOptions)
    GCKCastContext.sharedInstance().useDefaultExpandedMediaControls = true
}
  • After initializing GCKCastContext, call initialize() to add a GCKSessionManagerListener and register the GCKLogger callback for the SDK.

  • To receive FLCastManagerDelegate callbacks, set a confirmed instance of FLCastManagerDelegate using registerListener(_:).

  • To stop receiving callbacks, call unregisterListener().

  • Casting Content:

    • Use a CastPlayer instance to initiate content playback. Before casting, register the Cast device with the Firstlight Platform by calling registerUserData(clientDevice:castDeviceID:authToken:) after the Cast session has started.
    • After successful registration, load media on the receiver using loadMedia(castAsset:metadata:mediaTracks:) from the CastPlayer API.
    • If registration fails, you will be notified with an error when attempting to load media.
  • Cast Session Management:

    • A Cast session includes connecting to a device, launching or joining a receiver application, and initializing a media control channel. Sessions start automatically when the user selects a device and end when disconnected. Reconnection due to network issues is handled by the Cast SDK.
  • The Google Cast context instance.

    Declaration

    Swift

    var castContext: GCKCastContext { get }
  • The Google Cast session manager instance.

    Declaration

    Swift

    var castSessionManager: GCKSessionManager { get }
  • The Cast player, equivalent to the remote media client in the Google Cast SDK.

    Declaration

    Swift

    var castPlayer: FLCastPlayer? { get }
  • Adds a GCKSessionManagerListener and registers the GCKLogger callback for the SDK.

    Note

    Call after GCKCastContext is initialized.

    Declaration

    Swift

    func initialize()
  • Removes the GCKSessionManagerListener and ends the current session and casting.

    Declaration

    Swift

    func dispose()
  • Registers a delegate to receive FLCastManagerDelegate callbacks.

    Declaration

    Swift

    func registerListener(_ delegate: FLCastManagerDelegate?)
  • Unregisters the delegate to stop receiving FLCastManagerDelegate callbacks.

    Declaration

    Swift

    func unregisterListener()
  • Sends user context or device information to the receiver. Should be called after session initialization for device registration, a prerequisite for content authorization.

    Declaration

    Swift

    func registerUserData(clientDevice: PlatformClient, castDeviceID: String, authToken: String)

    Parameters

    clientDevice

    The sender client device.

    castDeviceID

    The cast device identifier.

    authToken

    The user authentication token.

  • Sends a text message to the receiver. Can only be sent when a cast session is active.

    Declaration

    Swift

    func sendMessage(payload: Message, completion: @escaping (GCKError?) -> Void)

    Parameters

    payload

    The message to send.

    completion

    Called on the main thread with a GCKError on failure, or nil on success.

  • Presents the default expanded media controls UI for the current Cast session.

    Configures and displays the default expanded media controls provided by the Google Cast SDK. Call this to present the standard media controls interface for the active Cast session. The expanded controller allows users to interact with playback, volume, and other media controls on the cast device. Applicable only for live content.

    Default Implementation

    Presents the default expanded media controls UI for the current Cast session.

    Configures and displays the default expanded media controls provided by the Google Cast SDK. Call this to present the standard media controls interface for the active Cast session. The expanded controller allows users to interact with playback, volume, and other media controls on the cast device. Applicable only for live content.

    Declaration

    Swift

    func presentExpandedController(disableSeek: Bool?)

    Parameters

    disableSeek

    If true, disables seek controls in the expanded controller.

  • Returns the connected cast device name.

    Declaration

    Swift

    func getDeviceName() -> String?

    Return Value

    The device name if a cast session is active; otherwise nil.