0.0.1 ā€¢ Published 5 months ago

rn-rtmp-friend v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

šŸ“¹ Live stream RTMP publisher for React Native with built in camera support!

THIS IS ORIGINALLY FORK OF THE AWESOME LIBRARY. p.s Created this fork, because i needed some fixes to be in the app (like video settings setup, reconnection, etc.)

āš ļøšŸ› ļø Support for the new architecture is under development

Installation

npm install react-native-publisher

or

yarn add react-native-publisher

and for iOS

cd ios && pod install

Android

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" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

iOS

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>

Example Project

Clone the repo and run

yarn

and

cd example && yarn ios (or yarn android)

You can use Youtube for live stream server. You can check Live on Youtube

Usage

import RTMPPublisher from 'react-native-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();
  await publisherRef.current.setAudioInput(audioInput: AudioInputType);
}

<RTMPPublisher
  ref={publisherRef}
  streamURL="rtmp://your-publish-url"
  streamName="stream-name"
  videoSettings={{
    width: 1080,
    height: 1920,
    bitrate: 5000 * 1024,
    audioBitrate: 192 * 1000
  }}
  allowedVideoOrientations={[
    "portrait",
    "landscapeLeft",
    "landscapeRight",
    "portraitUpsideDown"
  ]}
  videoOrientation="portrait"
  onConnectionFailedRtmp={() => ...}
  onConnectionStartedRtmp={() => ...}
  onConnectionSuccessRtmp={() => ...}
  onDisconnectRtmp={() => ...}
  onNewBitrateRtmp={() => ...}
  onStreamStateChanged={(status: streamState) => ...}
/>

Props

NameTypeRequiredDescription
streamURLstringtruePublish URL address with RTMP Protocol
streamNamestringtrueStream name or key
videoSettingsVideoSettingsTypefalseVideo settings for video
allowedVideoOrientationsVideoOrientation[]falseAllowed video orientation
videoOrientationVideoOrientationfalseInitial video orientation

Youtube Example

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="****-****-****-****-****"
  ...
  ...

Events

NameReturnsDescriptionAndroidiOS
onConnectionFailednullInvokes on connection fails to publish URLāœ…āœ…
onConnectionStartednullInvokes on connection start to publish URLāœ…āœ…
onConnectionSuccessnullInvokes on connection success to publish URLāœ…āœ…
onDisconnectnullInvokes on disconnect from publish URLāœ…āœ…
onNewBitrateReceivednullInvokes on new bitrate received from URLāœ…āŒ
onStreamStateChangedStreamStateInvokes on stream state changes. It can be use alternatively for above connection events.āœ…āœ…
onBluetoothDeviceStatusChangedBluetoothDeviceStatusesInvokes on bluetooth headset state changes.āœ…āŒ

Methods

NameReturnsDescriptionAndroidiOS
startStreamPromise<void>Starts the streamāœ…āœ…
stopStreamPromise<void>Stops the streamāœ…āœ…
mutePromise<void>Mutes the microphoneāœ…āœ…
unmutePromise<void>Unmutes the microphoneāœ…āœ…
switchCameraPromise<void>Switches the cameraāœ…āœ…
toggleFlashPromise<void>Toggles the flashāœ…āœ…
getPublishURLPromise<string>Gets the publish URLāœ…āœ…
isMutedPromise<boolean>Returns microphone stateāœ…āœ…
isStreamingPromise<boolean>Returns streaming stateāœ…āœ…
hasCongestionPromise<boolean>Returns if congestionāœ…āŒ
isAudioPreparedPromise<boolean>Returns audio prepare stateāœ…āœ…
isVideoPreparedPromise<boolean>Returns video prepare stateāœ…āœ…
isCameraOnPreviewPromise<boolean>Returns camera is onāœ…āŒ
setAudioInputPromise<AudioInputType>Sets microphone inputāœ…āœ…
setVideoSettingsPromise<VideoSettingsType>Sets camera quality settingsāœ…āœ…

Types

NameValue
streamStateCONNECTING, CONNECTED, DISCONNECTED, FAILED
BluetoothDeviceStatusesCONNECTING, CONNECTED, DISCONNECTED
AudioInputTypeBLUETOOTH_HEADSET, SPEAKER, WIRED_HEADSET
VideoSettingsType{width: number; height: number; bitrate: number; audioBitrate: number}
VideoOrientationportrait, landscapeLeft, landscapeRight, portraitUpsideDown
  • AudioInputType: WIRED_HEADSET type supporting in only iOS. On Android it affects nothing. If a wired headset connected to Android device, device uses it as default.

Used Native Packages

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT