# General

> This article introduces the business APIs provided by @ray-js/ray-ipc-utils, ready to use out of the box. Required version: ^1.1.5.

## 1. Native Page Navigation

**Description**

Some pages are implemented as native (App) pages and currently do not support customization. For more details or feedback, please contact us.

**Request Parameters**

| Parameter | Type      | Description                         | Required |
| --------- | --------- | ----------------------------------- | -------- |
| id        | `string`  | Route ID                            | Yes      |
| deviceId  | `string`  | Device ID                           | Yes      |
| theme     | themeType | Theme                               | No       |
| params    | `object`  | Route parameters (default `{}`)     | No       |
| isGeneral | `boolean` | General page flag (default `false`) | No       |

**themeType Details**

| Value     | Description                |
| --------- | -------------------------- |
| undefined | Default, follows app theme |
| dark      | Dark mode                  |
| light     | Light mode                 |

### Album

**Route ID: ipc_album_panel**

**Example**

```javascript

import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';

const id = 'ipc_album_panel';
const deviceId = '1234567890xxxxxx';

const result = await goToIpcPageNativeRoute(id, deviceId);

```

### Playback Hub (Recommended)

> 💡 **Note**: `@ray-js/ray-ipc-utils` version >= 1.1.11 is required.

**Example**

```javascript
import { goToIpcPlayBackHubNativePage } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const sdCardState = true; // Whether the SD card is working properly, usually true when DP sd_status === 1

const result = await goToIpcPlayBackHubNativePage(deviceId, sdCardState);

```

### Playback

> 💡 **Note**: Starting from App version 650, cloud and SD card playback are merged into one unified page.

**Cloud playback id**: camera_cloud_panel
**SD card playback id**: camera_playback_panel

Note: The playback page has internal logic. For example, if the device does not support cloud storage, the cloud tab will not display even if navigating to the cloud playback route.

**Example**

```javascript

import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';

const id = 'camera_cloud_panel';
const deviceId = '1234567890xxxxxx';

const result = await goToIpcPageNativeRoute(id, deviceId);

```

### Messages

The message page displays various types of notifications, mainly including: general event alerts, doorbell messages, and AI messages. Internally, it handles tasks such as image decryption and rendering, as well as video decryption and playback.

**Route ID: camera_message_panel**

**Example**

```javascript

import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';

const id = 'camera_message_panel';
const deviceId = '1234567890xxxxxx';

const result = await goToIpcPageNativeRoute(id, deviceId);

```

### Voice Manager

**Route ID: ipc_doorbell_voice_manager**

**Example**

```javascript

import { goToIpcPageNativeRoute } from '@ray-js/ray-ipc-utils';

const id = 'ipc_doorbell_voice_manager';
const deviceId = '1234567890xxxxxx';

const result = await goToIpcPageNativeRoute(id, deviceId);

```

## 2. Get Camera Configuration

**Description**

Retrieves config data such as speaker, intercom, resolution, zoom, etc.

**Request Parameter**

| Parameter | Type     | Description | Required |
| --------- | -------- | ----------- | -------- |
| deviceId  | `string` | Device ID   | Yes      |

**Return Parameter data**

| Parameter          | Data Type | Description                                |
| ------------------ | --------- | ------------------------------------------ |
| microphoneSettings | `object`  | Microphone-related settings                |
| intercomInfo       | `object`  | Intercom-related settings                  |
| videoResolution    | `object`  | Resolution-related settings                |
| maxZoomSettings    | `number`  | Maximum zoom level supported by the player |

**Field Details：microphoneSettings**

| Parameter             | Data Type | Description                                   |
| --------------------- | --------- | --------------------------------------------- |
| isMicrophoneSupported | `boolean` | Whether the speaker function is supported     |
| defaultMuteMode       | `boolean` | Default mute state (true means muted)         |
| cachedMuteMode        | `boolean` | Most recent mute configuration (cached value) |

**Field Details：intercomInfo**

| Parameter              | Data Type                     | Description                              |
| ---------------------- | ----------------------------- | ---------------------------------------- |
| isIntercomSupported    | `boolean`                     | Whether intercom is supported            |
| defaultIntercomMode    | `OneWay` or `TwoWay`          | Default intercom mode                    |
| cachedIntercomMode     | `OneWay` or `TwoWay`          | Most recent intercom mode (cached value) |
| supportedIntercomModes | `array` \['OneWay', 'TwoWay'] | List of supported intercom modes         |

**Intercom Mode Explanation**

| Parameter | Description      | Remarks                                                                                                |
| :-------- | :--------------- | :----------------------------------------------------------------------------------------------------- |
| OneWay    | One-way intercom | When intercom is on, speaker is off; when intercom ends, speaker turns on. Similar to a walkie-talkie. |
| TwoWay    | Two-way intercom | When intercom is on, speaker is on; when intercom ends, speaker remains on. Similar to a phone call.   |

**Field Details: videoResolution**

| Parameter            | Data Type               | Description                              |
| :------------------- | :---------------------- | :--------------------------------------- |
| defaultResolution    | `ClarityType`           | Default video clarity                    |
| cachedResolution     | `ClarityType`           | Last used clarity setting (cached value) |
| availableResolutions | `array`, ClarityType\[] | List of supported clarity levels         |

