Skip to content

Commit

Permalink
Exposed methods for RTMP broadcasting (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski authored Jan 28, 2025
1 parent 808ed28 commit 243b1fa
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 3 deletions.
27 changes: 27 additions & 0 deletions Sources/StreamVideo/Call.swift
Original file line number Diff line number Diff line change
Expand Up @@ -715,17 +715,20 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
/// - Parameters:
/// - startsHls: whether hls streaming should be started.
/// - startRecording: whether recording should be started.
/// - startRtmpBroadcasts: whether RTMP broadcasting should be started.
/// - startTranscription: whether transcription should be started.
/// - Returns: `GoLiveResponse`.
@discardableResult
public func goLive(
startHls: Bool? = nil,
startRecording: Bool? = nil,
startRtmpBroadcasts: Bool? = nil,
startTranscription: Bool? = nil
) async throws -> GoLiveResponse {
let goLiveRequest = GoLiveRequest(
startHls: startHls,
startRecording: startRecording,
startRtmpBroadcasts: startRtmpBroadcasts,
startTranscription: startTranscription
)
return try await coordinatorClient.goLive(
Expand Down Expand Up @@ -791,6 +794,30 @@ public class Call: @unchecked Sendable, WSEventsSubscriber {
public func stopHLS() async throws -> StopHLSBroadcastingResponse {
try await coordinatorClient.stopHLSBroadcasting(type: callType, id: callId)
}

/// Starts RTMP broadcasting of the call.
/// - Parameter request: The request to start RTMP broadcasting.
/// - Returns: `StartRTMPBroadcastsResponse`.
/// - Throws: An error if starting RTMP broadcasting.
@discardableResult
public func startRTMPBroadcast(
request: StartRTMPBroadcastsRequest
) async throws -> StartRTMPBroadcastsResponse {
try await coordinatorClient.startRTMPBroadcasts(
type: callType,
id: callId,
startRTMPBroadcastsRequest: request
)
}

/// Stops RTMP broadcasting of the call.
/// - Parameter name: The name of the RTMP broadcast.
/// - Returns: `StopRTMPBroadcastsResponse`.
/// - Throws: An error if stopping RTMP broadcasting.
@discardableResult
public func stopRTMPBroadcasts(name: String) async throws -> StopRTMPBroadcastsResponse {
try await coordinatorClient.stopRTMPBroadcast(type: callType, id: callId, name: name)
}

// MARK: - Events

Expand Down
6 changes: 3 additions & 3 deletions Sources/StreamVideo/CallState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ public class CallState: ObservableObject {
case .typeCallMissedEvent:
break
case .typeCallRtmpBroadcastStartedEvent:
break
broadcasting = true
case .typeCallRtmpBroadcastStoppedEvent:
break
broadcasting = false
case .typeCallRtmpBroadcastFailedEvent:
break
broadcasting = false
case .typeCallSessionParticipantCountsUpdatedEvent:
break
case .typeUserUpdatedEvent:
Expand Down
40 changes: 40 additions & 0 deletions StreamVideoTests/Call/Call_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,46 @@ final class Call_Tests: StreamVideoTestCase {
XCTAssertEqual(participants?[0].name, "Alexey")
XCTAssertEqual(participants?[1].name, "Ilias")
}

// MARK: - RTMP Broadcasting

func test_updateState_fromBroadcastStartedEvent() async throws {
// Given
let call = streamVideo?.call(callType: callType, callId: callId)
let event = CallRtmpBroadcastStartedEvent(callCid: callCid, createdAt: Date(), name: "test")

// When
call?.state.updateState(from: .typeCallRtmpBroadcastStartedEvent(event))

// Then
XCTAssert(call?.state.broadcasting == true)
}

func test_updateState_fromBroadcastStoppedEvent() async throws {
// Given
let call = streamVideo?.call(callType: callType, callId: callId)
let event = CallRtmpBroadcastStoppedEvent(callCid: callCid, createdAt: Date(), name: "test")
call?.state.broadcasting = true

// When
call?.state.updateState(from: .typeCallRtmpBroadcastStoppedEvent(event))

// Then
XCTAssert(call?.state.broadcasting == false)
}

func test_updateState_fromBroadcastFailedEvent() async throws {
// Given
let call = streamVideo?.call(callType: callType, callId: callId)
let event = CallRtmpBroadcastFailedEvent(callCid: callCid, createdAt: Date(), name: "test")
call?.state.broadcasting = true

// When
call?.state.updateState(from: .typeCallRtmpBroadcastFailedEvent(event))

// Then
XCTAssert(call?.state.broadcasting == false)
}

// MARK: - Private helpers

Expand Down

0 comments on commit 243b1fa

Please sign in to comment.