eufy-security-client 3.6.0 → 3.7.1
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/.prettierignore/342/200/216 +8 -0
- package/.prettierrc +11 -0
- package/README.md +18 -0
- package/a.ts +61 -0
- package/build/error.js.map +1 -1
- package/build/eufysecurity.d.ts +1 -0
- package/build/eufysecurity.js +721 -224
- package/build/eufysecurity.js.map +1 -1
- package/build/http/api.d.ts +29 -0
- package/build/http/api.js +991 -701
- package/build/http/api.js.map +1 -1
- package/build/http/cache.js.map +1 -1
- package/build/http/const.d.ts +6 -1
- package/build/http/const.js +2044 -7536
- package/build/http/const.js.map +1 -1
- package/build/http/device.d.ts +4 -0
- package/build/http/device.js +1325 -440
- package/build/http/device.js.map +1 -1
- package/build/http/error.js.map +1 -1
- package/build/http/index.js.map +1 -1
- package/build/http/interfaces.d.ts +22 -15
- package/build/http/models.d.ts +2 -1
- package/build/http/parameter.js +74 -63
- package/build/http/parameter.js.map +1 -1
- package/build/http/station.d.ts +20 -2
- package/build/http/station.js +8639 -3566
- package/build/http/station.js.map +1 -1
- package/build/http/types.d.ts +12 -0
- package/build/http/types.js +297 -155
- package/build/http/types.js.map +1 -1
- package/build/http/utils.d.ts +16 -6
- package/build/http/utils.js +335 -208
- package/build/http/utils.js.map +1 -1
- package/build/index.js.map +1 -1
- package/build/interfaces.d.ts +4 -3
- package/build/logging.js +8 -13
- package/build/logging.js.map +1 -1
- package/build/mqtt/interface.d.ts +2 -2
- package/build/mqtt/service.js +12 -3
- package/build/mqtt/service.js.map +1 -1
- package/build/p2p/ble.js +7 -6
- package/build/p2p/ble.js.map +1 -1
- package/build/p2p/error.js.map +1 -1
- package/build/p2p/interfaces.d.ts +41 -6
- package/build/p2p/session.js +1484 -383
- package/build/p2p/session.js.map +1 -1
- package/build/p2p/talkback.js.map +1 -1
- package/build/p2p/types.js +36 -36
- package/build/p2p/types.js.map +1 -1
- package/build/p2p/utils.d.ts +10 -0
- package/build/p2p/utils.js +183 -90
- package/build/p2p/utils.js.map +1 -1
- package/build/push/client.js +15 -4
- package/build/push/client.js.map +1 -1
- package/build/push/error.js.map +1 -1
- package/build/push/interfaces.d.ts +8 -8
- package/build/push/models.js.map +1 -1
- package/build/push/parser.js +6 -2
- package/build/push/parser.js.map +1 -1
- package/build/push/service.js +214 -85
- package/build/push/service.js.map +1 -1
- package/build/push/types.js.map +1 -1
- package/build/push/utils.js.map +1 -1
- package/build/utils.js +7 -15
- package/build/utils.js.map +1 -1
- package/coverage/clover.xml +11133 -13648
- package/coverage/coverage-final.json +20 -30
- package/coverage/lcov-report/error.ts.html +3 -3
- package/coverage/lcov-report/index.html +50 -65
- package/coverage/lcov-report/logging.ts.html +598 -0
- package/coverage/lcov.info +21072 -25751
- package/dont-care.js +101 -0
- package/package.json +9 -5
- package/build/package.json +0 -81
package/build/push/service.js
CHANGED
|
@@ -106,11 +106,11 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
106
106
|
throwHttpErrors: false,
|
|
107
107
|
retry: {
|
|
108
108
|
limit: 3,
|
|
109
|
-
methods: ["POST"]
|
|
109
|
+
methods: ["POST"],
|
|
110
110
|
},
|
|
111
111
|
hooks: {
|
|
112
112
|
beforeError: [
|
|
113
|
-
error => {
|
|
113
|
+
(error) => {
|
|
114
114
|
const { response, options } = error;
|
|
115
115
|
const statusCode = response?.statusCode || 0;
|
|
116
116
|
const { method, url, prefixUrl } = options;
|
|
@@ -121,9 +121,9 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
121
121
|
error.message = `${statusCode} ${method} ${shortUrl}\n${body}`;
|
|
122
122
|
}
|
|
123
123
|
return error;
|
|
124
|
-
}
|
|
125
|
-
]
|
|
126
|
-
}
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
127
|
});
|
|
128
128
|
if (response.statusCode == 200) {
|
|
129
129
|
const result = response.body;
|
|
@@ -136,8 +136,14 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
136
136
|
};
|
|
137
137
|
}
|
|
138
138
|
else {
|
|
139
|
-
logging_1.rootPushLogger.error("Register FID - Status return code not 200", {
|
|
140
|
-
|
|
139
|
+
logging_1.rootPushLogger.error("Register FID - Status return code not 200", {
|
|
140
|
+
status: response.statusCode,
|
|
141
|
+
statusText: response.statusMessage,
|
|
142
|
+
data: response.body,
|
|
143
|
+
});
|
|
144
|
+
throw new error_1.FidRegistrationFailedError("FID registration failed", {
|
|
145
|
+
context: { status: response.statusCode, statusText: response.statusMessage, data: response.body },
|
|
146
|
+
});
|
|
141
147
|
}
|
|
142
148
|
}
|
|
143
149
|
catch (err) {
|
|
@@ -155,24 +161,24 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
155
161
|
installation: {
|
|
156
162
|
appId: `${this.APP_ID}`,
|
|
157
163
|
sdkVersion: "a:16.3.1",
|
|
158
|
-
}
|
|
164
|
+
},
|
|
159
165
|
},
|
|
160
166
|
headers: {
|
|
161
167
|
"X-Android-Package": `${this.APP_PACKAGE}`,
|
|
162
168
|
"X-Android-Cert": `${this.APP_CERT_SHA1}`,
|
|
163
169
|
"x-goog-api-key": `${this.GOOGLE_API_KEY}`,
|
|
164
|
-
Authorization: `${this.AUTH_VERSION} ${refreshToken}
|
|
170
|
+
Authorization: `${this.AUTH_VERSION} ${refreshToken}`,
|
|
165
171
|
},
|
|
166
172
|
responseType: "json",
|
|
167
173
|
http2: false,
|
|
168
174
|
throwHttpErrors: false,
|
|
169
175
|
retry: {
|
|
170
176
|
limit: 3,
|
|
171
|
-
methods: ["POST"]
|
|
177
|
+
methods: ["POST"],
|
|
172
178
|
},
|
|
173
179
|
hooks: {
|
|
174
180
|
beforeError: [
|
|
175
|
-
error => {
|
|
181
|
+
(error) => {
|
|
176
182
|
const { response, options } = error;
|
|
177
183
|
const statusCode = response?.statusCode || 0;
|
|
178
184
|
const { method, url, prefixUrl } = options;
|
|
@@ -183,9 +189,9 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
183
189
|
error.message = `${statusCode} ${method} ${shortUrl}\n${body}`;
|
|
184
190
|
}
|
|
185
191
|
return error;
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
}
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
},
|
|
189
195
|
});
|
|
190
196
|
if (response.statusCode == 200) {
|
|
191
197
|
const result = response.body;
|
|
@@ -195,14 +201,23 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
195
201
|
};
|
|
196
202
|
}
|
|
197
203
|
else {
|
|
198
|
-
logging_1.rootPushLogger.error("Renew FID Token - Status return code not 200", {
|
|
199
|
-
|
|
204
|
+
logging_1.rootPushLogger.error("Renew FID Token - Status return code not 200", {
|
|
205
|
+
status: response.statusCode,
|
|
206
|
+
statusText: response.statusMessage,
|
|
207
|
+
data: response.body,
|
|
208
|
+
});
|
|
209
|
+
throw new error_1.RenewFidTokenFailedError("FID Token renewal failed", {
|
|
210
|
+
context: { status: response.statusCode, statusText: response.statusMessage, data: response.body },
|
|
211
|
+
});
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
catch (err) {
|
|
203
215
|
const error = (0, error_2.ensureError)(err);
|
|
204
216
|
logging_1.rootPushLogger.error("Renew FID Token - Generic Error", { error: (0, utils_3.getError)(error) });
|
|
205
|
-
throw new error_1.RenewFidTokenFailedError("FID Token renewal failed", {
|
|
217
|
+
throw new error_1.RenewFidTokenFailedError("FID Token renewal failed", {
|
|
218
|
+
cause: error,
|
|
219
|
+
context: { fid: fid, refreshToken: refreshToken },
|
|
220
|
+
});
|
|
206
221
|
}
|
|
207
222
|
}
|
|
208
223
|
async createPushCredentials() {
|
|
@@ -212,7 +227,7 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
212
227
|
const checkinResponse = await this.executeCheckin();
|
|
213
228
|
return {
|
|
214
229
|
fidResponse: registerFidResponse,
|
|
215
|
-
checkinResponse: checkinResponse
|
|
230
|
+
checkinResponse: checkinResponse,
|
|
216
231
|
};
|
|
217
232
|
})
|
|
218
233
|
.then(async (result) => {
|
|
@@ -221,7 +236,8 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
221
236
|
...result,
|
|
222
237
|
gcmResponse: registerGcmResponse,
|
|
223
238
|
};
|
|
224
|
-
})
|
|
239
|
+
})
|
|
240
|
+
.catch((err) => {
|
|
225
241
|
const error = (0, error_2.ensureError)(err);
|
|
226
242
|
throw error;
|
|
227
243
|
});
|
|
@@ -274,11 +290,11 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
274
290
|
throwHttpErrors: false,
|
|
275
291
|
retry: {
|
|
276
292
|
limit: 3,
|
|
277
|
-
methods: ["POST"]
|
|
293
|
+
methods: ["POST"],
|
|
278
294
|
},
|
|
279
295
|
hooks: {
|
|
280
296
|
beforeError: [
|
|
281
|
-
error => {
|
|
297
|
+
(error) => {
|
|
282
298
|
const { response, options } = error;
|
|
283
299
|
const statusCode = response?.statusCode || 0;
|
|
284
300
|
const { method, url, prefixUrl } = options;
|
|
@@ -289,16 +305,22 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
289
305
|
error.message = `${statusCode} ${method} ${shortUrl}\n${body}`;
|
|
290
306
|
}
|
|
291
307
|
return error;
|
|
292
|
-
}
|
|
293
|
-
]
|
|
294
|
-
}
|
|
308
|
+
},
|
|
309
|
+
],
|
|
310
|
+
},
|
|
295
311
|
});
|
|
296
312
|
if (response.statusCode == 200) {
|
|
297
313
|
return await (0, utils_1.parseCheckinResponse)(response.body);
|
|
298
314
|
}
|
|
299
315
|
else {
|
|
300
|
-
logging_1.rootPushLogger.error("Check in - Status return code not 200", {
|
|
301
|
-
|
|
316
|
+
logging_1.rootPushLogger.error("Check in - Status return code not 200", {
|
|
317
|
+
status: response.statusCode,
|
|
318
|
+
statusText: response.statusMessage,
|
|
319
|
+
data: response.body,
|
|
320
|
+
});
|
|
321
|
+
throw new error_1.ExecuteCheckInError("Google checkin failed", {
|
|
322
|
+
context: { status: response.statusCode, statusText: response.statusMessage, data: response.body },
|
|
323
|
+
});
|
|
302
324
|
}
|
|
303
325
|
}
|
|
304
326
|
catch (err) {
|
|
@@ -315,7 +337,11 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
315
337
|
const retry = 5;
|
|
316
338
|
try {
|
|
317
339
|
for (let retry_count = 1; retry_count <= retry; retry_count++) {
|
|
318
|
-
logging_1.rootPushLogger.debug(`Register GCM - Attempt ${retry_count} of ${retry}`, {
|
|
340
|
+
logging_1.rootPushLogger.debug(`Register GCM - Attempt ${retry_count} of ${retry}`, {
|
|
341
|
+
androidId: androidId,
|
|
342
|
+
fid: fid,
|
|
343
|
+
securityToken: securityToken,
|
|
344
|
+
});
|
|
319
345
|
const response = await this.got(url, {
|
|
320
346
|
method: "post",
|
|
321
347
|
body: qs.stringify({
|
|
@@ -353,11 +379,11 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
353
379
|
throwHttpErrors: false,
|
|
354
380
|
retry: {
|
|
355
381
|
limit: 3,
|
|
356
|
-
methods: ["POST"]
|
|
382
|
+
methods: ["POST"],
|
|
357
383
|
},
|
|
358
384
|
hooks: {
|
|
359
385
|
beforeError: [
|
|
360
|
-
error => {
|
|
386
|
+
(error) => {
|
|
361
387
|
const { response, options } = error;
|
|
362
388
|
const statusCode = response?.statusCode || 0;
|
|
363
389
|
const { method, url, prefixUrl } = options;
|
|
@@ -368,26 +394,38 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
368
394
|
error.message = `${statusCode} ${method} ${shortUrl}\n${body}`;
|
|
369
395
|
}
|
|
370
396
|
return error;
|
|
371
|
-
}
|
|
372
|
-
]
|
|
373
|
-
}
|
|
397
|
+
},
|
|
398
|
+
],
|
|
399
|
+
},
|
|
374
400
|
});
|
|
375
401
|
if (response.statusCode == 200) {
|
|
376
402
|
const result = response.body.split("=");
|
|
377
403
|
if (result[0] == "Error") {
|
|
378
|
-
logging_1.rootPushLogger.debug("GCM register error, retry...", {
|
|
404
|
+
logging_1.rootPushLogger.debug("GCM register error, retry...", {
|
|
405
|
+
retry: retry,
|
|
406
|
+
retryCount: retry_count,
|
|
407
|
+
response: response.body,
|
|
408
|
+
});
|
|
379
409
|
if (retry_count == retry)
|
|
380
|
-
throw new error_1.RegisterGcmError("Max GCM registration retries reached", {
|
|
410
|
+
throw new error_1.RegisterGcmError("Max GCM registration retries reached", {
|
|
411
|
+
context: { message: result[1], retry: retry, retryCount: retry_count },
|
|
412
|
+
});
|
|
381
413
|
}
|
|
382
414
|
else {
|
|
383
415
|
return {
|
|
384
|
-
token: result[1]
|
|
416
|
+
token: result[1],
|
|
385
417
|
};
|
|
386
418
|
}
|
|
387
419
|
}
|
|
388
420
|
else {
|
|
389
|
-
logging_1.rootPushLogger.error("Register GCM - Status return code not 200", {
|
|
390
|
-
|
|
421
|
+
logging_1.rootPushLogger.error("Register GCM - Status return code not 200", {
|
|
422
|
+
status: response.statusCode,
|
|
423
|
+
statusText: response.statusMessage,
|
|
424
|
+
data: response.body,
|
|
425
|
+
});
|
|
426
|
+
throw new error_1.RegisterGcmError("Google register to GCM failed", {
|
|
427
|
+
context: { status: response.statusCode, statusText: response.statusMessage, data: response.body },
|
|
428
|
+
});
|
|
391
429
|
}
|
|
392
430
|
await (0, utils_1.sleep)(10000 * retry_count);
|
|
393
431
|
}
|
|
@@ -396,7 +434,10 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
396
434
|
catch (err) {
|
|
397
435
|
const error = (0, error_2.ensureError)(err);
|
|
398
436
|
logging_1.rootPushLogger.error("Register GCM - Generic Error", { error: (0, utils_3.getError)(error) });
|
|
399
|
-
throw new error_1.RegisterGcmError("Google register to GCM failed", {
|
|
437
|
+
throw new error_1.RegisterGcmError("Google register to GCM failed", {
|
|
438
|
+
cause: error,
|
|
439
|
+
context: { fidInstallationResponse: fidInstallationResponse, checkinResponse: checkinResponse },
|
|
440
|
+
});
|
|
400
441
|
}
|
|
401
442
|
}
|
|
402
443
|
_normalizePushMessage(message) {
|
|
@@ -405,7 +446,7 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
405
446
|
event_time: 0,
|
|
406
447
|
type: -1,
|
|
407
448
|
station_sn: "",
|
|
408
|
-
device_sn: ""
|
|
449
|
+
device_sn: "",
|
|
409
450
|
};
|
|
410
451
|
if (message.payload.payload) {
|
|
411
452
|
const payload = message.payload;
|
|
@@ -436,28 +477,43 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
436
477
|
}
|
|
437
478
|
catch (err) {
|
|
438
479
|
const error = (0, error_2.ensureError)(err);
|
|
439
|
-
logging_1.rootPushLogger.error(`Normalize push message - alarm_type - Error`, {
|
|
480
|
+
logging_1.rootPushLogger.error(`Normalize push message - alarm_type - Error`, {
|
|
481
|
+
error: (0, utils_3.getError)(error),
|
|
482
|
+
message: message,
|
|
483
|
+
});
|
|
440
484
|
}
|
|
441
485
|
try {
|
|
442
|
-
normalizedMessage.event_time =
|
|
486
|
+
normalizedMessage.event_time =
|
|
487
|
+
alarmPushData.alert_time !== undefined
|
|
488
|
+
? (0, utils_1.convertTimestampMs)(alarmPushData.alert_time)
|
|
489
|
+
: Number.parseInt(alarmPushData.alert_time);
|
|
443
490
|
}
|
|
444
491
|
catch (err) {
|
|
445
492
|
const error = (0, error_2.ensureError)(err);
|
|
446
|
-
logging_1.rootPushLogger.error(`Normalize push message - event_time - Error`, {
|
|
493
|
+
logging_1.rootPushLogger.error(`Normalize push message - event_time - Error`, {
|
|
494
|
+
error: (0, utils_3.getError)(error),
|
|
495
|
+
message: message,
|
|
496
|
+
});
|
|
447
497
|
}
|
|
448
498
|
break;
|
|
449
499
|
}
|
|
450
500
|
}
|
|
451
501
|
else {
|
|
452
502
|
try {
|
|
453
|
-
normalizedMessage.event_time =
|
|
503
|
+
normalizedMessage.event_time =
|
|
504
|
+
payload.event_time !== undefined
|
|
505
|
+
? (0, utils_1.convertTimestampMs)(Number.parseInt(payload.event_time))
|
|
506
|
+
: Number.parseInt(payload.event_time);
|
|
454
507
|
}
|
|
455
508
|
catch (err) {
|
|
456
509
|
const error = (0, error_2.ensureError)(err);
|
|
457
510
|
logging_1.rootPushLogger.error(`Normalize push message - Type ${types_1.DeviceType[normalizedMessage.type]} CusPush - event_time - Error`, { error: (0, utils_3.getError)(error), message: message });
|
|
458
511
|
}
|
|
459
512
|
try {
|
|
460
|
-
normalizedMessage.push_time =
|
|
513
|
+
normalizedMessage.push_time =
|
|
514
|
+
payload.push_time !== undefined
|
|
515
|
+
? (0, utils_1.convertTimestampMs)(Number.parseInt(payload.push_time))
|
|
516
|
+
: Number.parseInt(payload.push_time);
|
|
461
517
|
}
|
|
462
518
|
catch (err) {
|
|
463
519
|
const error = (0, error_2.ensureError)(err);
|
|
@@ -473,18 +529,22 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
473
529
|
if ((0, utils_3.isEmpty)(normalizedMessage.device_sn) && !(0, utils_3.isEmpty)(normalizedMessage.station_sn)) {
|
|
474
530
|
normalizedMessage.device_sn = normalizedMessage.station_sn;
|
|
475
531
|
}
|
|
476
|
-
if (station_1.Station.isStationHomeBase3(normalizedMessage.type) ||
|
|
532
|
+
if (station_1.Station.isStationHomeBase3(normalizedMessage.type) ||
|
|
533
|
+
(normalizedMessage.station_sn.startsWith("T8030") && device_1.Device.isCamera(normalizedMessage.type))) {
|
|
477
534
|
const platformPushData = payload.payload;
|
|
478
535
|
normalizedMessage.name = platformPushData.name ? platformPushData.name : "";
|
|
479
536
|
normalizedMessage.channel = platformPushData.channel !== undefined ? platformPushData.channel : 0;
|
|
480
537
|
normalizedMessage.cipher = platformPushData.cipher !== undefined ? platformPushData.cipher : 0;
|
|
481
|
-
normalizedMessage.event_session =
|
|
482
|
-
|
|
538
|
+
normalizedMessage.event_session =
|
|
539
|
+
platformPushData.session_id !== undefined ? platformPushData.session_id : "";
|
|
540
|
+
normalizedMessage.event_type =
|
|
541
|
+
platformPushData.a !== undefined ? platformPushData.a : platformPushData.event_type;
|
|
483
542
|
normalizedMessage.file_path = platformPushData.file_path !== undefined ? platformPushData.file_path : "";
|
|
484
543
|
normalizedMessage.pic_url = platformPushData.pic_url !== undefined ? platformPushData.pic_url : "";
|
|
485
544
|
normalizedMessage.push_count = platformPushData.push_count !== undefined ? platformPushData.push_count : 1;
|
|
486
545
|
normalizedMessage.notification_style = platformPushData.notification_style;
|
|
487
|
-
normalizedMessage.storage_type =
|
|
546
|
+
normalizedMessage.storage_type =
|
|
547
|
+
platformPushData.storage_type !== undefined ? platformPushData.storage_type : 1;
|
|
488
548
|
normalizedMessage.msg_type = platformPushData.msg_type;
|
|
489
549
|
normalizedMessage.person_name = platformPushData.nick_name;
|
|
490
550
|
normalizedMessage.person_id = platformPushData.person_id;
|
|
@@ -494,25 +554,39 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
494
554
|
normalizedMessage.station_guard_mode = platformPushData.arming;
|
|
495
555
|
normalizedMessage.station_current_mode = platformPushData.mode;
|
|
496
556
|
normalizedMessage.alarm_delay = platformPushData.alarm_delay;
|
|
497
|
-
normalizedMessage.sound_alarm =
|
|
557
|
+
normalizedMessage.sound_alarm =
|
|
558
|
+
platformPushData.alarm !== undefined ? (platformPushData.alarm === 1 ? true : false) : undefined;
|
|
498
559
|
}
|
|
499
|
-
else if (device_1.Device.isBatteryDoorbell(normalizedMessage.type) ||
|
|
560
|
+
else if (device_1.Device.isBatteryDoorbell(normalizedMessage.type) ||
|
|
561
|
+
device_1.Device.isWiredDoorbellDual(normalizedMessage.type)) {
|
|
500
562
|
const batteryDoorbellPushData = payload.payload;
|
|
501
563
|
normalizedMessage.name = batteryDoorbellPushData.name ? batteryDoorbellPushData.name : "";
|
|
502
564
|
//Get family face names from Doorbell Dual "Family Recognition" event
|
|
503
565
|
if (batteryDoorbellPushData.objects !== undefined) {
|
|
504
|
-
normalizedMessage.person_name =
|
|
566
|
+
normalizedMessage.person_name =
|
|
567
|
+
batteryDoorbellPushData.objects.names !== undefined
|
|
568
|
+
? batteryDoorbellPushData.objects.names.join(",")
|
|
569
|
+
: "";
|
|
505
570
|
}
|
|
506
571
|
if (normalizedMessage.person_name === "") {
|
|
507
572
|
normalizedMessage.person_name = batteryDoorbellPushData.nick_name;
|
|
508
573
|
}
|
|
509
|
-
normalizedMessage.channel =
|
|
574
|
+
normalizedMessage.channel =
|
|
575
|
+
batteryDoorbellPushData.channel !== undefined ? batteryDoorbellPushData.channel : 0;
|
|
510
576
|
normalizedMessage.cipher = batteryDoorbellPushData.cipher !== undefined ? batteryDoorbellPushData.cipher : 0;
|
|
511
|
-
normalizedMessage.event_session =
|
|
577
|
+
normalizedMessage.event_session =
|
|
578
|
+
batteryDoorbellPushData.session_id !== undefined ? batteryDoorbellPushData.session_id : "";
|
|
512
579
|
normalizedMessage.event_type = batteryDoorbellPushData.event_type;
|
|
513
|
-
normalizedMessage.file_path =
|
|
514
|
-
|
|
515
|
-
|
|
580
|
+
normalizedMessage.file_path =
|
|
581
|
+
batteryDoorbellPushData.file_path !== undefined &&
|
|
582
|
+
batteryDoorbellPushData.file_path !== "" &&
|
|
583
|
+
batteryDoorbellPushData.channel !== undefined
|
|
584
|
+
? (0, utils_2.getAbsoluteFilePath)(normalizedMessage.type, batteryDoorbellPushData.channel, batteryDoorbellPushData.file_path)
|
|
585
|
+
: "";
|
|
586
|
+
normalizedMessage.pic_url =
|
|
587
|
+
batteryDoorbellPushData.pic_url !== undefined ? batteryDoorbellPushData.pic_url : "";
|
|
588
|
+
normalizedMessage.push_count =
|
|
589
|
+
batteryDoorbellPushData.push_count !== undefined ? batteryDoorbellPushData.push_count : 1;
|
|
516
590
|
normalizedMessage.notification_style = batteryDoorbellPushData.notification_style;
|
|
517
591
|
}
|
|
518
592
|
else if (device_1.Device.isIndoorCamera(normalizedMessage.type) ||
|
|
@@ -543,16 +617,16 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
543
617
|
normalizedMessage.event_type = smartSafePushData.event_type;
|
|
544
618
|
normalizedMessage.event_value = smartSafePushData.event_value;
|
|
545
619
|
/*
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
620
|
+
event_value: {
|
|
621
|
+
type: 3, 3/4
|
|
622
|
+
action: 1,
|
|
623
|
+
figure_id: 0,
|
|
624
|
+
user_id: 0
|
|
625
|
+
}
|
|
626
|
+
*/
|
|
553
627
|
normalizedMessage.name = smartSafePushData.dev_name !== undefined ? smartSafePushData.dev_name : "";
|
|
554
628
|
/*normalizedMessage.short_user_id = smartSafePushData.short_user_id !== undefined ? smartSafePushData.short_user_id : "";
|
|
555
|
-
|
|
629
|
+
normalizedMessage.user_id = smartSafePushData.user_id !== undefined ? smartSafePushData.user_id : "";*/
|
|
556
630
|
}
|
|
557
631
|
else if (device_1.Device.isLock(normalizedMessage.type) && !device_1.Device.isLockWifiVideo(normalizedMessage.type)) {
|
|
558
632
|
const lockPushData = payload.payload;
|
|
@@ -570,17 +644,30 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
570
644
|
normalizedMessage.name = garageDoorPushData.door_name !== undefined ? garageDoorPushData.door_name : "";
|
|
571
645
|
normalizedMessage.pic_url = garageDoorPushData.pic_url !== undefined ? garageDoorPushData.pic_url : "";
|
|
572
646
|
normalizedMessage.file_path = garageDoorPushData.file_path !== undefined ? garageDoorPushData.file_path : "";
|
|
573
|
-
normalizedMessage.storage_type =
|
|
647
|
+
normalizedMessage.storage_type =
|
|
648
|
+
garageDoorPushData.storage_type !== undefined ? garageDoorPushData.storage_type : 1;
|
|
574
649
|
normalizedMessage.power = garageDoorPushData.power !== undefined ? garageDoorPushData.power : undefined;
|
|
575
650
|
}
|
|
576
651
|
else {
|
|
577
652
|
const cusPushData = payload.payload;
|
|
578
|
-
normalizedMessage.name =
|
|
653
|
+
normalizedMessage.name =
|
|
654
|
+
cusPushData.device_name && cusPushData.device_name !== null && cusPushData.device_name !== ""
|
|
655
|
+
? cusPushData.device_name
|
|
656
|
+
: cusPushData.n
|
|
657
|
+
? cusPushData.n
|
|
658
|
+
: cusPushData.name
|
|
659
|
+
? cusPushData.name
|
|
660
|
+
: "";
|
|
579
661
|
normalizedMessage.channel = cusPushData.c ? cusPushData.c : cusPushData.channel;
|
|
580
662
|
normalizedMessage.cipher = cusPushData.k ? cusPushData.k : cusPushData.cipher;
|
|
581
663
|
normalizedMessage.event_session = cusPushData.session_id;
|
|
582
664
|
normalizedMessage.event_type = cusPushData.a ? cusPushData.a : cusPushData.event_type;
|
|
583
|
-
normalizedMessage.file_path =
|
|
665
|
+
normalizedMessage.file_path =
|
|
666
|
+
cusPushData.c !== undefined && cusPushData.p !== undefined && cusPushData.p !== ""
|
|
667
|
+
? (0, utils_2.getAbsoluteFilePath)(normalizedMessage.type, cusPushData.c, cusPushData.p)
|
|
668
|
+
: cusPushData.file_path
|
|
669
|
+
? cusPushData.file_path
|
|
670
|
+
: "";
|
|
584
671
|
normalizedMessage.pic_url = cusPushData.pic_url !== undefined ? cusPushData.pic_url : "";
|
|
585
672
|
normalizedMessage.push_count = cusPushData.push_count !== undefined ? cusPushData.push_count : 1;
|
|
586
673
|
normalizedMessage.notification_style = cusPushData.notification_style;
|
|
@@ -588,16 +675,24 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
588
675
|
normalizedMessage.alarm_delay_type = cusPushData.alarm_type;
|
|
589
676
|
normalizedMessage.alarm_delay = cusPushData.alarm_delay;
|
|
590
677
|
normalizedMessage.alarm_type = cusPushData.type;
|
|
591
|
-
normalizedMessage.sound_alarm =
|
|
678
|
+
normalizedMessage.sound_alarm =
|
|
679
|
+
cusPushData.alarm !== undefined ? (cusPushData.alarm === 1 ? true : false) : undefined;
|
|
592
680
|
normalizedMessage.user_name = cusPushData.user_name;
|
|
593
681
|
normalizedMessage.user_type = cusPushData.user;
|
|
594
682
|
normalizedMessage.user_id = cusPushData.user_id;
|
|
595
683
|
normalizedMessage.short_user_id = cusPushData.short_user_id;
|
|
596
684
|
normalizedMessage.station_guard_mode = cusPushData.arming;
|
|
597
685
|
normalizedMessage.station_current_mode = cusPushData.mode;
|
|
598
|
-
normalizedMessage.person_name =
|
|
599
|
-
|
|
600
|
-
|
|
686
|
+
normalizedMessage.person_name =
|
|
687
|
+
cusPushData.f && cusPushData.f !== ""
|
|
688
|
+
? cusPushData.f
|
|
689
|
+
: cusPushData.nick_name && cusPushData.nick_name
|
|
690
|
+
? cusPushData.nick_name
|
|
691
|
+
: "";
|
|
692
|
+
normalizedMessage.sensor_open =
|
|
693
|
+
cusPushData.e !== undefined ? (cusPushData.e == "1" ? true : false) : undefined;
|
|
694
|
+
normalizedMessage.device_online =
|
|
695
|
+
cusPushData.m !== undefined ? (cusPushData.m === 1 ? true : false) : undefined;
|
|
601
696
|
try {
|
|
602
697
|
normalizedMessage.fetch_id = cusPushData.i !== undefined ? Number.parseInt(cusPushData.i) : undefined;
|
|
603
698
|
}
|
|
@@ -606,9 +701,11 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
606
701
|
logging_1.rootPushLogger.error(`Normalize push message - Type ${types_1.DeviceType[normalizedMessage.type]} CusPushData - fetch_id - Error`, { error: (0, utils_3.getError)(error), message: message });
|
|
607
702
|
}
|
|
608
703
|
normalizedMessage.sense_id = cusPushData.j;
|
|
609
|
-
normalizedMessage.battery_powered =
|
|
704
|
+
normalizedMessage.battery_powered =
|
|
705
|
+
cusPushData.batt_powered !== undefined ? (cusPushData.batt_powered === 1 ? true : false) : undefined;
|
|
610
706
|
try {
|
|
611
|
-
normalizedMessage.battery_low =
|
|
707
|
+
normalizedMessage.battery_low =
|
|
708
|
+
cusPushData.bat_low !== undefined ? Number.parseInt(cusPushData.bat_low) : undefined;
|
|
612
709
|
}
|
|
613
710
|
catch (err) {
|
|
614
711
|
const error = (0, error_2.ensureError)(err);
|
|
@@ -665,12 +762,18 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
665
762
|
if (doorbellPushData !== undefined) {
|
|
666
763
|
normalizedMessage.name = "Doorbell";
|
|
667
764
|
normalizedMessage.type = 5;
|
|
668
|
-
normalizedMessage.event_time =
|
|
765
|
+
normalizedMessage.event_time =
|
|
766
|
+
doorbellPushData.create_time !== undefined
|
|
767
|
+
? (0, utils_1.convertTimestampMs)(doorbellPushData.create_time)
|
|
768
|
+
: doorbellPushData.create_time;
|
|
669
769
|
normalizedMessage.station_sn = doorbellPushData.device_sn;
|
|
670
770
|
normalizedMessage.device_sn = doorbellPushData.device_sn;
|
|
671
771
|
normalizedMessage.title = doorbellPushData.title;
|
|
672
772
|
normalizedMessage.content = doorbellPushData.content;
|
|
673
|
-
normalizedMessage.push_time =
|
|
773
|
+
normalizedMessage.push_time =
|
|
774
|
+
doorbellPushData.event_time !== undefined
|
|
775
|
+
? (0, utils_1.convertTimestampMs)(doorbellPushData.event_time)
|
|
776
|
+
: doorbellPushData.event_time;
|
|
674
777
|
normalizedMessage.channel = doorbellPushData.channel;
|
|
675
778
|
normalizedMessage.cipher = doorbellPushData.cipher;
|
|
676
779
|
normalizedMessage.event_session = doorbellPushData.event_session;
|
|
@@ -713,33 +816,53 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
713
816
|
return this.persistentIds;
|
|
714
817
|
}
|
|
715
818
|
async _open(renew = false, forceNew = false) {
|
|
716
|
-
if (forceNew ||
|
|
819
|
+
if (forceNew ||
|
|
820
|
+
!this.credentials ||
|
|
821
|
+
Object.keys(this.credentials).length === 0 ||
|
|
822
|
+
(this.credentials &&
|
|
823
|
+
this.credentials.fidResponse &&
|
|
824
|
+
new Date().getTime() >= this.credentials.fidResponse.authToken.expiresAt)) {
|
|
717
825
|
logging_1.rootPushLogger.debug(`Create new push credentials...`, { credentials: this.credentials, renew: renew });
|
|
718
|
-
this.credentials = await this.createPushCredentials().catch(err => {
|
|
826
|
+
this.credentials = await this.createPushCredentials().catch((err) => {
|
|
719
827
|
const error = (0, error_2.ensureError)(err);
|
|
720
|
-
logging_1.rootPushLogger.error("Create push credentials Error", {
|
|
828
|
+
logging_1.rootPushLogger.error("Create push credentials Error", {
|
|
829
|
+
error: (0, utils_3.getError)(error),
|
|
830
|
+
credentials: this.credentials,
|
|
831
|
+
renew: renew,
|
|
832
|
+
});
|
|
721
833
|
return undefined;
|
|
722
834
|
});
|
|
723
835
|
}
|
|
724
836
|
else if (this.credentials && renew) {
|
|
725
837
|
logging_1.rootPushLogger.debug(`Renew push credentials...`, { credentials: this.credentials, renew: renew });
|
|
726
|
-
this.credentials = await this.renewPushCredentials(this.credentials).catch(err => {
|
|
838
|
+
this.credentials = await this.renewPushCredentials(this.credentials).catch((err) => {
|
|
727
839
|
const error = (0, error_2.ensureError)(err);
|
|
728
|
-
logging_1.rootPushLogger.error("Push credentials renew Error", {
|
|
840
|
+
logging_1.rootPushLogger.error("Push credentials renew Error", {
|
|
841
|
+
error: (0, utils_3.getError)(error),
|
|
842
|
+
credentials: this.credentials,
|
|
843
|
+
renew: renew,
|
|
844
|
+
});
|
|
729
845
|
return undefined;
|
|
730
846
|
});
|
|
731
847
|
}
|
|
732
848
|
else {
|
|
733
849
|
logging_1.rootPushLogger.debug(`Login with previous push credentials...`, { credentials: this.credentials });
|
|
734
|
-
this.credentials = await this.loginPushCredentials(this.credentials).catch(err => {
|
|
850
|
+
this.credentials = await this.loginPushCredentials(this.credentials).catch((err) => {
|
|
735
851
|
const error = (0, error_2.ensureError)(err);
|
|
736
|
-
logging_1.rootPushLogger.error("Push credentials login Error", {
|
|
852
|
+
logging_1.rootPushLogger.error("Push credentials login Error", {
|
|
853
|
+
error: (0, utils_3.getError)(error),
|
|
854
|
+
credentials: this.credentials,
|
|
855
|
+
renew: renew,
|
|
856
|
+
});
|
|
737
857
|
return undefined;
|
|
738
858
|
});
|
|
739
859
|
}
|
|
740
860
|
if (this.credentials) {
|
|
741
861
|
this.emit("credential", this.credentials);
|
|
742
|
-
logging_1.rootPushLogger.debug("Push notification token received", {
|
|
862
|
+
logging_1.rootPushLogger.debug("Push notification token received", {
|
|
863
|
+
token: this.credentials.gcmResponse.token,
|
|
864
|
+
credentials: this.credentials,
|
|
865
|
+
});
|
|
743
866
|
this.clearCredentialsTimeout();
|
|
744
867
|
this.credentialsTimeout = setTimeout(async () => {
|
|
745
868
|
logging_1.rootPushLogger.info("Push notification token is expiring, renew it.");
|
|
@@ -773,7 +896,10 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
773
896
|
this.emit("close");
|
|
774
897
|
this.connected = false;
|
|
775
898
|
this.connecting = false;
|
|
776
|
-
logging_1.rootPushLogger.error("Push notifications are disabled, because the registration failed!", {
|
|
899
|
+
logging_1.rootPushLogger.error("Push notifications are disabled, because the registration failed!", {
|
|
900
|
+
credentials: this.credentials,
|
|
901
|
+
renew: renew,
|
|
902
|
+
});
|
|
777
903
|
}
|
|
778
904
|
}
|
|
779
905
|
async open() {
|
|
@@ -781,7 +907,10 @@ class PushNotificationService extends tiny_typed_emitter_1.TypedEmitter {
|
|
|
781
907
|
this.connecting = true;
|
|
782
908
|
await this._open(false, true).catch((err) => {
|
|
783
909
|
const error = (0, error_2.ensureError)(err);
|
|
784
|
-
logging_1.rootPushLogger.error(`Got exception trying to initialize push notifications`, {
|
|
910
|
+
logging_1.rootPushLogger.error(`Got exception trying to initialize push notifications`, {
|
|
911
|
+
error: (0, utils_3.getError)(error),
|
|
912
|
+
credentials: this.credentials,
|
|
913
|
+
});
|
|
785
914
|
});
|
|
786
915
|
if (!this.credentials) {
|
|
787
916
|
this.clearRetryTimeout();
|