Advanced Usage

This section outlines key considerations and common issues when using the player component.

Business Scenarios

Native Components

The player is a native component. When custom components (such as swipe dials or draggable gesture areas) are layered on top of it, the gesture response area may extend beyond the native component itself. This can cause events to be intercepted by the player, affecting business interaction experience.

To ensure proper interaction, it is recommended to temporarily disable the native component’s gesture response by calling ty.nativeDisabled(true) before the user operates a custom component. After the operation is complete, call ty.nativeDisabled(false) to restore gesture response.

For more information, refer to Native Components.

// Drag Start
const handTouchStart = value => {
    ty.nativeDisabled(true);
};

// While Dragging
const handTouchMove = value => {
    ty.nativeDisabled(true);
};
// Drag End
const handTouchEnd = value => {
    ty.nativeDisabled(true);
};

Custom Components on the Player

When adding clickable areas on top of the player—such as screenshot buttons, intercom buttons, etc.—you must wrap them using the CoverView component.

Example Code

import IpcPlayer from '@ray-js/ray-ipc-player';
import { View, Text, CoverView } from '@ray-js/ray';

function Page() {

  const [show, setShow] = useState(false)
  const deviceId = '1234567890xxxxxx';
  // Device online status
  const onlineStatus = true; 
  // Get player instance – allows calling methods on the player
  const onCtx = (ctx) => {
    console.log(ctx, 'ctx');
  };
  // Listen to player stream status
  const onChangeStreamStatus = (status) => {
     console.log(status, 'status');
     // When the player starts streaming, show the screenshot button,
    // or customize your own display logic
     if( status === 1002 ) {
        setShow(true);
     }
  };

  return (
    // playerContainer is the player container,
    // used to define the size of the player area
    <View className={Styles.playerContainer}>
      <IpcPlayer
          objectFit='contain'
          onCtx={onCtx}
          devId={deviceId}
          onlineStatus={onlineStatus}
          onChangeStreamStatus={onChangeStreamStatus}
        />

        <View className={Styles.featureContainer}>
          {show && <CoverView className={Styles.coverView}>
            <Text>screenshot</Text> 
          </CoverView> }  
        </View>
     </View>    
  )
}

Style Definition

.playerContainer {
  width: 100%;
  height: 300px;
  position: relative;
}
.featureContainer {
  //  Only handle positioning 
  // Width and height should be defined by the content inside
  position: absolute;
  top: 0;
  left: 0
}
.coverView {
    width: 100px;
    height: 20px;
}

FAQ

1. Player appears white (no video) when streaming

Ensure that the container of the player component does not have a background color set.
Refer to the Native Component Documentation for details.

2. Troubleshooting Video Stream Loading Errors

Starting from App version 650 and IpcPlayer v2.0.20 or later, if the video stream fails to load, an error code will be returned.
Developers can use this error code to troubleshoot specific issues.

Appendix

Error Codes

CodeDescription
-60000No available traffic, please recharge soon
-1000Invalid or empty request parameters (parameter validation failed)
-1001API call failed
-1301API call failed
-30API call failed
-1002Failed to parse API result [Invalid data]
-1303Failed to parse API result [Invalid data]
-20003Failed to parse API result [Invalid data]
-5Invalid parameter, method parameter is illegal
-1010Invalid parameter, method parameter is illegal
-1310Invalid parameter, method parameter is illegal
-20002Invalid parameter, method parameter is illegal
-40001Invalid parameter, method parameter is illegal
-1011Returned result is empty
-1311Returned result is empty
-40002Returned result is empty
-1020Unsupported P2PType
-1Not initialized
-1360Camera object not initialized or has been destroyed
-10000Camera object not initialized or has been destroyed
-1361Failed to create camera object
-1362Camera object connection error / not connected
-10001Camera object connection error / not connected
-1390Device offline
-10006Device offline
-1General error code
-40000cameraSDK general error
-40200General streaming error
-40300General decoding error
-40400General cloud storage error
-11Invalid session
-10002Session expired
-3Timeout
-10003Timeout
-40201Network data fetch timeout
-40202Streaming timeout, more data needed
-40203Decoding timeout
-33P2P session fetch timeout
-38DTLS handshake timeout
-55Connection timeout (detail of -3)
-56Connection timeout (detail of -3)
-57Connection timeout (detail of -3)
-58Connection timeout (detail of -3)
-1004P2P session was cancelled midway
-1008Device error occurred
-41001Device not responding
-39Peer not responding to preconnect command
-20001Invalid operation
-20004Operation interrupted
-40205Streaming process interrupted by user
-20005Operation not allowed
-20007Device busy
-20008Memory allocation failed
-29Insufficient memory
-30012Incorrect audio parameters
-30060Invalid parameter returned by device
-30061Data transmission error
-30082No first I-frame received [No data]
-12Session closed by peer
-13Session closed
-14Session closed locally
-100Session closed by peer
-115Device in restricted streaming mode
-23Session limit reached
-104Session limit reached, session closed
-24Invalid preconnect
-25Preconnect disconnected
-102Session detected, but device in privacy mode, session closed
-103Failed to create data sending thread
-105Authentication failed
-108Zombie session
-114Application layer resource request failed
-50No answer or candidate received
-52Socket connection failed
-53Peer socket connection failed
-54tcprelay service not responding (auth failed or device ID incorrect)
-20006Current app version does not support this protocol, please update the app
-30083Only MJPEG stream is supported
-40301Invalid decoding input
-40302Invalid decoding output
-40303Unsupported pixel format
-41000Device general error code
-40206Device exception during streaming
-54tcprelay service not responding (auth failed or device ID incorrect)