@basmilius/apple-companion-link 0.0.86 → 0.0.88
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 +19 -14
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -410,21 +410,26 @@ class CompanionLinkSocket extends EncryptionAwareConnection {
|
|
|
410
410
|
async onData(buffer) {
|
|
411
411
|
reporter2.raw("Received data frame", buffer.toString("hex"));
|
|
412
412
|
this.#buffer = Buffer.concat([this.#buffer, buffer]);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
413
|
+
try {
|
|
414
|
+
while (this.#buffer.byteLength >= HEADER_BYTES) {
|
|
415
|
+
const header = this.#buffer.subarray(0, HEADER_BYTES);
|
|
416
|
+
const payloadLength = header.readUintBE(1, 3);
|
|
417
|
+
const totalLength = HEADER_BYTES + payloadLength;
|
|
418
|
+
if (this.#buffer.byteLength < totalLength) {
|
|
419
|
+
reporter2.warn(`Not enough data yet, waiting on the next frame.. needed=${totalLength} available=${this.#buffer.byteLength} receivedLength=${buffer.byteLength}`);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
reporter2.raw(`Frame found length=${totalLength} availableLength=${this.#buffer.byteLength} receivedLength=${buffer.byteLength}`);
|
|
423
|
+
const frame = Buffer.from(this.#buffer.subarray(0, totalLength));
|
|
424
|
+
this.#buffer = this.#buffer.subarray(totalLength);
|
|
425
|
+
reporter2.raw(`Handle frame, ${this.#buffer.byteLength} bytes left...`);
|
|
426
|
+
const data = await this.#decrypt(frame);
|
|
427
|
+
let payload = data.subarray(4, totalLength);
|
|
428
|
+
await this.#handle(header, payload);
|
|
420
429
|
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
this
|
|
424
|
-
reporter2.raw(`Handle frame, ${this.#buffer.byteLength} bytes left...`);
|
|
425
|
-
const data = await this.#decrypt(frame);
|
|
426
|
-
let payload = data.subarray(4, totalLength);
|
|
427
|
-
await this.#handle(header, payload);
|
|
430
|
+
} catch (err) {
|
|
431
|
+
reporter2.error("Error in Companion Link onData handler", err);
|
|
432
|
+
this.emit("error", err);
|
|
428
433
|
}
|
|
429
434
|
}
|
|
430
435
|
async#decrypt(data) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@basmilius/apple-companion-link",
|
|
3
3
|
"description": "Implementation of Apple's Companion Link in Node.js.",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.88",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"author": {
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@basmilius/apple-common": "0.0.
|
|
44
|
-
"@basmilius/apple-encoding": "0.0.
|
|
43
|
+
"@basmilius/apple-common": "0.0.88",
|
|
44
|
+
"@basmilius/apple-encoding": "0.0.88"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@basmilius/tools": "^2.23.0",
|