Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

expo-camera-rtmp-publisher

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expo-camera-rtmp-publisher

My new module

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

Expo Camera RTMP Publisher

A React Native/Expo module for RTMP streaming from a mobile device camera. Currently only iOS platform is supported.

Features

  • Video streaming via RTMP protocol
  • Front and back camera support with switching capability
  • Device flashlight control with brightness adjustment
  • Configurable video and audio settings (resolution, bitrate)
  • Audio muting control
  • Broadcasting state management (start/stop/error events)
  • Full integration with Expo permissions system
  • Hardware-accelerated video encoding
  • Built on HaishinKit for iOS

Installation

In managed Expo projects

npx expo install expo-camera-rtmp-publisher

In bare React Native projects

Make sure you have installed and configured the expo package before continuing.

npm install expo-camera-rtmp-publisher

iOS configuration

Run npx pod-install after installing the npm package.

Note: Android support is currently under development.

Usage

Basic example

import React, { useRef, useState } from "react";
import { Button, View } from "react-native";
import {
  ExpoCameraRtmpPublisherView,
  requestCameraPermissionsAsync,
  requestMicrophonePermissionsAsync,
} from "expo-camera-rtmp-publisher";

export default function App() {
  const [isPublishing, setIsPublishing] = useState(false);
  const [cameraReady, setCameraReady] = useState(false);
  const publisherRef = useRef(null);

  const startPublishing = async () => {
    try {
      await publisherRef.current?.startPublishing(
        "rtmp://your-rtmp-server/live",
        "stream-key",
        {
          videoWidth: 1080,
          videoHeight: 1920,
          videoBitrate: 2000000,
          audioBitrate: 128000,
        },
      );
    } catch (err) {
      console.error("Broadcasting error:", err);
    }
  };

  return (
    <View style={{ flex: 1 }}>
      <ExpoCameraRtmpPublisherView
        ref={publisherRef}
        style={{ flex: 1 }}
        cameraPosition="front"
        muted={false}
        onReady={() => setCameraReady(true)}
        onPublishStarted={() => setIsPublishing(true)}
        onPublishStopped={() => setIsPublishing(false)}
        onPublishError={(error) => console.error(error)}
      />

      {cameraReady && (
        <Button
          title={isPublishing ? "Stop Broadcasting" : "Start Broadcasting"}
          onPress={isPublishing
            ? () => publisherRef.current?.stopPublishing()
            : startPublishing}
        />
      )}
    </View>
  );
}

Permissions

Before using the camera and microphone, you need to request permissions:

import { requestCameraPermissionsAsync, requestMicrophonePermissionsAsync } from 'expo-camera-rtmp-publisher;

async function requestPermissions() {
  const cameraPermission = await requestCameraPermissionsAsync();
  const microphonePermission = await requestMicrophonePermissionsAsync();
  
  if (!cameraPermission.granted || !microphonePermission.granted) {
    // Handle missing permissions
  }
}

Required Configuration Files

For the module to work properly, you need to add the following configurations to your project files:

iOS (Info.plist)

Add the following to your ios/Info.plist file to request camera and microphone permissions:

<key>NSCameraUsageDescription</key>
<string>The application requests access to the camera for video broadcasting</string>
<key>NSMicrophoneUsageDescription</key>
<string>The application requests access to the microphone for audio broadcasting</string>

API

ExpoCameraRtmpPublisherView

Properties

PropertyTypeDescription
cameraPosition'front' | 'back'Camera position (default: 'front')
mutedbooleanAudio muting state (default: false)
onReady() => voidCallback when the camera is ready
onPublishStarted() => voidCallback when broadcasting starts
onPublishStopped() => voidCallback when broadcasting stops
onPublishError(error: string) => voidCallback when a broadcasting error occurs

Methods

MethodParametersDescription
startPublishing(url: string, name: string, options?: PublishOptions)Starts RTMP broadcasting
stopPublishing()Stops RTMP broadcasting
switchCamera()Switches between front and back cameras
toggleTorch(level: number)Controls flashlight (0.0-1.0)

PublishOptions Type

PropertyTypeDefaultDescription
videoWidthnumber1080Video width in pixels
videoHeightnumber1920Video height in pixels
videoBitratenumber2000000Video bitrate in bits per second
audioBitratenumber128000Audio bitrate in bits per second

Permission Functions

FunctionReturn TypeDescription
requestCameraPermissionsAsyncPromise<PermissionResponse>Requests camera access
requestMicrophonePermissionsAsyncPromise<PermissionResponse>Requests microphone access
getCameraPermissionsAsyncPromise<PermissionResponse>Gets camera permission status
getMicrophonePermissionsAsyncPromise<PermissionResponse>Gets microphone permission status

PermissionResponse Type

PropertyTypeDescription
statusstringPermission status ('granted', 'denied', etc.)
grantedbooleanWhether permission is granted

License

MIT

Keywords

react-native

FAQs

Package last updated on 11 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts