alemonjs 2.1.0-alpha.12 → 2.1.0-alpha.13
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.
- package/lib/cbp/actions.js +2 -2
- package/lib/cbp/api.js +2 -2
- package/lib/cbp/connect.js +6 -6
- package/lib/cbp/index.js +3 -3
- package/lib/core/config.js +0 -1
- package/package.json +1 -1
package/lib/cbp/actions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResultCode } from '../core/code.js';
|
|
2
2
|
import { createResult } from '../core/utils.js';
|
|
3
3
|
import { generateUniqueId, actionResolves, deviceId, actionTimeouts, timeoutTime } from './config.js';
|
|
4
|
-
import * as
|
|
4
|
+
import * as flattedJSON from 'flatted';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 发送行为
|
|
@@ -16,7 +16,7 @@ const sendAction = (data) => {
|
|
|
16
16
|
// 设置设备 ID
|
|
17
17
|
data.DeviceId = deviceId;
|
|
18
18
|
// 发送消息
|
|
19
|
-
global.chatbotClient.send(
|
|
19
|
+
global.chatbotClient.send(flattedJSON.stringify(data));
|
|
20
20
|
// 12 秒后超时
|
|
21
21
|
const timeout = setTimeout(() => {
|
|
22
22
|
// 被清理了
|
package/lib/cbp/api.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ResultCode } from '../core/code.js';
|
|
2
2
|
import { createResult } from '../core/utils.js';
|
|
3
3
|
import { generateUniqueId, apiResolves, deviceId, apiTimeouts, timeoutTime } from './config.js';
|
|
4
|
-
import * as
|
|
4
|
+
import * as flattedJSON from 'flatted';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 发送行为
|
|
@@ -16,7 +16,7 @@ const sendAPI = (data) => {
|
|
|
16
16
|
// 设置设备 ID
|
|
17
17
|
data.DeviceId = deviceId;
|
|
18
18
|
// 发送消息
|
|
19
|
-
global.chatbotClient.send(
|
|
19
|
+
global.chatbotClient.send(flattedJSON.stringify(data));
|
|
20
20
|
// 12 秒后超时
|
|
21
21
|
const timeout = setTimeout(() => {
|
|
22
22
|
// 被清理了
|
package/lib/cbp/connect.js
CHANGED
|
@@ -3,7 +3,7 @@ import { onProcessor } from '../app/event-processor.js';
|
|
|
3
3
|
import { ResultCode } from '../core/code.js';
|
|
4
4
|
import { deviceId, FULL_RECEIVE_HEADER, DEVICE_ID_HEADER, USER_AGENT_HEADER, apiResolves, apiTimeouts, actionResolves, actionTimeouts, reconnectInterval, HEARTBEAT_INTERVAL } from './config.js';
|
|
5
5
|
import { createResult } from '../core/utils.js';
|
|
6
|
-
import * as
|
|
6
|
+
import * as flattedJSON from 'flatted';
|
|
7
7
|
|
|
8
8
|
// 心跳
|
|
9
9
|
const useHeartbeat = ({ ping, isConnected, terminate }) => {
|
|
@@ -116,7 +116,7 @@ const cbpClient = (url, options = {}) => {
|
|
|
116
116
|
global.chatbotClient.on('message', message => {
|
|
117
117
|
try {
|
|
118
118
|
// 解析消息
|
|
119
|
-
const parsedMessage =
|
|
119
|
+
const parsedMessage = flattedJSON.parse(message.toString());
|
|
120
120
|
logger.debug({
|
|
121
121
|
code: ResultCode.Ok,
|
|
122
122
|
message: '客户端接收到消息',
|
|
@@ -245,7 +245,7 @@ const cbpPlatform = (url, options = {
|
|
|
245
245
|
const send = (data) => {
|
|
246
246
|
if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
|
|
247
247
|
data.DeviceId = deviceId; // 设置设备 ID
|
|
248
|
-
global.chatbotPlatform.send(
|
|
248
|
+
global.chatbotPlatform.send(flattedJSON.stringify(data));
|
|
249
249
|
}
|
|
250
250
|
};
|
|
251
251
|
const actionReplys = [];
|
|
@@ -258,7 +258,7 @@ const cbpPlatform = (url, options = {
|
|
|
258
258
|
const replyAction = (data, payload) => {
|
|
259
259
|
if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
|
|
260
260
|
// 透传消费。也就是对应的设备进行处理消费。
|
|
261
|
-
global.chatbotPlatform.send(
|
|
261
|
+
global.chatbotPlatform.send(flattedJSON.stringify({
|
|
262
262
|
action: data.action,
|
|
263
263
|
payload: payload,
|
|
264
264
|
actionId: data.actionId,
|
|
@@ -269,7 +269,7 @@ const cbpPlatform = (url, options = {
|
|
|
269
269
|
const replyApi = (data, payload) => {
|
|
270
270
|
if (global.chatbotPlatform && global.chatbotPlatform.readyState === WebSocket.OPEN) {
|
|
271
271
|
// 透传消费。也就是对应的设备进行处理消费。
|
|
272
|
-
global.chatbotPlatform.send(
|
|
272
|
+
global.chatbotPlatform.send(flattedJSON.stringify({
|
|
273
273
|
action: data.action,
|
|
274
274
|
apiId: data.apiId,
|
|
275
275
|
DeviceId: data.DeviceId,
|
|
@@ -309,7 +309,7 @@ const cbpPlatform = (url, options = {
|
|
|
309
309
|
});
|
|
310
310
|
global.chatbotPlatform.on('message', message => {
|
|
311
311
|
try {
|
|
312
|
-
const data =
|
|
312
|
+
const data = flattedJSON.parse(message.toString());
|
|
313
313
|
logger.debug({
|
|
314
314
|
code: ResultCode.Ok,
|
|
315
315
|
message: '平台端接收消息',
|
package/lib/cbp/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import koaCors from '@koa/cors';
|
|
|
6
6
|
import { ResultCode } from '../core/code.js';
|
|
7
7
|
import { USER_AGENT_HEADER, DEVICE_ID_HEADER, FULL_RECEIVE_HEADER, platformClient, childrenClient, fullClient, childrenBind } from './config.js';
|
|
8
8
|
import { getConfig } from '../core/config.js';
|
|
9
|
-
import * as
|
|
9
|
+
import * as flattedJSON from 'flatted';
|
|
10
10
|
|
|
11
11
|
const cbpServer = (port, listeningListener) => {
|
|
12
12
|
if (global.chatbotServer) {
|
|
@@ -47,7 +47,7 @@ const cbpServer = (port, listeningListener) => {
|
|
|
47
47
|
ws.on('message', (message) => {
|
|
48
48
|
try {
|
|
49
49
|
// 解析消息
|
|
50
|
-
const parsedMessage =
|
|
50
|
+
const parsedMessage = flattedJSON.parse(message.toString());
|
|
51
51
|
// 1. 解析得到 actionId ,说明是消费行为请求。要广播告诉所有客户端。
|
|
52
52
|
// 2. 解析得到 name ,说明是一个事件请求。
|
|
53
53
|
// 3. 解析得到 apiId ,说明是一个接口请求。
|
|
@@ -319,7 +319,7 @@ const cbpServer = (port, listeningListener) => {
|
|
|
319
319
|
return;
|
|
320
320
|
}
|
|
321
321
|
// 连接时,需要给客户端发送主动消息
|
|
322
|
-
ws.send(
|
|
322
|
+
ws.send(flattedJSON.stringify({
|
|
323
323
|
active: 'sync',
|
|
324
324
|
payload: {
|
|
325
325
|
value: getConfig().value,
|
package/lib/core/config.js
CHANGED