@basmilius/apple-common 0.0.89 → 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 +21 -3
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1022,7 +1022,20 @@ class Connection extends EventEmitter {
1022
1022
  return this.#state === "connected";
1023
1023
  }
1024
1024
  get state() {
1025
- return this.#state;
1025
+ if (this.#state === "closing" || this.#state === "failed") {
1026
+ return this.#state;
1027
+ }
1028
+ if (!this.#socket) {
1029
+ return "disconnected";
1030
+ }
1031
+ switch (this.#socket.readyState) {
1032
+ case "opening":
1033
+ return "connecting";
1034
+ case "open":
1035
+ return "connected";
1036
+ default:
1037
+ return this.#state;
1038
+ }
1026
1039
  }
1027
1040
  #address;
1028
1041
  #port;
@@ -1089,8 +1102,9 @@ class Connection extends EventEmitter {
1089
1102
  return this;
1090
1103
  }
1091
1104
  async write(data) {
1092
- if (!this.#socket || this.#state !== "connected") {
1093
- throw new Error("Cannot write to a disconnected connection.");
1105
+ if (!this.#socket || this.state !== "connected") {
1106
+ this.emit("error", new Error("Cannot write to a disconnected connection."));
1107
+ return;
1094
1108
  }
1095
1109
  return new Promise((resolve, reject) => {
1096
1110
  this.#socket.write(data, (err) => err ? reject(err) : resolve());
@@ -1117,6 +1131,10 @@ class Connection extends EventEmitter {
1117
1131
  });
1118
1132
  }
1119
1133
  #cleanup() {
1134
+ if (this.#retryTimeout) {
1135
+ clearTimeout(this.#retryTimeout);
1136
+ this.#retryTimeout = undefined;
1137
+ }
1120
1138
  if (this.#socket) {
1121
1139
  this.#socket.removeAllListeners();
1122
1140
  this.#socket.destroy();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@basmilius/apple-common",
3
3
  "description": "Common features shared across various apple protocol packages.",
4
- "version": "0.0.89",
4
+ "version": "0.0.91",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -38,7 +38,7 @@
38
38
  }
39
39
  },
40
40
  "dependencies": {
41
- "@basmilius/apple-encoding": "0.0.89",
41
+ "@basmilius/apple-encoding": "0.0.91",
42
42
  "@stablelib/chacha20poly1305": "^2.0.1",
43
43
  "fast-srp-hap": "^2.0.4",
44
44
  "node-dns-sd": "^1.0.1",