English | [简体中文](./README-zh_CN.md)

# @ray-js/robot-data-stream

[![latest](https://img.shields.io/npm/v/@ray-js/robot-data-stream/latest.svg)](https://www.npmjs.com/package/@ray-js/robot-data-stream) [![download](https://img.shields.io/npm/dt/@ray-js/robot-data-stream.svg)](https://www.npmjs.com/package/@ray-js/robot-data-stream)

> Robot P2P data stream hooks

## Installation

```sh
$ npm install @ray-js/robot-data-stream
# or
$ yarn add @ray-js/robot-data-stream
```

## Develop

```sh
# watch compile component code
yarn watch
# watch compile demo
yarn start:tuya
```

## Usage

```tsx
import React from 'react';
import { View, Text } from '@ray-js/ray';
import { useP2PDataStream, StreamDataNotificationCenter } from '@ray-js/robot-data-stream';
import styles from './index.module.less';

const DemoBlock = ({ devId }) => {
  const onReceiveMapData = (data: string) => {
    StreamDataNotificationCenter.emit('receiveMapData', data);
  };

  const onReceivePathData = (data: string) => {
    StreamDataNotificationCenter.emit('receivePathData', data);
  };

  const onReceiveAIPicData = (data: string) => {
    StreamDataNotificationCenter.emit('receiveAIPicData', data);
  };

  const onReceiveAIPicHDData = (data: string) => {
    StreamDataNotificationCenter.emit('receiveAIPicHDData', data);
  };

  const { appendDownloadStreamDuringTask } = useP2PDataStream(
    devId,
    onReceiveMapData,
    onReceivePathData,
    {
      logTag: 'Robot_Stream',
      onReceiveAIPicData,
      onReceiveAIPicHDData
    }
  );

  return (
    <View className={styles.demoBlock}>
      <View className={styles.demoBlockTitle}>
        <Text className={styles.demoBlockTitleText}>{devId}</Text>
      </View>
    </View>
  );
};

export default function Home() {
  return (
    <View className={styles.view}>
      <DemoBlock devId="" />
    </View>
  );
}

```