0.0.3 • Published 5 months ago

@unblur-dev/rtmp-friend v0.0.3

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

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>

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"
  onConnectionFailed={() => ...}
  onConnectionStarted={() => ...}
  onConnectionSuccess={() => ...}
  onDisconnect={() => ...}
  onNewBitrate={() => ...}
  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.

Contributing

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

License

MIT

0.0.3

5 months ago

0.0.2

7 months ago

0.0.1

1 year ago