RTMP Streaming / Recording

Want to preserve your video call for posterity in a recording? Or live stream it out to millions of viewers on Twitch or YouTube or whatever gives you an RTMP ingest URL?

Turn on RTMP Streaming or Recording

In 100ms, recording and streaming is usually achieved by having a bot join your room and stream what it sees and hears to a file (recording) or to an RTMP ingest URL (streaming).

The topics covered in this doc are:

  1. How to start streaming / recording.
  2. How to stop streaming / recording.
  3. Checking the current status for streaming / recording.

Starting Streaming / Recording

To start recording, streaming or both, create an instance of HMSRTMPConfig.

HMSRTMPConfig takes the following:

  1. meetingURL: URL?. The URL the 100ms bot user will open to join your room. It must allow access without any user level interaction.

  2. rtmpURLs: [URL]?. If streaming is required, this has to be one or more RTMP ingest Urls with max limit of 3 urls where the stream should go. If only recording, this should be nil.

    • Format: rtmp://server.com/app/STREAM_KEY
    • Example: rtmp://a.rtmp.youtube.com/live2/k0jv-329m-1y7f-ktth-ck48
      • "rtmp://a.rtmp.youtube.com/live2/" - RTMP stream URL.
      • "k0jv-329m-1y7f-ktth-ck48" - RTMP stream key.
  3. record: Bool. If recording is required, set true. If recording is not required, set false. This value has no effect on streaming.

  • If both rtmpURLs and record = true are provided, both streaming and recording will begin.
  • If only rtmpURLs are provided, only streaming will begin.
  • If only record true is provided, only recording will begin.

If either one is started, the other can't be started without first stopping whatever is running. Eg: Only streaming is started. Recording can't be started unless streaming is stopped first.

If both are required, they have to be started together by providing both RTMP ingest Urls and recording = true.

The result of the action is sent in the completion handler ((Bool, HMSError?) -> Void)?. When attempt to start streaming/recording is successful then Bool will be true & HMSError will be nil. In case of failure, Bool will be false & a HMSError object will be passed with relevant error information.

let config = HMSRTMPConfig(meetingURL: <#meetingURL#>, rtmpURLs: <#rtmpURLs#>, record: <#recordingEnabled#>) hmsSDK?.startRTMPOrRecording(config: config) { didStart, error in print(didStart, error) }

Stopping Streaming / Recording

To stop streaming AND recording. It is not currently possible to stop just one, whatever is running will be stopped.

Here's how to stop both:

The stopRTMPAndRecording only has a completion handler. When attempt to stop is successful then Bool will be true & HMSError will be nil. In case of failure to stop streaming AND recording, Bool will be false & a HMSError object will be passed with relevant error information.

hmsSDK?.stopRTMPAndRecording() { didStop, error in }

Current Room Status

The current status for the room is always reflected in the HMSRoom object that is returned from the HMSUpdateListener.

Here are the relevant properties inside the HMSRoom object which you can read to get the current recording/streaming status of the room namely: browserRecordingState, serverRecordingState and rtmpStreamingState.

Each of them are objects which contain a boolean running which lets you know if it's active on the room right now and error which lets you know if there was an error.

Apart from the RTMP stream and the browser recording, which are ones you can start and stop, there is also a serverRecordingState, which can be turned on for the room for archival purposes and which cannot currently be stopped if enabled for the room from the dashboard.

  1. rtmpStreamingState an instance of HMSRTMPStreamingState, which looks like:
@objcMembers public class HMSRTMPStreamingState : NSObject { public let running: Bool public let error: HMSError? }

This represents a livestream to one or more RTMP urls.

  1. browserRecordingState an instance of HMSBrowserRecordingState, which looks like:
@objcMembers public class HMSBrowserRecordingState : NSObject { public let running: Bool public let error: HMSError? }

This represents the recording that can be requested to start.

  1. serverRecordingState an instance of HMSServerRecordingState, which looks like:
@objcMembers public class HMSServerRecordingState : NSObject { public let running: Bool public let error: HMSError? }

This represents that the room was set to be recorded when it was created and all sessions within it will always be recorded for archival by the server.

The room status should be checked in following two places -

  1. In the onJoin(room: HMSRoom) callback of HMSUpdateListener The properties mentioned above will be on the HMSRoom object.
  2. In the on(room: HMSRoom, update: HMSRoomUpdate) callback of HMSUpdateListener. The HMSRoomUpdate type will be browserRecordingStateUpdated, serverRecordingStateUpdated or rtmpStreamingStateUpdated.

Code sample

Refer to the code example within the 100ms Sample App for further information.


Have a suggestion? Recommend changes ->

Was this helpful?

1234