@mega-yfue/eufy-sdk 0.3.0-beta.4 → 0.3.0-beta.6
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/dist/index.js +32 -14
- package/dist/index.js.map +2 -2
- package/dist/transport/push/push-client.d.ts +11 -0
- package/dist/transport/push/types.d.ts +8 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -23816,24 +23816,35 @@ function readNullTerminated(buf) {
|
|
|
23816
23816
|
function nonemptyString(value) {
|
|
23817
23817
|
return typeof value === "string" && value.trim().length > 0;
|
|
23818
23818
|
}
|
|
23819
|
-
function
|
|
23820
|
-
const
|
|
23821
|
-
let
|
|
23822
|
-
|
|
23823
|
-
|
|
23824
|
-
|
|
23825
|
-
|
|
23826
|
-
|
|
23819
|
+
function payloadLevels(env) {
|
|
23820
|
+
const levels = [env];
|
|
23821
|
+
for (let level = env; level.payload != null; ) {
|
|
23822
|
+
let next = level.payload;
|
|
23823
|
+
if (typeof next === "string") {
|
|
23824
|
+
try {
|
|
23825
|
+
next = JSON.parse(next);
|
|
23826
|
+
} catch {
|
|
23827
|
+
next = void 0;
|
|
23828
|
+
}
|
|
23827
23829
|
}
|
|
23830
|
+
level = typeof next === "object" && next ? next : {};
|
|
23831
|
+
levels.push(level);
|
|
23828
23832
|
}
|
|
23829
|
-
|
|
23833
|
+
return levels;
|
|
23834
|
+
}
|
|
23835
|
+
function normalizePushEvent(raw) {
|
|
23836
|
+
const env = raw.payload ?? {};
|
|
23837
|
+
const levels = payloadLevels(env);
|
|
23838
|
+
const p = levels[levels.length - 1];
|
|
23839
|
+
const deepestFirst = [...levels].reverse();
|
|
23840
|
+
const deviceClaims = deepestFirst.map((l) => l.device_sn).filter(nonemptyString);
|
|
23841
|
+
const levelStations = deepestFirst.map((l) => l.station_sn).filter(nonemptyString);
|
|
23842
|
+
const stationClaims = nonemptyString(p.s) ? [...levelStations, p.s] : levelStations;
|
|
23830
23843
|
const eventType = p.event_type ?? p.a;
|
|
23831
23844
|
const url = nonemptyString(p.pic_url) ? p.pic_url : nonemptyString(p.thumbnail) ? p.thumbnail : void 0;
|
|
23832
23845
|
let thumbnailCandidate;
|
|
23833
23846
|
if (url) {
|
|
23834
|
-
const deviceClaims = [p.device_sn, env.device_sn].filter(nonemptyString);
|
|
23835
23847
|
const deviceSn = deviceClaims[0];
|
|
23836
|
-
const stationClaims = [p.station_sn, env.station_sn, p.s].filter(nonemptyString);
|
|
23837
23848
|
const stationSn = stationClaims[0];
|
|
23838
23849
|
thumbnailCandidate = {
|
|
23839
23850
|
url,
|
|
@@ -23844,8 +23855,8 @@ function normalizePushEvent(raw) {
|
|
|
23844
23855
|
};
|
|
23845
23856
|
}
|
|
23846
23857
|
return {
|
|
23847
|
-
deviceSn:
|
|
23848
|
-
stationSn:
|
|
23858
|
+
deviceSn: deviceClaims[0] ?? (nonemptyString(p.s) ? p.s : void 0),
|
|
23859
|
+
stationSn: levelStations[0],
|
|
23849
23860
|
eventType,
|
|
23850
23861
|
thumbnailUrl: p.pic_url ?? p.thumbnail,
|
|
23851
23862
|
thumbnailCandidate,
|
|
@@ -23985,6 +23996,13 @@ var PushClient = class _PushClient extends EventEmitter8 {
|
|
|
23985
23996
|
}
|
|
23986
23997
|
this.socket?.destroy();
|
|
23987
23998
|
}
|
|
23999
|
+
/**
|
|
24000
|
+
* Decode one MCS `DataMessageStanza` into a {@link RawPushMessage} and the normalised event.
|
|
24001
|
+
*
|
|
24002
|
+
* `payload` carries the whole app_data envelope, with its `payload` entry (base64 of NUL-terminated
|
|
24003
|
+
* JSON) parsed in place: the envelope's own keys, `device_sn` and `station_sn` among them, sit beside
|
|
24004
|
+
* that entry.
|
|
24005
|
+
*/
|
|
23988
24006
|
handleDataMessage(object) {
|
|
23989
24007
|
if (object?.persistentId)
|
|
23990
24008
|
this.persistentIds.push(object.persistentId);
|
|
@@ -24009,7 +24027,7 @@ var PushClient = class _PushClient extends EventEmitter8 {
|
|
|
24009
24027
|
persistentId: object?.persistentId,
|
|
24010
24028
|
ttl: object?.ttl,
|
|
24011
24029
|
sent: object?.sent,
|
|
24012
|
-
payload: data
|
|
24030
|
+
payload: data
|
|
24013
24031
|
};
|
|
24014
24032
|
this.emit("message", raw);
|
|
24015
24033
|
const event = normalizePushEvent(raw);
|