**ClarityType Details: ClarityType**

| Parameter | Description            | Note                                     |
| :-------- | :--------------------- | :--------------------------------------- |
| SS        | Data-saving mode       | -                                        |
| SD        | Standard Definition    | Commonly used                            |
| HD        | High Definition        | Commonly used                            |
| UD        | Ultra Definition       | -                                        |
| SSP       | Super Super Definition |                                          |
| AUTO      | Auto                   | Supported from P2P version 4.0 and above |

> The clarity list values are mainly configured based on the product PID dimension, with the default being ['HD', 'SD']. For special configurations, please confirm and provide feedback to the project manager.

**Example**

```javascript

import { getCameraConfigInfo } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await getCameraConfigInfo(deviceId);

```

**Response Example**

```json
{
  "code": 0,
  "data": {
    "microphoneSettings": {
      "isMicrophoneSupported": true,
      "defaultMuteMode": false,
      "cachedMuteMode": true
    },
    "intercomInfo": {
      "isIntercomSupported": true,
      "defaultIntercomMode": "OneWay",
      "cachedIntercomMode": "OneWay",
      "supportedIntercomModes": ["OneWay", "TwoWay"]
    }
  }
}
```

## 3. Cloud Storage Support

**Description**

Used to check whether the specified camera device supports cloud storage.

**Request Parameters**

| Parameter | Type     | Description | Required |
| :-------- | :------- | :---------- | :------- |
| deviceId  | `string` | Device ID   | Yes      |

**Response Parameters data**

- true: Supported
- false: Not supported

**Example**

```javascript

import { getIsSupportedCloudStorageSync } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await getIsSupportedCloudStorageSync(deviceId);

```

**Response Example**

```json
{
  "code": 0,
  "data": true
}
```

## 4. Get Signal Strength

**Description**

Used to obtain the signal strength of the specified camera device when streaming.

**Request Parameters**

| Parameter | Type     | Description | Required |
| --------- | -------- | ----------- | -------- |
| deviceId  | `string` | Device ID   | Yes      |

**Response Parameters data**

Signal strength value, ranging from 0 to 100.

- `0` indicates the weakest signal.
- `100` indicates the strongest signal.  
  Unit: **%**

**Example**

```javascript

import { requestWifiSignal } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await requestWifiSignal(deviceId);

```

**Response Example**

```json
{
  "code": 0,
  "data": 100
}
```

## 5. Get Video Bitrate

**Description**

Used to get the video bitrate of the specified camera device during streaming, indicating the amount of data transmitted per unit time.

**Request Parameters**

| Parameter | Type     | Description | Required |
| --------- | -------- | ----------- | -------- |
| deviceId  | `string` | Device ID   | Yes      |

**Response Parameters data**

Video Bitrate: A numeric value greater than or equal to 0, representing the data transmission rate during video streaming.  
**Unit**: `KB/S` (Kilobytes per second)

**Example**

```javascript

import { getVideoBitrateKbps } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await getVideoBitrateKbps(deviceId);

```

**Response Example**

```json
{
  "code": 0,
  "data": 100
}
```

## 6. Picture-in-Picture (PiP)

### Support Check

**Description**

First, determine whether the device supports this feature.

**Request Parameters**

| Parameter | Data Type | Description | Required |
| :-------- | :-------- | :---------- | :------- |
| deviceId  | `string`  | Device ID   | Yes      |

**Response Parameters data**

isSupport: true (**supported**) or false (**not supported**)

**Example**

```javascript

import { isSupportFloatWindow } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await isSupportFloatWindow(deviceId);

```

**Response Example**

```json
{
  "code": 0,
  "data": { "isSupport": true}
}
```

### Enable Picture-in-Picture

**Description**

This feature can only be successfully called to enable picture-in-picture if the device supports it.

**Request Parameters**

| Parameter | Data Type | Description | Required |
| :-------- | :-------- | :---------- | :------- |
| deviceId  | `string`  | Device ID   | Yes      |

**Response Parameters code**

code: 0 (**Success**) Picture-in-picture enabled directly Others (**Failure**)

**Example**

```javascript

import { openFloatWindow } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await openFloatWindow(deviceId);

```

**Response Example**

```json
{
  "code": 0
}
```

## 7. Low Power Wake-up

**Description**

For low-power devices using dpId (**149**) and dpCode (**wireless_awake**), it is necessary to call the wake-up function at least three times with 200ms intervals before establishing the connection.

**Request Parameters**

| Parameter | Data Type | Description | Required |
| :-------- | :-------- | :---------- | :------- |
| deviceId  | `string`  | Device ID   | Yes      |

**Response Parameter: code**

code: 0 (**Success**) Method call succeeded; others indicate (**Failure**)

**Example**

```javascript

import { wakeUpDevice } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';

const result = await wakeUpDevice(deviceId);

```

**Response Example**

```json
{
  "code": 0
}
```

## 8. Get Current Mobile Screen Orientation

**Description**

Get the current screen orientation of the mobile device once.

