API: Etc

    API: Etc


    Article summary

    mute

    Mute the currently playing video.

    func mute()

    Sample code

    ShopLive.mute()


    unmute

    Unmute the currently playing video.

    func unmute()

    Sample code

    ShopLive.unmute()


    getCampaigns

    Retrieves the list of campaigns (broadcasts) that belong to the accessKey, together with the current status of each campaign. Set the accessKey with ShopLive.configure(with:) before calling. Available in iOS SDK 1.8.15 and later.

    extension ShopLive.API {
    
        // completion
        @discardableResult
        static func getCampaigns(_ request: ShopLiveCampaignListRequest = ShopLiveCampaignListRequest(),
                                 completion: @escaping (Result<ShopLiveCampaignListResponse, ShopLiveCommonError>) -> Void) -> ShopLiveCancellable
    
        // async/await (iOS 13+)
        static func getCampaigns(_ request: ShopLiveCampaignListRequest = ShopLiveCampaignListRequest()) async throws -> ShopLiveCampaignListResponse
    }

    Note

    • The completion handler is called on the main thread.

    • Call cancel() on the returned ShopLiveCancellable to cancel a request in progress. With the async version, cancelling the Task also cancels the request.

    • The request and response types are defined in the ShopliveSDKCommon module. Add import ShopliveSDKCommon when you refer to the type names directly in code.

    ShopLiveCampaignListRequest

    Query conditions. Every parameter is optional; passing ShopLiveCampaignListRequest() with no arguments fetches all statuses with the server defaults.

    Parameter name

    Type

    Description

    page

    Int?

    Page number, starting at 1. (Default: 1)

    size

    Int?

    Number of campaigns per page. Maximum 20. (Default: 10)

    statuses

    [ShopLiveCampaignListRequest.Status]

    Status filter. An empty array fetches every status. Only .ready (READY), .onair (ONAIR) and .closed (CLOSED) can be specified.

    order

    ShopLiveCampaignListRequest.Order?

    Sort direction by scheduledAt. .ascending / .descending (Default: .descending, newest first)

    ShopLiveCampaignListResponse

    The query result.

    Property

    Type

    Description

    campaigns

    [ShopLiveCampaign]

    The campaigns that were fetched.

    hasMore

    Bool

    Whether a next page exists. If true, increase page by 1 and query again.

    ShopLiveCampaign

    Information about a single campaign.

    Property

    Type

    Description

    campaignId

    Int64

    Campaign ID

    campaignKey

    String

    Campaign key. Use it as the campaignKey for ShopLive.play(data:) / ShopLive.preview(data:completion:).

    title

    String?

    Campaign title

    description

    String?

    Campaign description

    campaignUrl

    String?

    Campaign URL

    rerun

    Bool

    Whether the campaign is a rerun.

    archiveStream

    Bool

    Whether an archived stream (replay) is provided.

    privateLive

    Bool

    Whether the campaign is a private broadcast. It is still included in the list, so the app decides whether to show it.

    scheduledAt

    Date?

    Scheduled start time

    scheduledEndAt

    Date?

    Scheduled end time

    posterUrl

    String?

    Poster image URL

    lifecycle

    ShopLiveCampaign.Lifecycle

    Status and status-transition timestamps

    metrics

    ShopLiveCampaign.Metrics?

    Viewing metrics. Returned only in the .onair / .closed statuses; nil otherwise.

    ShopLiveCampaign.Lifecycle

    The status of the campaign and the timestamps of its status transitions.

    Property

    Type

    Description

    status

    ShopLiveCampaign.Status

    Campaign status. A rehearsal is reported as .ready, and a campaign that is closing is reported as .onair.

    rehearsal

    Bool

    Whether the campaign is in rehearsal. The status stays .ready during a rehearsal, so use this value to tell them apart.

    startedAt

    Date?

    Time the broadcast started

    closingAt

    Date?

    Time the closing process started. When the status is .onair and this value is present, the broadcast is closing.

    endedAt

    Date?

    Time the broadcast ended

    ShopLiveCampaign.Status

    Campaign status values. Server values are mapped as-is; an undefined value is delivered as .unknown.

    Case

    Server value

    Description

    .reserved

    RESERVED

    Reserved broadcast. It cannot be specified in the request filter (statuses) and is included only when fetching all statuses.

    .ready

    READY

    Preparing (standby). If lifecycle.rehearsal is true, the campaign is in rehearsal.

    .onair

    ONAIR

    On air. If lifecycle.closingAt is present, the broadcast is closing.

    .closed

    CLOSED

    Broadcast ended

    .unknown(String)

    Other

    An undefined server status value. The raw string is preserved to accommodate statuses added in the future.

    ShopLiveCampaign.Metrics

    Viewing metrics. Provided only in the .onair / .closed statuses.

    Property

    Type

    Description

    userCount

    Int?

    Number of viewers

    adoreCount

    Int?

    Number of likes (hearts)

    showUserCount

    Bool

    If false, userCount / adoreCount must not be shown in the UI.

    Error handling

    On failure a ShopLiveCommonError is delivered. codes holds the error code, and message is always the fixed text Failed to fetch campaign list. Refer to the error code. Determine the cause from codes. Error codes returned by the server are passed through as-is; see the Error codes document for the full list.

    Code

    Description

    9000

    The accessKey is not set. Call ShopLive.configure(with:) first.

    -200

    The accessKey does not exist. (Customer Account Not Found)

    Other server error codes

    Error codes returned by the server are passed through as-is. See the Error codes document.

    HTTP status code

    If the server responds without an error body, the HTTP status code (e.g. 404, 500) is passed through as-is.

    9900

    Network connection failed.

    9901

    Failed to parse the response JSON.

    10000

    Unexpected error.

    Sample code

    import ShopLiveSDK
    import ShopliveSDKCommon
    
    // Set the accessKey (once per app launch)
    ShopLive.configure(with: "{accessKey}")
    
    // Fetch up to 20 on-air and preparing campaigns, newest first
    let request = ShopLiveCampaignListRequest(page: 1,
                                              size: 20,
                                              statuses: [.onair, .ready],
                                              order: .descending)
    
    let cancellable = ShopLive.API.getCampaigns(request) { result in
        switch result {
        case let .success(response):
            for campaign in response.campaigns {
                switch campaign.lifecycle.status {
                case .reserved:
                    print("Reserved", campaign.title ?? "")
                case .ready:
                    print(campaign.lifecycle.rehearsal ? "Rehearsal" : "Preparing", campaign.title ?? "")
                case .onair:
                    print(campaign.lifecycle.closingAt == nil ? "On air" : "Closing", campaign.title ?? "")
                case .closed:
                    print("Closed", campaign.title ?? "")
                case let .unknown(raw):
                    print("Unknown status", raw)
                }
            }
            if response.hasMore {
                // Increase page by 1 and fetch the next page.
            }
        case let .failure(error):
            print("getCampaigns failed:", error.codes, error.message ?? "")
        }
    }
    
    // Cancel the request when the result is no longer needed (e.g. the screen is dismissed).
    // cancellable.cancel()

    Sample code (async/await)

    // iOS 13+ — cancelling the Task also cancels the request in progress.
    Task {
        do {
            let response = try await ShopLive.API.getCampaigns(ShopLiveCampaignListRequest(statuses: [.onair]))
            let onair = response.campaigns.filter { $0.lifecycle.closingAt == nil }
            if let campaign = onair.first {
                ShopLive.play(data: ShopLivePlayerData(campaignKey: campaign.campaignKey))
            }
        } catch let error as ShopLiveCommonError {
            print("getCampaigns failed:", error.codes)
        } catch {
            // Task cancellation (CancellationError), etc.
        }
    }


    What's Next