100ms Logo

100ms

Docs

Search docs
/

HLS Streaming & Recording

HLS Streaming allows for scaling to millions of viewers in near real time. You can give a link of your web-app which will be converted to a HLS feed by our server and can be played across devices for consumption.

Behind the scenes, this will be achieved by having a bot join your room and stream what it sees and hears. Once the feed is ready, the server will give a URL which can be played using any HLS Player.

Note that the media server serving the content in this case is owned by 100ms. If you're looking for a way to stream on YouTube, Twitch, etc. then please have a look at our RTMP streaming docs here.

Starting HLS

Check if user has permissions

const hlsStreaming: boolean = peer.role.permissions.hlsStreaming;

HLS can be started in two ways depending on the level of customization you need.

  1. Default View: The simplest view to just begin a stream with default UI and parameters.
  2. Custom Views: To use your own UI for HLS streaming, you need to provide your own web-app URL for our bot to join and stream.

Default View

Begins a stream with default parameters.

await hmsInstance.startHLSStreaming()

Custom View

You can call hmsSDK.startHLSStreaming with a HMSHLSConfig having either an array of meetingURLVariants or hlsRecordingConfig.

To use our own browser UI for HLS, you'll need to pass in a meeting URL. The 100ms bot will open this URL to join your room, so it must allow access without any user level interaction. In the future it'll be possible to start HLS for multiple such URLs for the same room.

For this purpose the API supports taking in an array, although currently only the first element of the array will be used. To distinguish between multiple URLs an additional field metadata can be passed.

Here's what the HMSHLSMeetingURLVariant looks like

class HMSHLSMeetingURLVariant { meetingUrl: string; metadata: string; }

To record the HLS stream you may specify an HMSHLSRecordingConfig within the HMSHLSConfig.

Here's what the HMSHLSRecordingConfig looks like

class HMSHLSRecordingConfig { singleFilePerLayer: boolean; videoOnDemand: boolean; }
  1. singleFilePerLayer if the desired end result is a mp4 file per HLS layer, false by default.
  2. videoOnDemand if the desired end result is a zip of m3u8 and all the chunks, false by default.
import { HMSHLSRecordingConfig, HMSHLSMeetingURLVariant, HMSHLSConfig, } from '@100mslive/react-native-hms'; const startHLSStreaming = () => { const hmsHLSMeetingURLVariant = new HMSHLSMeetingURLVariant({ meetingUrl: 'https://yogi.app.100ms.live/preview/nih-bkn-vek?skip_preview=true', metadata: '', }); const hmsHLSRecordingConfig = new HMSHLSRecordingConfig({ singleFilePerLayer: false, videoOnDemand: false, }); const hmsHLSConfig = new HMSHLSConfig({ hlsRecordingConfig: hmsHLSRecordingConfig, meetingURLVariants: [hlsStreamingDetails], }); await hmsInstance.startHLSStreaming(hmsHLSConfig) .then(d => console.log('Start Hls Success: ', d)) .catch(e => console.log('Start Hls Error: ', e)); };

Stopping HLS

You can call hmsInstance.stopHLSStreaming to stop HLS Streaming which will stop all the variants.

const stopHLSStreaming = () => { await hmsInstance.stopHLSStreaming() .then(d => console.log('Stop Hls Success: ', d)) .catch(e => console.log('Stop Hls Error: ', e)); };

Want to see how this works in a live project? Take a look at our advanced sample app.

Current Room Status The current status for the room is always reflected in the HMSRoom object.

Here are the relevant properties inside the HMSRoom object which you can read to get the current hls streaming status of the room hmsInstance.room.hlsStreamingState.

The object contains a boolean running which lets you know if it's active on the room right now as well as list of active variants.

hlsStreamingState an instance of HMSHLSStreamingState, which looks like:

class HMSHLSStreamingState { running: boolean; variants: Array<HMSHLSVariant>; }

This represents a livestream to one or more HLS URLs in the container of HMSHLSVariant. Which looks like:

class HMSHLSVariant { hlsStreamUrl: string; meetingUrl: string; metadata: string; startedAt: number; }

The room status should be checked in following two places -

  1. In the onJoin({ room }: { room: HMSRoom }) callback of HMSUpdateListener The properties mentioned above will be on the HMSRoom object.

  2. In the onRoomUpdate({ type, room }: { type: HMSRoomUpdate, room: HMSRoom }) callback of HMSUpdateListener. The HMSRoomUpdate type will be HMSRoomUpdate.HLS_STREAMING_STATE_UPDATED.

Tips

  • If you're using the dashboard web-app from 100ms, please make sure to use a role which doesn't have publish permissions for beam tile to not show up.

  • If using your own web-app, do put in place retries for API calls like tokens etc. just in case any call fails. As human users we're used to reloading the page in these scenarios which is difficult to achieve in the automated case.

  • Make sure to not disable the logs for the passed in meeting URL. This will allow for us to have more visibility into the room, refreshing the page if join doesn't happen within a time interval.