**Response Parameters data**

portrait (**portrait mode**) landscape (**landscape mode**)

**Example**

```javascript

import { getMobileOrientation } from '@ray-js/ray-ipc-utils';

const result = await getMobileOrientation();

```

**Response Example**

```json
{
  "code": 0,
  "data": "portrait"
}
```

## 9. Set Screen Orientation

**Description**

Manually set the screen orientation to portrait or landscape.  
If the player contains landscape videos, the current page configuration (**index.config.ts**) must have **pageOrientation** set to **auto** for proper rotation.

**Request Parameters**

| Parameter       | Data Type                 | Description        | Required |
| :-------------- | :------------------------ | :----------------- | :------- |
| pageOrientation | `portrait` or `landscape` | Screen orientation | Yes      |

**Response Parameters data**

portrait (**portrait mode**) landscape (**landscape mode**)

**Example**

```javascript

import { setScreenOrientation } from '@ray-js/ray-ipc-utils';

const pageOrientation = 'portrait';

const result = await setScreenOrientation(pageOrientation);

```

**Response Example**

```json
{
  "code": 0,
}
```

## 10. Get Value-Added Service URL

**Description**

Retrieve URLs for various common value-added services, or directly navigate to the corresponding service pages.

**Request Parameters**

| Parameter   | Data Type     | Description                  | Required |
| :---------- | :------------ | :--------------------------- | :------- |
| deviceId    | `string`      | Device ID                    | Yes      |
| serviceType | `ServiceType` | Service type                 | Yes      |
| params      | `Params`      | Parameters for service       | Yes      |
| action      | `bool`        | Whether to navigate directly | No       |

**Service Types: ServiceType**

| Type                   | Description       |
| :--------------------- | :---------------- |
| security_cloud_service | Cloud Storage     |
| ai_service             | AI Cloud Service  |
| aiInspectionReport     | Inspection Report |
| traffic_service        | 4G Data Traffic   |

> **Note** Value-added services are continuously expanding. If some services are not covered or different services require different parameters, please contact the Tuya Mini Program team for feedback. We will respond promptly.

**Response Parameters data**

**Example**

```javascript

import { getServiceUrl } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';
const serviceType = 'security_cloud_service';
const params = {}

// If serviceType is aiInspectionReport, you need to pass activeTime, reportId, and devId

// const params = {
//   activeTime: 'xxx',
//   reportId: 'xxx',
//   devId: 'xxx'
// };

const action = true;

const result = await getServiceUrl(deviceId, serviceType, params, true);

```

**Response Example**

```json
{
  "code": 0,
}
```

## 11. Navigate to IPC Settings Mini Program

**Description**

Navigate to the IPC device settings mini program page, where users can configure device-related settings.

**Request Parameters**

| Parameter        | Data Type               | Description                        | Required |
| :--------------- | :---------------------- | :--------------------------------- | :------- |
| deviceId         | `string`                | Device ID                          | Yes      |
| options          | `object`                | Optional configuration             | No       |
| options.position | `'right'` or `'bottom'` | Pop-up position (default: 'right') | No       |

**Example**

```javascript

import { goToIpcSettingMini } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';
const options = {
  position: 'right'
};

const result = await goToIpcSettingMini(deviceId, options);

```

**Response Example**

```json
{
  "code": 0,
}
```

## 12. Navigate to IPC Service Hall Mini Program

**Description**

Navigate to the IPC Service Hall mini program.

**Request Parameters**

| Parameter        | Data Type               | Description                        | Required |
| :--------------- | :---------------------- | :--------------------------------- | :------- |
| options          | `object`                | Optional configuration             | No       |
| options.position | `'right'` or `'bottom'` | Pop-up position (default: 'right') | No       |

**Example**

```javascript

import { goToIpcServiceHallMini } from '@ray-js/ray-ipc-utils';

const options = {
  position: 'right'
};

const result = await goToIpcServiceHallMini(options);

```

**Response Example**

```json
{
  "code": 0,
}
```

## 13. Get Service Subscription Status

**Description**

Used to check whether a specified value-added service is subscribed for a device.

**Request Parameters**

| Parameter    | Data Type | Description  | Required |
| :----------- | :-------- | :----------- | :------- |
| deviceId     | `string`  | Device ID    | Yes      |
| categoryCode | `string`  | Service type | Yes      |

**Service Types (categoryCode)**

| categoryCode           | Description              |
| :--------------------- | :----------------------- |
| security_cloud_service | Cloud Storage            |
| ai_inspection_service  | Video Inspection Service |

> **Note** Value-added services are continuously expanding. If some services are not covered or different services require different parameters, please contact the Tuya Smart Mini Program team for feedback. We will respond promptly.

**Response Parameters data**

- true: Subscribed
- false: Not subscribed

**Example**

```javascript

import { getServiceIsOpen } from '@ray-js/ray-ipc-utils';

const deviceId = '1234567890xxxxxx';
const categoryCode = 'security_cloud_service'; // Cloud Storage

const result = await getServiceIsOpen(deviceId, categoryCode);

```

**Response Example**

```json
{
  "code": 0,
  "data": true
}
```
