@ray-js/robot-data-stream 0.0.15-beta.7 → 0.0.15-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -72,7 +72,7 @@ export class SweeperP2p extends P2pApi {
72
72
  this.packetTotalMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
73
73
  this.packetSerialNumberCacheMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
74
74
  this.fileLengthCacheMap = new Map([['map.bin', -1], ['map_structured.bin', -1], ['cleanPath.bin', -1], ['ai.bin', -1], ['aiHD_XXXX_YYYY.bin', -1], ['map.bin.stream', -1], ['map_structured.bin.stream', -1], ['cleanPath.bin.stream', -1], ['ai.bin.stream', -1], ['aiHD_XXXX_YYYY.bin.stream', -1]]);
75
- this.packetDataCacheMap = new Map([['map.bin', new Map()], ['map_structured.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['map_structured.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
75
+ this.packetDataCacheMap = new Map([['map.bin', new Map()], ['map_structured.bin', new Map()], ['cleanPath.bin', new Map()], ['ai.bin', new Map()], ['aiHD_XXXX_YYYY.bin', new Map()], ['map.bin.stream', new Map()], ['map_structured.bin.stream', new Map()], ['cleanPath.bin.stream', new Map()], ['wifi_map.bin', new Map()], ['wifi_map.bin.stream', new Map()], ['ai.bin.stream', new Map()], ['aiHD_XXXX_YYYY.bin.stream', new Map()]]);
76
76
  }
77
77
  setStreamFilePath = () => {
78
78
  // this.streamFilePath = this.cacheDir + `/${this.albumName}/${devId}/stream`;
@@ -59,51 +59,94 @@ export const useStructuredMessage = () => {
59
59
  return;
60
60
  }
61
61
  try {
62
- var _ty, _ty2;
63
62
  const params = createSetCommonParams({
64
63
  deviceId: devId,
65
64
  reqType,
66
65
  message,
67
66
  isLocalOnLine: isLocalOnLineRef.current
68
67
  });
68
+ const {
69
+ preferredChannel
70
+ } = context;
69
71
 
70
- // 优先使用局域网通信(LAN)
71
- if (isLocalOnLineRef.current && (_ty = ty) !== null && _ty !== void 0 && _ty.device && isFunction(ty.device.publishLanMessage)) {
72
- // @ts-ignore - publishLanMessage 可能不存在于类型定义中
73
- ty.device.publishLanMessage(_objectSpread(_objectSpread({}, params), {}, {
74
- success: () => {
75
- logger('info', {
76
- msg: `${reqType} LAN message publish success: ${JSON.stringify(params)}`
77
- });
78
- // 局域网通信成功回调
79
- },
80
- fail: e => {
81
- logger('error', {
82
- msg: `${reqType} LAN message publish failed: ${JSON.stringify(e)}`
83
- });
84
- }
85
- }));
86
- }
87
- // 如果局域网不可用,使用 WiFi MQTT 通信
88
- else if (isWifiOnLineRef.current && (_ty2 = ty) !== null && _ty2 !== void 0 && _ty2.device && isFunction(ty.device.sendMqttMessage)) {
89
- ty.device.sendMqttMessage(_objectSpread(_objectSpread({}, params), {}, {
90
- success: () => {
91
- // WiFi MQTT 通信成功回调
92
- logger('info', {
93
- msg: `${reqType} WiFi MQTT message send success: ${JSON.stringify(params)}`
94
- });
95
- },
96
- fail: e => {
97
- logger('error', {
98
- msg: `${reqType} MQTT message send failed: ${JSON.stringify(e)}`
99
- });
100
- }
101
- }));
102
- }
103
- // 如果两种通信方式都不可用,抛出错误
104
- else {
105
- reject(new Error(`No available communication method. LAN online: ${isLocalOnLineRef.current}, WiFi online: ${isWifiOnLineRef.current}`));
106
- return;
72
+ // 根据 preferredChannel 决定优先使用的通信通道
73
+ if (preferredChannel === 'mqtt') {
74
+ var _ty, _ty2;
75
+ // 优先使用 WiFi MQTT 通信
76
+ if (isWifiOnLineRef.current && (_ty = ty) !== null && _ty !== void 0 && _ty.device && isFunction(ty.device.sendMqttMessage)) {
77
+ ty.device.sendMqttMessage(_objectSpread(_objectSpread({}, params), {}, {
78
+ success: () => {
79
+ // WiFi MQTT 通信成功回调
80
+ logger('info', {
81
+ msg: `${reqType} WiFi MQTT message send success: ${JSON.stringify(params)}`
82
+ });
83
+ },
84
+ fail: e => {
85
+ logger('error', {
86
+ msg: `${reqType} MQTT message send failed: ${JSON.stringify(e)}`
87
+ });
88
+ }
89
+ }));
90
+ }
91
+ // 如果 MQTT 不可用,尝试使用局域网通信(LAN)
92
+ else if (isLocalOnLineRef.current && (_ty2 = ty) !== null && _ty2 !== void 0 && _ty2.device && isFunction(ty.device.publishLanMessage)) {
93
+ // @ts-ignore - publishLanMessage 可能不存在于类型定义中
94
+ ty.device.publishLanMessage(_objectSpread(_objectSpread({}, params), {}, {
95
+ success: () => {
96
+ logger('info', {
97
+ msg: `${reqType} LAN message publish success (fallback): ${JSON.stringify(params)}`
98
+ });
99
+ },
100
+ fail: e => {
101
+ logger('error', {
102
+ msg: `${reqType} LAN message publish failed: ${JSON.stringify(e)}`
103
+ });
104
+ }
105
+ }));
106
+ }
107
+ // 如果两种通信方式都不可用,抛出错误
108
+ else {
109
+ reject(new Error(`No available communication method. LAN online: ${isLocalOnLineRef.current}, WiFi online: ${isWifiOnLineRef.current}`));
110
+ return;
111
+ }
112
+ } else {
113
+ var _ty3, _ty4;
114
+ // 优先使用局域网通信(LAN)
115
+ if (isLocalOnLineRef.current && (_ty3 = ty) !== null && _ty3 !== void 0 && _ty3.device && isFunction(ty.device.publishLanMessage)) {
116
+ // @ts-ignore - publishLanMessage 可能不存在于类型定义中
117
+ ty.device.publishLanMessage(_objectSpread(_objectSpread({}, params), {}, {
118
+ success: () => {
119
+ logger('info', {
120
+ msg: `${reqType} LAN message publish success: ${JSON.stringify(params)}`
121
+ });
122
+ },
123
+ fail: e => {
124
+ logger('error', {
125
+ msg: `${reqType} LAN message publish failed: ${JSON.stringify(e)}`
126
+ });
127
+ }
128
+ }));
129
+ }
130
+ // 如果局域网不可用,使用 WiFi MQTT 通信
131
+ else if (isWifiOnLineRef.current && (_ty4 = ty) !== null && _ty4 !== void 0 && _ty4.device && isFunction(ty.device.sendMqttMessage)) {
132
+ ty.device.sendMqttMessage(_objectSpread(_objectSpread({}, params), {}, {
133
+ success: () => {
134
+ logger('info', {
135
+ msg: `${reqType} WiFi MQTT message send success (fallback): ${JSON.stringify(params)}`
136
+ });
137
+ },
138
+ fail: e => {
139
+ logger('error', {
140
+ msg: `${reqType} MQTT message send failed: ${JSON.stringify(e)}`
141
+ });
142
+ }
143
+ }));
144
+ }
145
+ // 如果两种通信方式都不可用,抛出错误
146
+ else {
147
+ reject(new Error(`No available communication method. LAN online: ${isLocalOnLineRef.current}, WiFi online: ${isWifiOnLineRef.current}`));
148
+ return;
149
+ }
107
150
  }
108
151
  // 如果指定了响应类型,使用响应类型;否则使用请求类型
109
152
 
@@ -1,8 +1,10 @@
1
1
  import React from 'react';
2
2
  import { MqttError } from './promise';
3
+ export type CommunicationChannel = 'mqtt' | 'lan';
3
4
  export interface MqttContextValue {
4
5
  useMqtt: boolean;
5
6
  commandVersion: '0' | '1';
7
+ preferredChannel: CommunicationChannel;
6
8
  devices: {
7
9
  common: {
8
10
  getDevInfo: () => {
@@ -26,6 +28,13 @@ export interface MqttProviderProps {
26
28
  useMqtt: boolean;
27
29
  commandVersion: '0' | '1';
28
30
  devices: MqttContextValue['devices'];
31
+ /**
32
+ * 优先选择的通信通道
33
+ * - 'mqtt': 优先使用 MQTT 通道(WiFi MQTT)
34
+ * - 'lan': 优先使用局域网通道(LAN)
35
+ * @default 'mqtt'
36
+ */
37
+ preferredChannel?: CommunicationChannel;
29
38
  onMqttReady?: () => void;
30
39
  /**
31
40
  * 可选的错误处理回调
@@ -45,7 +54,7 @@ export interface MqttProviderProps {
45
54
  onError?: MqttErrorHandler;
46
55
  }
47
56
  export declare function useMqtt(): MqttContextValue;
48
- export declare function MqttProvider({ children, useMqtt, commandVersion, devices, onError, onMqttReady, }: MqttProviderProps): React.JSX.Element;
57
+ export declare function MqttProvider({ children, useMqtt, commandVersion, devices, preferredChannel, onError, onMqttReady, }: MqttProviderProps): React.JSX.Element;
49
58
  export declare namespace MqttProvider {
50
59
  var defaultProps: {
51
60
  onMqttReady: undefined;
@@ -7,6 +7,8 @@ import { setUnhandledRejectionHandler } from './promise';
7
7
  import { ProtocolEnum } from './type';
8
8
  import log4js from '@ray-js/log4js';
9
9
 
10
+ // 通信通道类型
11
+
10
12
  // Context 类型定义
11
13
 
12
14
  // 创建一个Context
@@ -32,6 +34,7 @@ export function MqttProvider(_ref) {
32
34
  useMqtt,
33
35
  commandVersion,
34
36
  devices,
37
+ preferredChannel = 'mqtt',
35
38
  onError,
36
39
  onMqttReady
37
40
  } = _ref;
@@ -42,10 +45,9 @@ export function MqttProvider(_ref) {
42
45
  const instance = useMemo(() => ({
43
46
  useMqtt,
44
47
  commandVersion,
48
+ preferredChannel,
45
49
  devices
46
- // isLocalOnLine,
47
- // isWifiOnLine,
48
- }), [useMqtt, commandVersion, devices]);
50
+ }), [useMqtt, commandVersion, preferredChannel, devices]);
49
51
 
50
52
  // 使用 ref 存储设备 ID 和初始化状态,避免重复初始化
51
53
  const devIdRef = useRef(null);
@@ -198,7 +198,7 @@ export declare const ProtocolSchemas: {
198
198
  position: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniArray<import("../../myLib/zod/src/v4/mini/schemas").ZodMiniNumber<number>>;
199
199
  subDevId: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniString<string>;
200
200
  }, z.core.$strip>>;
201
- set_carpet_clean: any;
201
+ set_carpet_clean: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniArray<import("../../myLib/zod/src/v4/mini/schemas").ZodMiniNumber<number>>;
202
202
  set_room_property: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniObject<{
203
203
  num: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniOptional<import("../../myLib/zod/src/v4/mini/schemas").ZodMiniNumberFormat>;
204
204
  ids: import("../../myLib/zod/src/v4/mini/schemas").ZodMiniArray<import("../../myLib/zod/src/v4/mini/schemas").ZodMiniNumberFormat>;
@@ -1,5 +1,5 @@
1
1
  import * as z from '../../../myLib/zod/mini';
2
- declare const setCarpetCleanSchema: import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniArray<import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniNumber<number>>;
2
+ export declare const setCarpetCleanSchema: import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniArray<import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniNumber<number>>;
3
3
  declare const carpetCleanResponseSchema: import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniObject<{
4
4
  success: import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniBoolean<boolean>;
5
5
  errCode: import("../../../myLib/zod/src/v4/mini/schemas").ZodMiniNumber<number>;
@@ -2,7 +2,7 @@ import * as z from '../../../myLib/zod/mini';
2
2
  import { BaseResponseSchema } from './base';
3
3
 
4
4
  // 设置地毯清扫参数 Schema
5
- const setCarpetCleanSchema = z.array(z.number()); // 地毯ID数组,注意: .min()放在数组元素上
5
+ export const setCarpetCleanSchema = z.array(z.number()); // 地毯ID数组,注意: .min()放在数组元素上
6
6
 
7
7
  // 地毯清扫响应 Schema
8
8
  const carpetCleanResponseSchema = z.extend(BaseResponseSchema, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.0.15-beta.7",
3
+ "version": "0.0.15-beta.9",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [