@basmilius/apple-airplay 0.0.90 → 0.0.91

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.
Files changed (2) hide show
  1. package/dist/index.js +10 -11
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -2228,6 +2228,7 @@ class AirPlayRTSP extends AirPlayStream {
2228
2228
  #buffer = Buffer.alloc(0);
2229
2229
  #cseq = 0;
2230
2230
  #requesting = false;
2231
+ #requestTimer;
2231
2232
  #reject;
2232
2233
  #resolve;
2233
2234
  constructor(address, port) {
@@ -2259,6 +2260,10 @@ class AirPlayRTSP extends AirPlayStream {
2259
2260
  return await this.#request("SETUP", path, body, headers, timeout);
2260
2261
  }
2261
2262
  async#handle(data, err) {
2263
+ if (this.#requestTimer) {
2264
+ clearTimeout(this.#requestTimer);
2265
+ this.#requestTimer = undefined;
2266
+ }
2262
2267
  if (err) {
2263
2268
  this.#reject?.(err);
2264
2269
  } else {
@@ -2296,20 +2301,14 @@ class AirPlayRTSP extends AirPlayStream {
2296
2301
  data = await this.encrypt(data);
2297
2302
  }
2298
2303
  return new Promise(async (resolve, reject) => {
2299
- let timer;
2300
- this.#reject = (reason) => {
2301
- reject(reason);
2302
- clearTimeout(timer);
2303
- };
2304
- this.#resolve = (response) => {
2305
- resolve(response);
2306
- clearTimeout(timer);
2307
- };
2308
- timer = setTimeout(() => reject(new Error("Request timed out")), timeout);
2309
- await this.write(data);
2304
+ this.#reject = reject;
2305
+ this.#resolve = resolve;
2306
+ this.#requestTimer = setTimeout(() => this.#handle(undefined, new Error("Request timed out")), timeout);
2307
+ await this.write(data).catch((err) => this.#handle(undefined, err));
2310
2308
  });
2311
2309
  }
2312
2310
  async#onClose() {
2311
+ this.#buffer = Buffer.alloc(0);
2313
2312
  await this.#handle(undefined, new Error("Connection closed."));
2314
2313
  }
2315
2314
  async#onData(buffer) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-airplay",
3
3
  "description": "Implementation of Apple's AirPlay2 in Node.js.",
4
- "version": "0.0.90",
4
+ "version": "0.0.91",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -41,8 +41,8 @@
41
41
  }
42
42
  },
43
43
  "dependencies": {
44
- "@basmilius/apple-common": "0.0.90",
45
- "@basmilius/apple-encoding": "0.0.90",
44
+ "@basmilius/apple-common": "0.0.91",
45
+ "@basmilius/apple-encoding": "0.0.91",
46
46
  "@bufbuild/protobuf": "^2.10.2"
47
47
  },
48
48
  "devDependencies": {