@mega-yfue/eufy-sdk 0.5.0-beta.83 → 0.5.0-beta.84
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 +7 -53
- package/dist/index.js.map +2 -2
- package/dist/transport/p2p/p2p-session.d.ts +0 -21
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16227,10 +16227,6 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16227
16227
|
* change (the level-2 key arrived after an initial level-1 start), otherwise sends the 1139 nudge.
|
|
16228
16228
|
*/
|
|
16229
16229
|
liveStartedChannels = /* @__PURE__ */ new Map();
|
|
16230
|
-
/** The `cipher_id` this connection's `CMD_GATEWAYINFO` reply named, once its negotiation has read it. */
|
|
16231
|
-
gatewayCipherId;
|
|
16232
|
-
/** The `n` of the last `[0x01, n]` header this connection sent in the clear — see {@link nextClearCommandBytes}. */
|
|
16233
|
-
clearCommandCount = 0;
|
|
16234
16230
|
unackedLiveStarts = /* @__PURE__ */ new Map();
|
|
16235
16231
|
liveStartRetransmitTimer;
|
|
16236
16232
|
logger;
|
|
@@ -16428,7 +16424,6 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16428
16424
|
this.level2Negotiating = true;
|
|
16429
16425
|
const generation = this.connectionGeneration;
|
|
16430
16426
|
const cipherId = gatewayInfoCipherId(gwPayload);
|
|
16431
|
-
this.gatewayCipherId = cipherId;
|
|
16432
16427
|
this.trace({ phase: "level2-negotiating", cipherId });
|
|
16433
16428
|
void (async () => {
|
|
16434
16429
|
try {
|
|
@@ -16535,8 +16530,6 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16535
16530
|
this.level2Pending = this.cfg.resolveCipherKey !== void 0;
|
|
16536
16531
|
this.level2Negotiating = false;
|
|
16537
16532
|
this.level2Reprompted = false;
|
|
16538
|
-
this.gatewayCipherId = void 0;
|
|
16539
|
-
this.clearCommandCount = 0;
|
|
16540
16533
|
}
|
|
16541
16534
|
const socket = dgram.createSocket("udp4");
|
|
16542
16535
|
this.socket = socket;
|
|
@@ -16827,7 +16820,7 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16827
16820
|
this.sendMediaPayloadLevel2(CMD_START_REALTIME_MEDIA, channel, accountId, {});
|
|
16828
16821
|
return;
|
|
16829
16822
|
}
|
|
16830
|
-
const want = this.level2Key ? "l2" :
|
|
16823
|
+
const want = this.level2Key ? "l2" : "l1";
|
|
16831
16824
|
if (opts?.force) {
|
|
16832
16825
|
for (const pending of this.unackedLiveStarts.values())
|
|
16833
16826
|
if (pending.channel === channel)
|
|
@@ -16857,17 +16850,8 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16857
16850
|
* `video_type` is 12, and `transaction` is the millisecond timestamp as a string. The device answers a
|
|
16858
16851
|
* start carrying these values with a keyframe; `encryptkey` is the modulus it RSA-wraps each keyframe's
|
|
16859
16852
|
* AES media key with (unwrapped by {@link decodeVideoFrame}).
|
|
16860
|
-
*
|
|
16861
|
-
* With `clearMsgId`, the body of a start sent in the clear: `{accountId, encryptkey, msg_id, streamtype: 1}`
|
|
16862
|
-
* only, `msg_id` being `clearMsgId`, which changes from one start to the next.
|
|
16863
16853
|
*/
|
|
16864
|
-
startLiveJson(channel, accountId
|
|
16865
|
-
if (clearMsgId !== void 0) {
|
|
16866
|
-
return Buffer.from(JSON.stringify({
|
|
16867
|
-
commandType: CMD_START_LIVE,
|
|
16868
|
-
data: { accountId, encryptkey: this.rsaModulus(), msg_id: clearMsgId, streamtype: 1 }
|
|
16869
|
-
}), "utf-8");
|
|
16870
|
-
}
|
|
16854
|
+
startLiveJson(channel, accountId) {
|
|
16871
16855
|
const now2 = Date.now();
|
|
16872
16856
|
return Buffer.from(JSON.stringify({
|
|
16873
16857
|
commandType: CMD_START_LIVE,
|
|
@@ -16898,31 +16882,25 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16898
16882
|
* (GCM, signCode 8, frame type 10) when the session has a negotiated key, else level-1 (AES-128-ECB,
|
|
16899
16883
|
* signCode 1, frame type 11) — chosen by the session key, not the device family. The camera RSA-wraps
|
|
16900
16884
|
* each keyframe's AES media key with the `encryptkey` modulus (unwrapped by {@link decodeVideoFrame}).
|
|
16901
|
-
* A session that {@link sendsInTheClear} sends it unencrypted instead: signCode 0, frame type 0, header
|
|
16902
|
-
* bytes `[0x01, n]` from {@link nextClearCommandBytes}, and `n` as the body's `msg_id`.
|
|
16903
16885
|
*/
|
|
16904
16886
|
sendStartLiveOwnSession(channel, accountId) {
|
|
16905
16887
|
if (!this.connectAddress)
|
|
16906
16888
|
return;
|
|
16889
|
+
const plain = this.startLiveJson(channel, accountId);
|
|
16907
16890
|
let payload;
|
|
16908
16891
|
let signCode;
|
|
16909
16892
|
let magic;
|
|
16910
16893
|
let frameType;
|
|
16911
16894
|
if (this.level2Key) {
|
|
16912
|
-
const enc2 = this.encryptLevel2(
|
|
16895
|
+
const enc2 = this.encryptLevel2(plain);
|
|
16913
16896
|
if (!enc2)
|
|
16914
16897
|
return;
|
|
16915
16898
|
payload = enc2;
|
|
16916
16899
|
signCode = 8;
|
|
16917
16900
|
magic = [8, 0];
|
|
16918
16901
|
frameType = START_LIVE_FRAME_TYPE_L2;
|
|
16919
|
-
} else if (this.sendsInTheClear()) {
|
|
16920
|
-
magic = this.nextClearCommandBytes();
|
|
16921
|
-
payload = this.startLiveJson(channel, accountId, magic[1]);
|
|
16922
|
-
signCode = 0;
|
|
16923
|
-
frameType = 0;
|
|
16924
16902
|
} else {
|
|
16925
|
-
payload = encryptP2PData(paddingP2PData(
|
|
16903
|
+
payload = encryptP2PData(paddingP2PData(plain), this.level1Key);
|
|
16926
16904
|
signCode = 1;
|
|
16927
16905
|
magic = [1, 0];
|
|
16928
16906
|
frameType = START_LIVE_FRAME_TYPE_L1;
|
|
@@ -16942,21 +16920,6 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
16942
16920
|
this.armLiveStartRetransmit();
|
|
16943
16921
|
this.send(this.connectAddress, RequestMessageType.DATA, data);
|
|
16944
16922
|
}
|
|
16945
|
-
/**
|
|
16946
|
-
* Whether this session's own-session start and stop go in the clear: its `CMD_GATEWAYINFO` reply named
|
|
16947
|
-
* `cipher_id` 0.
|
|
16948
|
-
*/
|
|
16949
|
-
sendsInTheClear() {
|
|
16950
|
-
return this.gatewayCipherId === 0;
|
|
16951
|
-
}
|
|
16952
|
-
/**
|
|
16953
|
-
* Header bytes 10-11 of this connection's next command sent in the clear: `[0x01, n]`, with `n` counting
|
|
16954
|
-
* those commands from 1 and never 0. A retransmit repeats its `n`, and the device's reply echoes it.
|
|
16955
|
-
*/
|
|
16956
|
-
nextClearCommandBytes() {
|
|
16957
|
-
this.clearCommandCount = this.clearCommandCount % 255 + 1;
|
|
16958
|
-
return [1, this.clearCommandCount];
|
|
16959
|
-
}
|
|
16960
16923
|
/**
|
|
16961
16924
|
* Repeat unacknowledged own-session live starts until the device takes one. Runs only while a start is
|
|
16962
16925
|
* outstanding.
|
|
@@ -17119,8 +17082,6 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
17119
17082
|
* `uint32`, the same 4-byte body as the attached talkback frames. The app sends this frame on closing
|
|
17120
17083
|
* an own-session camera's live view; the camera stops streaming on it within a second, and keeps
|
|
17121
17084
|
* streaming through the 1350-wrapped form.
|
|
17122
|
-
* - own-session on a session that {@link sendsInTheClear}: the same 4-byte body unencrypted, signCode 0,
|
|
17123
|
-
* header bytes from {@link nextClearCommandBytes}.
|
|
17124
17085
|
* - without a level-2 key: the bare 1004 command.
|
|
17125
17086
|
*/
|
|
17126
17087
|
stopLiveMedia(channel = STATION_CHANNEL3, accountId = "", homeBaseAttached = false) {
|
|
@@ -17133,19 +17094,12 @@ var P2PSession = class _P2PSession extends EventEmitter2 {
|
|
|
17133
17094
|
clearInterval(this.liveStartRetransmitTimer);
|
|
17134
17095
|
this.liveStartRetransmitTimer = void 0;
|
|
17135
17096
|
}
|
|
17136
|
-
const body = Buffer.allocUnsafe(4);
|
|
17137
|
-
body.writeUInt32LE(channel >>> 0, 0);
|
|
17138
17097
|
if (this.level2Key && !homeBaseAttached) {
|
|
17098
|
+
const body = Buffer.allocUnsafe(4);
|
|
17099
|
+
body.writeUInt32LE(channel >>> 0, 0);
|
|
17139
17100
|
this.sendRawLevel2Bytes(body, channel, CMD_STOP_REALTIME_MEDIA, 8);
|
|
17140
17101
|
} else if (this.level2Key) {
|
|
17141
17102
|
this.sendMediaPayloadLevel2(CMD_STOP_REALTIME_MEDIA, channel, accountId, {});
|
|
17142
|
-
} else if (!homeBaseAttached && this.sendsInTheClear() && this.connectAddress) {
|
|
17143
|
-
const data = Buffer.concat([
|
|
17144
|
-
buildCommandHeader(this.seqNumber, CMD_STOP_REALTIME_MEDIA),
|
|
17145
|
-
buildRawCommandPayload(body, channel, 0, this.nextClearCommandBytes(), 0)
|
|
17146
|
-
]);
|
|
17147
|
-
this.seqNumber = this.seqNumber + 1 & 65535;
|
|
17148
|
-
this.send(this.connectAddress, RequestMessageType.DATA, data);
|
|
17149
17103
|
} else {
|
|
17150
17104
|
this.sendCommand(CMD_STOP_REALTIME_MEDIA, channel);
|
|
17151
17105
|
}
|