? Live stream RTMP Publisher for React Native
? Live stream RTMP publisher for React Native with built in camera support!
npm install react-native-rtmp-publisher
or
yarn add react-native-rtmp-publisher
for iOS, on /ios
directory
pod install
Clone the repo and on /example
directory
yarn
and
yarn ios (or yarn android)
You can use Youtube for live stream server. You can check Live on Youtube
Add Android Permission for camera and audio to AndroidManifest.xml
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
Add iOS Permission for camera and audio to Info.plist
<key>NSCameraUsageDescription</key>
<string>CAMERA PERMISSION DESCRIPTION</string>
<key>NSMicrophoneUsageDescription</key>
<string>AUDIO PERMISSION DESCRIPTION</string>
import { RTMPPublisher } from 'react-native-rtmp-publisher';
// ...
async function publisherActions() {
await publisherRef.current.startStream();
await publisherRef.current.stopStream();
await publisherRef.current.mute();
await publisherRef.current.unmute();
await publisherRef.current.switchCamera();
await publisherRef.current.getPublishURL();
await publisherRef.current.isMuted();
await publisherRef.current.isStreaming();
await publisherRef.current.toggleFlash();
await publisherRef.current.hasCongestion();
await publisherRef.current.isAudioPrepared();
await publisherRef.current.isVideoPrepared();
await publisherRef.current.isCameraOnPreview();
}
<RTMPPublisher
ref={publisherRef}
streamURL="rtmp://your-publish-url"
streamName="stream-name"
onConnectionFailedRtmp={() => null}
onConnectionStartedRtmp={() => null}
onConnectionSuccessRtmp={() => null}
onDisconnectRtmp={() => null}
onNewBitrateRtmp={() => null}
onStreamStateChanged={(s: streamState) => null}
/>;
Name | Type | Required | Description |
---|---|---|---|
streamURL |
string |
true |
Publish URL address with RTM Protocol |
streamName |
string |
true |
Stream name or key |
For live stream, Youtube gives you stream url and stream key, you can place the key on streamName
parameter
Youtube Stream URL: rtmp://a.rtmp.youtube.com/live2
Youtube Stream Key: ****-****-****-****-****
<RTMPPublisher
streamURL="rtmp://a.rtmp.youtube.com/live2"
streamName="****-****-****-****-****"
...
...
Name | Returns | Description | Android | iOS |
---|---|---|---|---|
onConnectionFailed |
null |
Invokes on connection fails to publish URL | ✅ | ✅ |
onConnectionStarted |
null |
Invokes on connection start to publish URL | ✅ | ✅ |
onConnectionSuccess |
null |
Invokes on connection success to publish URL | ✅ | ✅ |
onDisconnect |
null |
Invokes on disconnect from publish URL | ✅ | ✅ |
onNewBitrateReceived |
null |
Invokes on new bitrate received from URL | ✅ | ❌ |
onStreamStateChanged |
streamState |
Invokes on stream state changes. It can be use alternatively for above connection events. | ✅ | ✅ |
Name | Returns | Description | Android | iOS |
---|---|---|---|---|
startStream |
Promise<void> |
Starts the stream | ✅ | ✅ |
stopStream |
Promise<void> |
Stops the stream | ✅ | ✅ |
mute |
Promise<void> |
Mutes the microphone | ✅ | ✅ |
unmute |
Promise<void> |
Unmutes the microphone | ✅ | ✅ |
switchCamera |
Promise<void> |
Switches the camera | ✅ | ✅ |
toggleFlash |
Promise<void> |
Toggles the flash | ✅ | ✅ |
getPublishURL |
Promise<string> |
Gets the publish URL | ✅ | ✅ |
isMuted |
Promise<boolean> |
Returns microphone state | ✅ | ✅ |
isStreaming |
Promise<boolean> |
Returns streaming state | ✅ | ✅ |
hasCongestion |
Promise<boolean> |
Returns if congestion | ✅ | ❌ |
isAudioPrepared |
Promise<boolean> |
Returns audio prepare state | ✅ | ✅ |
isVideoPrepared |
Promise<boolean> |
Returns video prepare state | ✅ | ✅ |
isCameraOnPreview |
Promise<boolean> |
Returns camera is on | ✅ | ❌ |
Name | Value |
---|---|
streamState |
CONNECTING CONNECTED DISCONNECTED FAILED |
See the contributing guide to learn how to contribute to the repository and the development workflow.
MIT