Skip to main content
Version: 4.x.x

Stream Class Methods - iOS

resume()​

  • By using resume(), you can resume a remote participant's stream.
  • resume() is async throws. Call it with try await inside a Task or another async context.

Throws​

  • VideoSDKError with the same errors as pause(), except:
    • ERROR_ALREADY_IN_REQUESTED_STATE (3054) when the stream is not paused.
    • RESUME_STREAM_FAILED (4075) when the server refuses the request.

Returns​

  • Void

Example​

Task {
do {
try await stream.resume()
} catch let error as VideoSDKError {
print("resume() failed: \(error.name) (\(error.code)): \(error.message)")
} catch {
print("resume() failed: \(error)")
}
}

pause()​

  • By using pause(), you can pause a remote participant's stream. Only your device stops receiving it. The participant keeps sending it to everyone else.
  • Only a remote stream that you receive can be paused. You cannot pause your own streams.
  • pause() is async throws. Call it with try await inside a Task or another async context.

Throws​

  • VideoSDKError when the call is refused or fails:
    • ERROR_ACTION_PERFORMED_BEFORE_ROOM_JOINED (3035) before you join the room, or after you leave it.
    • ERROR_ROOM_RECONNECTING (3065) while the room is reconnecting.
    • ERROR_ACTION_NOT_SUPPORTED (3068) for a stream you do not receive, such as one of your own streams.
    • ERROR_ALREADY_IN_REQUESTED_STATE (3054) when the stream is already paused.
    • PAUSE_STREAM_FAILED (4074) when the server refuses the request.
    • ERROR_OPERATION_TIMED_OUT (3079) when the server does not answer in time.
  • 3035 and 3065 are also reported to onError().

Returns​

  • Void

Example​

Task {
do {
try await stream.pause()
} catch let error as VideoSDKError {
print("pause() failed: \(error.name) (\(error.code)): \(error.message)")
} catch {
print("pause() failed: \(error)")
}
}

createRenderView()​

  • Returns a view that shows the stream's video. Add it to your view hierarchy to show the video.
  • It works for camera and screen-share streams, and returns nil for an audio stream.
  • Each call for the same participant's camera, or the same participant's screen share, returns the same view.
  • See RTCMTLVideoView for the properties of the view.

Returns​

  • RTCMTLVideoView?

Example​

extension RoomViewController: ParticipantEventListener {
func onStreamEnabled(_ stream: RTCStream, forParticipant participant: Participant) {
if let videoView = stream.createRenderView() {
videoView.frame = view.bounds
view.addSubview(videoView)
}
}
}

on()​

  • Adds a listener for a stream event. The only event is state.
  • The listener is called on the main thread.

Parameters​

  • event: MediaStreamEventType. Use .state.
  • listener: (StreamState) -> Void

Returns​

  • UUID that identifies the listener. Pass it to off() to remove the listener.

Example​

let listenerId = stream.on(.state) { state in
print("Stream state changed: \(state)")
}

off()​

  • Removes a listener that on() added.

Parameters​

  • event: MediaStreamEventType. Use .state.
  • listenerId: UUID that on() returned.

Returns​

  • Void

Example​

stream.off(.state, listenerId: listenerId)

Got a Question? Ask us on discord