@bits-innovate/react-native-vstarcam
v1.0.23
Published
React Native bridge for VStarCam P2P SDK
Downloads
2,883
Maintainers
Readme
react-native-vstarcam
React Native bridge for VStarCam P2P SDK - enables direct communication with VStarCam cameras for WiFi configuration, video streaming, PTZ control, and more.
Features
- ✅ P2P Connection to VStarCam cameras
- ✅ WiFi configuration
- ✅ WiFi network scanning
- ✅ PTZ control (pan, tilt, zoom)
- ✅ Video streaming
- ✅ Snapshot capture
- ✅ Two-way audio (planned)
Installation
npm install react-native-vstarcam
# or
yarn add react-native-vstarcamExpo Users
This package requires native code and won't work with Expo Go. You need to use a development build:
npx expo prebuild
npx expo run:android
# or
npx expo run:iosAndroid Setup
The package automatically links the VStarCam AAR library. No additional setup required.
iOS Setup
- Run
pod installin your iOS directory - The VStarCam iOS framework needs to be placed in
ios/Frameworks/
Usage
import { createVStarCamClient, ConnectionState } from "react-native-vstarcam";
// Create a client
const client = createVStarCamClient();
// Connect to camera
async function connectToCamera(deviceId: string) {
// Create client with device ID
await client.create(deviceId);
// Connect via P2P
const result = await client.connect(true);
if (result.state === ConnectionState.ONLINE) {
console.log("Connected!");
// Login
await client.login("admin", "888888");
// Get device info
const info = await client.getDeviceInfo();
console.log("Device:", info);
}
}
// Configure WiFi
async function configureWiFi() {
// Scan for networks
const networks = await client.scanWiFi();
console.log("Available networks:", networks);
// Configure WiFi
const success = await client.configureWiFi("MyWiFi", "MyPassword", "WPA2", 6);
if (success) {
console.log("WiFi configured successfully!");
}
}
// PTZ Control
async function moveCameraUp() {
await client.ptzUp(true); // Continuous movement
await new Promise((resolve) => setTimeout(resolve, 1000));
await client.ptzStop();
}
// Cleanup
async function disconnect() {
await client.disconnect();
await client.destroy();
}API Reference
VStarCamClient
Methods
| Method | Description |
| ----------------------------------------------- | -------------------------------- |
| create(deviceId) | Create a P2P client for a device |
| connect(lanScan?, serverParam?, connectType?) | Connect to camera |
| login(username?, password?) | Login to camera |
| disconnect() | Disconnect from camera |
| destroy() | Cleanup and release resources |
WiFi Methods
| Method | Description |
| ---------------------------------------------------- | -------------------------------- |
| scanWiFi() | Scan for available WiFi networks |
| configureWiFi(ssid, password, security?, channel?) | Configure camera WiFi |
PTZ Methods
| Method | Description |
| ----------------------- | -------------------- |
| ptzUp(continuous?) | Move camera up |
| ptzDown(continuous?) | Move camera down |
| ptzLeft(continuous?) | Move camera left |
| ptzRight(continuous?) | Move camera right |
| ptzStop() | Stop camera movement |
Video Methods
| Method | Description |
| ------------------------- | ------------------ |
| startVideo(streamType?) | Start video stream |
| stopVideo() | Stop video stream |
| takeSnapshot() | Capture a snapshot |
Enums
enum ConnectionState {
INVALID_CLIENT,
CONNECTING,
INITIALIZING,
ONLINE,
CONNECT_FAILED,
DISCONNECTED,
INVALID_ID,
OFFLINE,
TIMEOUT,
MAX_SESSION,
MAX,
REMOVE_CLOSE,
}
enum ConnectionMode {
NONE,
P2P,
RELAY,
SOCKET,
}Events
// Connection state changes
client.addConnectionListener((clientId, state) => {
console.log("Connection state:", ConnectionState[state]);
});
// Command responses
client.addCommandListener((clientId, command, data) => {
console.log("Command:", command, "Data:", data);
});
// Video frames
client.addVideoListener((clientId, frame, width, height, timestamp) => {
// Handle video frame
});VStarCam Device ID
The Device ID (DID) is typically printed on the camera or shown in the VStarCam app. Format: VSTA-XXXXXX-XXXXX
Troubleshooting
Connection fails
- Ensure the camera is powered on and in pairing mode
- Check that your phone is on the same network
- Verify the Device ID is correct
WiFi configuration fails
- Ensure you're connected to the camera first
- Check WiFi password is correct
- Make sure the network is 2.4GHz (most VStarCam cameras don't support 5GHz)
License
MIT
