unifi-protect 3.0.3 → 4.0.0

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/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  Internet Systems Consortium license
2
2
  ===================================
3
3
 
4
- Copyright (c) `2017-2022`, `HJD https://github.com/hjdhjd`
4
+ Copyright (c) `2017-2023`, `HJD https://github.com/hjdhjd`
5
5
 
6
6
  Permission to use, copy, modify, and/or distribute this software for any purpose
7
7
  with or without fee is hereby granted, provided that the above copyright notice
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- export * from "./protect-api";
2
- export * from "./protect-api-livestream";
3
- export * from "./protect-api-updates";
4
- export * from "./protect-logging";
5
- export * from "./protect-types";
6
- export { FetchError } from "node-fetch-cjs";
1
+ export * from "./protect-api.js";
2
+ export type { ProtectLivestream } from "./protect-api-livestream.js";
3
+ export { ProtectApiEvents, ProtectEventPacket } from "./protect-api-updates.js";
4
+ export * from "./protect-logging.js";
5
+ export * from "./protect-types.js";
6
+ export { FetchError } from "node-fetch";
package/dist/index.js CHANGED
@@ -1,25 +1,10 @@
1
- "use strict";
2
- /* Copyright(C) 2019-2022, HJD (https://github.com/hjdhjd). All rights reserved.
1
+ /* Copyright(C) 2019-2023, HJD (https://github.com/hjdhjd). All rights reserved.
3
2
  *
4
3
  * index.ts: UniFi Protect API registration.
5
4
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.FetchError = void 0;
18
- __exportStar(require("./protect-api"), exports);
19
- __exportStar(require("./protect-api-livestream"), exports);
20
- __exportStar(require("./protect-api-updates"), exports);
21
- __exportStar(require("./protect-logging"), exports);
22
- __exportStar(require("./protect-types"), exports);
23
- var node_fetch_cjs_1 = require("node-fetch-cjs");
24
- Object.defineProperty(exports, "FetchError", { enumerable: true, get: function () { return node_fetch_cjs_1.FetchError; } });
5
+ export * from "./protect-api.js";
6
+ export { ProtectApiEvents } from "./protect-api-updates.js";
7
+ export * from "./protect-logging.js";
8
+ export * from "./protect-types.js";
9
+ export { FetchError } from "node-fetch";
25
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;AAEH,gDAA8B;AAC9B,2DAAyC;AACzC,wDAAsC;AACtC,oDAAkC;AAClC,kDAAgC;AAChC,iDAA4C;AAAnC,4GAAA,UAAU,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,kBAAkB,CAAC;AAEjC,OAAO,EAAE,gBAAgB,EAAsB,MAAM,0BAA0B,CAAC;AAChF,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC"}
@@ -1,13 +1,13 @@
1
1
  /// <reference types="node" />
2
- import { EventEmitter } from "events";
3
- import { ProtectApi } from "./protect-api";
4
- import { ProtectLogging } from "./protect-logging";
2
+ /// <reference types="node" />
3
+ import { EventEmitter } from "node:events";
4
+ import { ProtectApi } from "./protect-api.js";
5
+ import { ProtectLogging } from "./protect-logging.js";
5
6
  export declare class ProtectLivestream extends EventEmitter {
6
7
  private _initSegment;
7
8
  private api;
8
9
  private errorHandler;
9
10
  private log;
10
- private name;
11
11
  private segmentHandler;
12
12
  private ws;
13
13
  constructor(api: ProtectApi, log?: ProtectLogging);
@@ -1,15 +1,9 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ProtectLivestream = void 0;
7
- /* Copyright(C) 2022, HJD (https://github.com/hjdhjd). All rights reserved.
1
+ /* Copyright(C) 2022-2023, HJD (https://github.com/hjdhjd). All rights reserved.
8
2
  *
9
3
  * protect-api-livestream.ts: Our UniFi Protect livestream API implementation.
10
4
  */
11
- const events_1 = require("events");
12
- const ws_1 = __importDefault(require("ws"));
5
+ import events, { EventEmitter } from "node:events";
6
+ import WebSocket from "ws";
13
7
  /*
14
8
  * The UniFi Protect livestream API is largely undocumented and has been reverse engineered mostly through
15
9
  * trial and error, as well as observing the Protect controller in action. It builds on the works of others in the
@@ -58,7 +52,7 @@ var ProtectLiveFrame;
58
52
  ProtectLiveFrame[ProtectLiveFrame["ENDSEGMENT"] = 255] = "ENDSEGMENT";
59
53
  })(ProtectLiveFrame || (ProtectLiveFrame = {}));
60
54
  // UniFi Protect livestream API implementation.
61
- class ProtectLivestream extends events_1.EventEmitter {
55
+ export class ProtectLivestream extends EventEmitter {
62
56
  // Create a new instance.
63
57
  constructor(api, log = api.log) {
64
58
  // Initialize the event emitter.
@@ -67,7 +61,6 @@ class ProtectLivestream extends events_1.EventEmitter {
67
61
  this.api = api;
68
62
  this.errorHandler = null;
69
63
  this.log = log;
70
- this.name = api.getNvrName.bind(api);
71
64
  this.segmentHandler = null;
72
65
  this.ws = null;
73
66
  }
@@ -82,18 +75,17 @@ class ProtectLivestream extends events_1.EventEmitter {
82
75
  }
83
76
  // Stop the UniFi Protect livestream.
84
77
  stop() {
85
- var _a, _b, _c, _d, _e;
86
78
  // Close the websocket.
87
- if ((((_a = this.ws) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING) || (((_b = this.ws) === null || _b === void 0 ? void 0 : _b.readyState) === ws_1.default.OPEN)) {
88
- (_c = this.ws) === null || _c === void 0 ? void 0 : _c.terminate();
79
+ if ((this.ws?.readyState === WebSocket.CLOSING) || (this.ws?.readyState === WebSocket.OPEN)) {
80
+ this.ws?.terminate();
89
81
  }
90
82
  // Clean up our segment processing handler.
91
83
  if (this.errorHandler) {
92
- (_d = this.ws) === null || _d === void 0 ? void 0 : _d.removeListener("error", this.errorHandler);
84
+ this.ws?.removeListener("error", this.errorHandler);
93
85
  this.errorHandler = null;
94
86
  }
95
87
  if (this.segmentHandler) {
96
- (_e = this.ws) === null || _e === void 0 ? void 0 : _e.removeListener("message", this.segmentHandler);
88
+ this.ws?.removeListener("message", this.segmentHandler);
97
89
  this.segmentHandler = null;
98
90
  }
99
91
  // Flag that we are no longer running.
@@ -101,7 +93,6 @@ class ProtectLivestream extends events_1.EventEmitter {
101
93
  }
102
94
  // Configure the websocket to populate the prebuffer.
103
95
  async launchLivestream(cameraId, channel, segmentLength, requestId) {
104
- var _a, _b;
105
96
  // To ensure there are minimal performance implications to the Protect NVR, enforce a 100ms floor for
106
97
  // segment length. Protect happens to default to a 100ms segment length as well, so we do too.
107
98
  if (segmentLength < 100) {
@@ -116,7 +107,7 @@ class ProtectLivestream extends events_1.EventEmitter {
116
107
  // extendedVideoMetadata: Provide extended metadata in the MOOV box when possible.
117
108
  // fragmentDurationMillis: Length of each fMP4 segment or fragment, in milliseconds.
118
109
  // progressive: Enable progressive livestreaming.
119
- // rebaseTimestampsToZero: Rebase the timestamps of each segment to zero. Otherwise, timestamps will reflect the controller's default.
110
+ // rebaseTimestampsToZero: Rebase the timestamps of each livestream session to zero. Otherwise, timestamps will reflect the controller's default.
120
111
  // requestId: Name for this particular request. It's optional in practice, and can be any string.
121
112
  // type: Container format type. The valid values are fmp4 and UBV (UniFi Video proprietary format).
122
113
  const params = new URLSearchParams({
@@ -130,33 +121,30 @@ class ProtectLivestream extends events_1.EventEmitter {
130
121
  requestId: requestId,
131
122
  type: "fmp4"
132
123
  });
133
- // Generate our websocket endpoint URL.
134
- const url = this.api.wsUrl() + "/livestream?" + params.toString();
135
- this.log.debug("%s: Opening livestream websocket URL: %s", this.name(), url);
136
- // Get the websocket.
137
- const wsUrl = await this.api.getWsEndpoint(url);
124
+ // Get the websocket endpoint URL from Protect.
125
+ const wsUrl = await this.api.getWsEndpoint("livestream", params);
138
126
  // We ran into a problem getting the websocket URL. We're done.
139
127
  if (!wsUrl) {
140
- this.log.error("%s: Unable to retrieve the livestream websocket API endpoint from the UniFi Protect controller.", this.name());
128
+ this.log.error("Unable to retrieve the livestream websocket API endpoint from the UniFi Protect controller.");
141
129
  return false;
142
130
  }
143
131
  try {
144
132
  // Open the livestream websocket.
145
- this.ws = new ws_1.default(wsUrl, { rejectUnauthorized: false });
133
+ this.ws = new WebSocket(wsUrl, { rejectUnauthorized: false });
146
134
  if (!this.ws) {
147
135
  this.ws = null;
148
- this.log.error("%s: Unable to connect to the livestream websocket API endpoint.", this.name());
136
+ this.log.error("Unable to connect to the livestream websocket API endpoint.");
149
137
  return false;
150
138
  }
151
139
  // Catch any errors and inform the user, if needed.
152
- (_a = this.ws) === null || _a === void 0 ? void 0 : _a.once("error", this.errorHandler = (error) => {
140
+ this.ws?.once("error", this.errorHandler = (error) => {
153
141
  // Ignore timeout errors, but notify the user about anything else.
154
142
  if (error.code !== "ETIMEDOUT") {
155
- this.log.error("%s: Error while communicating with the livestream websocket API: %s", this.name(), error);
143
+ this.log.error("Error while communicating with the livestream websocket API: %s", error);
156
144
  }
157
145
  this.stop();
158
146
  });
159
- (_b = this.ws) === null || _b === void 0 ? void 0 : _b.once("close", (code) => {
147
+ this.ws?.once("close", (code) => {
160
148
  switch (code) {
161
149
  // Websocket has been closed normally. We fire off a close event to inform our listeners and we're done.
162
150
  case 1005:
@@ -167,14 +155,14 @@ class ProtectLivestream extends events_1.EventEmitter {
167
155
  case 1006:
168
156
  break;
169
157
  default:
170
- this.log.error("%s: Unknown livestream API websocket error with camera %s. Error code: %s.", this.name(), cameraId, code);
158
+ this.log.error("Unknown livestream API websocket error with camera %s. Error code: %s.", cameraId, code);
171
159
  }
172
160
  });
173
161
  // Process packets coming to our websocket.
174
162
  this.processLivestream();
175
163
  }
176
164
  catch (error) {
177
- this.log.error("%s: Error while connecting to the livestream websocket API: %s", this.name(), error);
165
+ this.log.error("Error while connecting to the livestream websocket API: %s", error);
178
166
  this.stop();
179
167
  }
180
168
  return true;
@@ -214,7 +202,7 @@ class ProtectLivestream extends events_1.EventEmitter {
214
202
  const header = packet.slice(offset, offsetWithHeader);
215
203
  // Ensure we have a valid header before we do anything.
216
204
  if (!Object.values(ProtectLiveFrame).includes(header[0])) {
217
- this.log.error("%s: Invalid header found while decoding the livestream: %s", this.name(), header[0]);
205
+ this.log.error("Invalid header found while decoding the livestream: %s", header[0]);
218
206
  break;
219
207
  }
220
208
  // Get the length of the actual fMP4 segment we are decoding. Since all this is done over a websocket,
@@ -290,20 +278,17 @@ class ProtectLivestream extends events_1.EventEmitter {
290
278
  }
291
279
  // Asynchronously wait for the initialization segment.
292
280
  async getInitSegment() {
293
- for (;;) {
294
- // Return our segment once we've seen it.
295
- if (this.initSegment) {
296
- return this.initSegment;
297
- }
298
- // Sleep for a short period of time and try again.
299
- // eslint-disable-next-line no-await-in-loop
300
- await new Promise(resolve => setTimeout(resolve, 50));
281
+ // Return our segment once we've seen it.
282
+ if (this.initSegment) {
283
+ return this.initSegment;
301
284
  }
285
+ // Wait until the initialization segment is seen and then try again.
286
+ await events.once(this, "initsegment");
287
+ return this.getInitSegment();
302
288
  }
303
289
  // Retrieve the initialization segment, if we've seen it.
304
290
  get initSegment() {
305
291
  return this._initSegment;
306
292
  }
307
293
  }
308
- exports.ProtectLivestream = ProtectLivestream;
309
294
  //# sourceMappingURL=protect-api-livestream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protect-api-livestream.js","sourceRoot":"","sources":["../src/protect-api-livestream.ts"],"names":[],"mappings":";;;;;;AAAA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E,CAAC,CAAC;wBACrE,MAAM;oBAER,oEAAoE;oBACpE;wBAEE,MAAM;iBACT;gBAED,uCAAuC;gBACvC,MAAM,GAAG,gBAAgB,GAAG,aAAa,CAAC;aAC3C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sDAAsD;IAC/C,KAAK,CAAC,cAAc;QAEzB,SAAQ;YAEN,yCAAyC;YACzC,IAAG,IAAI,CAAC,WAAW,EAAE;gBAEnB,OAAO,IAAI,CAAC,WAAW,CAAC;aACzB;YAED,kDAAkD;YAClD,4CAA4C;YAC5C,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;SACvD;IACH,CAAC;IAED,yDAAyD;IACzD,IAAW,WAAW;QAEpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AA9VD,8CA8VC"}
1
+ {"version":3,"file":"protect-api-livestream.js","sourceRoot":"","sources":["../src/protect-api-livestream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,MAAM,EAAE,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGnD,OAAO,SAAS,MAAM,IAAI,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,4EAA4E;AAC5E,IAAK,gBAWJ;AAXD,WAAK,gBAAgB;IAEnB,iEAAc,CAAA;IACd,iFAAsB,CAAA;IACtB,yEAAkB,CAAA;IAClB,uEAAiB,CAAA;IACjB,yDAAU,CAAA;IACV,2DAAW,CAAA;IACX,2DAAW,CAAA;IACX,yDAAU,CAAA;IACV,qEAAgB,CAAA;AAClB,CAAC,EAXI,gBAAgB,KAAhB,gBAAgB,QAWpB;AAED,+CAA+C;AAC/C,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IASjD,yBAAyB;IACzB,YAAY,GAAe,EAAE,GAAG,GAAG,GAAG,CAAC,GAAG;QAExC,gCAAgC;QACh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AAI,CAAE,CAAC,CAAC;wBACnE,MAAM;oBAER,uDAAuD;oBACvD,KAAK,gBAAgB,CAAC,KAAK;wBAEzB,cAAc,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,CAAE,cAAc,CAAC,KAAK,EAAE,IAAI,CAAE,CAAC,CAAC;wBACrE,MAAM;oBAER,oEAAoE;oBACpE;wBAEE,MAAM;iBACT;gBAED,uCAAuC;gBACvC,MAAM,GAAG,gBAAgB,GAAG,aAAa,CAAC;aAC3C;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,sDAAsD;IAC/C,KAAK,CAAC,cAAc;QAEzB,yCAAyC;QACzC,IAAG,IAAI,CAAC,WAAW,EAAE;YAEnB,OAAO,IAAI,CAAC,WAAW,CAAC;SACzB;QAED,oEAAoE;QACpE,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;QACvC,OAAO,IAAI,CAAC,cAAc,EAAE,CAAC;IAC/B,CAAC;IAED,yDAAyD;IACzD,IAAW,WAAW;QAEpB,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF"}
@@ -1,17 +1,17 @@
1
1
  /// <reference types="node" />
2
- import { ProtectCameraLcdMessagePayload } from "./protect-types";
3
- import { ProtectLogging } from "./protect-logging";
4
- declare type ProtectNvrUpdatePacket = {
5
- action: ProtectNvrUpdateEventAction;
6
- payload: Record<string, unknown> | string | Buffer;
2
+ import { ProtectCameraLcdMessagePayload } from "./protect-types.js";
3
+ import { ProtectLogging } from "./protect-logging.js";
4
+ export type ProtectEventPacket = {
5
+ header: ProtectEventHeader;
6
+ payload: unknown;
7
7
  };
8
- declare type ProtectNvrUpdateEventAction = {
8
+ export type ProtectEventHeader = {
9
9
  action: string;
10
10
  id: string;
11
11
  modelKey: string;
12
12
  newUpdateId: string;
13
13
  };
14
- export declare type ProtectNvrUpdatePayloadEventAdd = {
14
+ export type ProtectNvrUpdatePayloadEventAdd = {
15
15
  camera: string;
16
16
  id: string;
17
17
  modelKey: string;
@@ -22,14 +22,13 @@ export declare type ProtectNvrUpdatePayloadEventAdd = {
22
22
  start: number;
23
23
  type: string;
24
24
  };
25
- export declare type ProtectNvrUpdatePayloadCameraUpdate = {
25
+ export type ProtectNvrUpdatePayloadCameraUpdate = {
26
26
  isMotionDetected: boolean;
27
27
  lastMotion: number;
28
28
  lastRing: number;
29
29
  lcdMessage: ProtectCameraLcdMessagePayload;
30
30
  };
31
- export declare class ProtectApiUpdates {
32
- static decodeUpdatePacket(log: ProtectLogging, packet: Buffer): ProtectNvrUpdatePacket | null;
33
- private static decodeUpdateFrame;
31
+ export declare class ProtectApiEvents {
32
+ static decodePacket(log: ProtectLogging, packet: Buffer): ProtectEventPacket | null;
33
+ private static decodeFrame;
34
34
  }
35
- export {};
@@ -1,10 +1,4 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ProtectApiUpdates = void 0;
7
- const zlib_1 = __importDefault(require("zlib"));
1
+ import zlib from "node:zlib";
8
2
  /*
9
3
  * The UniFi Protect realtime updates API is largely undocumented and has been reverse engineered mostly through
10
4
  * trial and error, as well as observing the Protect controller in action.
@@ -69,49 +63,49 @@ const zlib_1 = __importDefault(require("zlib"));
69
63
  * - With the exception of update actions with a modelKey of event, JSONs are always a subset of the bootstrap JSON, indexed off
70
64
  * of modelKey. So for a modelKey of camera, the data payload is always a subset of ProtectCameraConfigInterface (see protect-types.ts).
71
65
  */
72
- // Update realtime API packet header size, in bytes.
73
- const UPDATE_PACKET_HEADER_SIZE = 8;
66
+ // UniFi Protect events API packet header size, in bytes.
67
+ const EVENT_PACKET_HEADER_SIZE = 8;
74
68
  // Update realtime API packet types.
75
- var UpdatePacketType;
76
- (function (UpdatePacketType) {
77
- UpdatePacketType[UpdatePacketType["ACTION"] = 1] = "ACTION";
78
- UpdatePacketType[UpdatePacketType["PAYLOAD"] = 2] = "PAYLOAD";
79
- })(UpdatePacketType || (UpdatePacketType = {}));
69
+ var ProtectEventPacketType;
70
+ (function (ProtectEventPacketType) {
71
+ ProtectEventPacketType[ProtectEventPacketType["HEADER"] = 1] = "HEADER";
72
+ ProtectEventPacketType[ProtectEventPacketType["PAYLOAD"] = 2] = "PAYLOAD";
73
+ })(ProtectEventPacketType || (ProtectEventPacketType = {}));
80
74
  // Update realtime API payload types.
81
- var UpdatePayloadType;
82
- (function (UpdatePayloadType) {
83
- UpdatePayloadType[UpdatePayloadType["JSON"] = 1] = "JSON";
84
- UpdatePayloadType[UpdatePayloadType["STRING"] = 2] = "STRING";
85
- UpdatePayloadType[UpdatePayloadType["BUFFER"] = 3] = "BUFFER";
86
- })(UpdatePayloadType || (UpdatePayloadType = {}));
75
+ var EventPayloadType;
76
+ (function (EventPayloadType) {
77
+ EventPayloadType[EventPayloadType["JSON"] = 1] = "JSON";
78
+ EventPayloadType[EventPayloadType["STRING"] = 2] = "STRING";
79
+ EventPayloadType[EventPayloadType["BUFFER"] = 3] = "BUFFER";
80
+ })(EventPayloadType || (EventPayloadType = {}));
87
81
  /* A packet header is composed of 8 bytes in this order:
88
82
  *
89
83
  * Byte Offset Description Bits Values
90
- * 0 Packet Type 8 1 - action frame, 2 - payload frame.
84
+ * 0 Packet Type 8 1 - header frame, 2 - payload frame.
91
85
  * 1 Payload Format 8 1 - JSON object, 2 - UTF8-encoded string, 3 - Node Buffer.
92
86
  * 2 Deflated 8 0 - uncompressed, 1 - compressed / deflated (zlib-based compression).
93
87
  * 3 Unknown 8 Always 0. Possibly reserved for future use by Ubiquiti?
94
88
  * 4-7 Payload Size: 32 Size of payload in network-byte order (big endian).
95
89
  */
96
- var UpdatePacketHeader;
97
- (function (UpdatePacketHeader) {
98
- UpdatePacketHeader[UpdatePacketHeader["TYPE"] = 0] = "TYPE";
99
- UpdatePacketHeader[UpdatePacketHeader["PAYLOAD_FORMAT"] = 1] = "PAYLOAD_FORMAT";
100
- UpdatePacketHeader[UpdatePacketHeader["DEFLATED"] = 2] = "DEFLATED";
101
- UpdatePacketHeader[UpdatePacketHeader["UNKNOWN"] = 3] = "UNKNOWN";
102
- UpdatePacketHeader[UpdatePacketHeader["PAYLOAD_SIZE"] = 4] = "PAYLOAD_SIZE";
103
- })(UpdatePacketHeader || (UpdatePacketHeader = {}));
104
- class ProtectApiUpdates {
90
+ var ProtectEventPacketHeader;
91
+ (function (ProtectEventPacketHeader) {
92
+ ProtectEventPacketHeader[ProtectEventPacketHeader["TYPE"] = 0] = "TYPE";
93
+ ProtectEventPacketHeader[ProtectEventPacketHeader["PAYLOAD_FORMAT"] = 1] = "PAYLOAD_FORMAT";
94
+ ProtectEventPacketHeader[ProtectEventPacketHeader["DEFLATED"] = 2] = "DEFLATED";
95
+ ProtectEventPacketHeader[ProtectEventPacketHeader["UNKNOWN"] = 3] = "UNKNOWN";
96
+ ProtectEventPacketHeader[ProtectEventPacketHeader["PAYLOAD_SIZE"] = 4] = "PAYLOAD_SIZE";
97
+ })(ProtectEventPacketHeader || (ProtectEventPacketHeader = {}));
98
+ export class ProtectApiEvents {
105
99
  // Process an update data packet and return the action and payload.
106
- static decodeUpdatePacket(log, packet) {
100
+ static decodePacket(log, packet) {
107
101
  // What we need to do here is to split this packet into the header and payload, and decode them.
108
102
  let dataOffset;
109
103
  try {
110
104
  // The fourth byte holds our payload size. When you add the payload size to our header frame size, you get the location of the
111
105
  // data header frame.
112
- dataOffset = packet.readUInt32BE(UpdatePacketHeader.PAYLOAD_SIZE) + UPDATE_PACKET_HEADER_SIZE;
106
+ dataOffset = packet.readUInt32BE(ProtectEventPacketHeader.PAYLOAD_SIZE) + EVENT_PACKET_HEADER_SIZE;
113
107
  // Validate our packet size, just in case we have more or less data than we expect. If we do, we're done for now.
114
- if (packet.length !== (dataOffset + UPDATE_PACKET_HEADER_SIZE + packet.readUInt32BE(dataOffset + UpdatePacketHeader.PAYLOAD_SIZE))) {
108
+ if (packet.length !== (dataOffset + EVENT_PACKET_HEADER_SIZE + packet.readUInt32BE(dataOffset + ProtectEventPacketHeader.PAYLOAD_SIZE))) {
115
109
  throw new Error("Packet length doesn't match header information.");
116
110
  }
117
111
  }
@@ -120,39 +114,39 @@ class ProtectApiUpdates {
120
114
  return null;
121
115
  }
122
116
  // Decode the action and payload frames now that we know where everything is.
123
- const actionFrame = this.decodeUpdateFrame(log, packet.slice(0, dataOffset), UpdatePacketType.ACTION);
124
- const payloadFrame = this.decodeUpdateFrame(log, packet.slice(dataOffset), UpdatePacketType.PAYLOAD);
125
- if (!actionFrame || !payloadFrame) {
117
+ const headerFrame = this.decodeFrame(log, packet.slice(0, dataOffset), ProtectEventPacketType.HEADER);
118
+ const payloadFrame = this.decodeFrame(log, packet.slice(dataOffset), ProtectEventPacketType.PAYLOAD);
119
+ if (!headerFrame || !payloadFrame) {
126
120
  return null;
127
121
  }
128
- return ({ action: actionFrame, payload: payloadFrame });
122
+ return ({ header: headerFrame, payload: payloadFrame });
129
123
  }
130
124
  // Decode a frame, composed of a header and payload, received through the update events API.
131
- static decodeUpdateFrame(log, packet, packetType) {
125
+ static decodeFrame(log, packet, packetType) {
132
126
  // Read the packet frame type.
133
- const frameType = packet.readUInt8(UpdatePacketHeader.TYPE);
127
+ const frameType = packet.readUInt8(ProtectEventPacketHeader.TYPE);
134
128
  // This isn't the frame type we were expecting - we're done.
135
129
  if (packetType !== frameType) {
136
130
  return null;
137
131
  }
138
132
  // Read the payload format.
139
- const payloadFormat = packet.readUInt8(UpdatePacketHeader.PAYLOAD_FORMAT);
133
+ const payloadFormat = packet.readUInt8(ProtectEventPacketHeader.PAYLOAD_FORMAT);
140
134
  // Check to see if we're compressed or not, and inflate if needed after skipping past the 8-byte header.
141
- const payload = packet.readUInt8(UpdatePacketHeader.DEFLATED) ? zlib_1.default.inflateSync(packet.slice(UPDATE_PACKET_HEADER_SIZE)) : packet.slice(UPDATE_PACKET_HEADER_SIZE);
142
- // If it's an action, it can only have one format.
143
- if (frameType === UpdatePacketType.ACTION) {
144
- return (payloadFormat === UpdatePayloadType.JSON) ? JSON.parse(payload.toString()) : null;
135
+ const payload = packet.readUInt8(ProtectEventPacketHeader.DEFLATED) ? zlib.inflateSync(packet.slice(EVENT_PACKET_HEADER_SIZE)) : packet.slice(EVENT_PACKET_HEADER_SIZE);
136
+ // If it's a header, it can only have one format.
137
+ if (frameType === ProtectEventPacketType.HEADER) {
138
+ return (payloadFormat === EventPayloadType.JSON) ? JSON.parse(payload.toString()) : null;
145
139
  }
146
140
  // Process the payload format accordingly.
147
141
  switch (payloadFormat) {
148
- case UpdatePayloadType.JSON:
142
+ case EventPayloadType.JSON:
149
143
  // If it's data payload, it can be anything.
150
144
  return JSON.parse(payload.toString());
151
145
  break;
152
- case UpdatePayloadType.STRING:
146
+ case EventPayloadType.STRING:
153
147
  return payload.toString("utf8");
154
148
  break;
155
- case UpdatePayloadType.BUFFER:
149
+ case EventPayloadType.BUFFER:
156
150
  return payload;
157
151
  break;
158
152
  default:
@@ -162,5 +156,4 @@ class ProtectApiUpdates {
162
156
  }
163
157
  }
164
158
  }
165
- exports.ProtectApiUpdates = ProtectApiUpdates;
166
159
  //# sourceMappingURL=protect-api-updates.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"protect-api-updates.js","sourceRoot":"","sources":["../src/protect-api-updates.ts"],"names":[],"mappings":";;;;;;AAMA,gDAAwB;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AAEH,oDAAoD;AACpD,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAEpC,oCAAoC;AACpC,IAAK,gBAGJ;AAHD,WAAK,gBAAgB;IACnB,2DAAU,CAAA;IACV,6DAAW,CAAA;AACb,CAAC,EAHI,gBAAgB,KAAhB,gBAAgB,QAGpB;AAED,qCAAqC;AACrC,IAAK,iBAIJ;AAJD,WAAK,iBAAiB;IACpB,yDAAQ,CAAA;IACR,6D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,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;QAExK,iDAAiD;QACjD,IAAG,SAAS,KAAK,sBAAsB,CAAC,MAAM,EAAE;YAE9C,OAAO,CAAC,aAAa,KAAK,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAuB,CAAC,CAAC,CAAC,IAAI,CAAC;SAChH;QAED,0CAA0C;QAC1C,QAAO,aAAa,EAAE;YAEpB,KAAK,gBAAgB,CAAC,IAAI;gBAExB,4CAA4C;gBAC5C,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAS,CAAC;gBAC9C,MAAM;YAER,KAAK,gBAAgB,CAAC,MAAM;gBAE1B,OAAO,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;gBAChC,MAAM;YAER,KAAK,gBAAgB,CAAC,MAAM;gBAE1B,OAAO,OAAO,CAAC;gBACf,MAAM;YAER;gBAEE,GAAG,CAAC,KAAK,CAAC,6EAA6E,EAAE,aAAa,CAAC,CAAC;gBACxG,OAAO,IAAI,CAAC;gBACZ,MAAM;SACT;IACH,CAAC;CACF"}
@@ -1,64 +1,49 @@
1
- import { ProtectCameraConfig, ProtectCameraConfigInterface, ProtectCameraConfigPayload, ProtectLightConfig, ProtectLightConfigPayload, ProtectNvrBootstrap, ProtectSensorConfig, ProtectViewerConfig, ProtectViewerConfigPayload } from "./protect-types";
2
- import { RequestInfo, RequestInit, Response } from "node-fetch-cjs";
3
- import { ProtectLogging } from "./protect-logging";
4
- import WebSocket from "ws";
5
- declare type ProtectKnownDeviceTypes = ProtectCameraConfig | ProtectLightConfig | ProtectSensorConfig | ProtectViewerConfig;
6
- export declare class ProtectApi {
1
+ /// <reference types="node" />
2
+ import { ProtectCameraConfig, ProtectCameraConfigInterface, ProtectCameraConfigPayload, ProtectLightConfig, ProtectLightConfigPayload, ProtectNvrBootstrap, ProtectNvrConfig, ProtectNvrConfigPayload, ProtectSensorConfig, ProtectSensorConfigPayload, ProtectViewerConfig, ProtectViewerConfigPayload } from "./protect-types.js";
3
+ import { RequestInfo, RequestInit, Response } from "node-fetch";
4
+ import { EventEmitter } from "node:events";
5
+ import { ProtectLivestream } from "./protect-api-livestream.js";
6
+ import { ProtectLogging } from "./protect-logging.js";
7
+ type ProtectKnownDeviceTypes = ProtectCameraConfig | ProtectLightConfig | ProtectNvrConfig | ProtectSensorConfig | ProtectViewerConfig;
8
+ type ProtectKnownDevicePayloads = ProtectCameraConfigPayload | ProtectLightConfigPayload | ProtectNvrConfigPayload | ProtectSensorConfigPayload | ProtectViewerConfigPayload;
9
+ export declare class ProtectApi extends EventEmitter {
7
10
  private _bootstrap;
8
- private _cameras;
9
11
  private _eventsWs;
10
- private _lights;
11
12
  private _log;
12
- private _sensors;
13
- private _viewers;
14
13
  private apiErrorCount;
15
14
  private apiLastSuccess;
16
15
  private headers;
17
16
  private httpsAgent;
18
17
  private isAdminUser;
19
- private isLoggedIn;
20
- private isLoginRefresh;
21
18
  private loginAge;
22
19
  private loginAttempt;
20
+ private loginRefreshTimer;
23
21
  private nvrAddress;
24
22
  private password;
25
23
  private username;
26
- constructor(nvrAddress: string, username: string, password: string, log?: ProtectLogging);
27
- private acquireToken;
28
- private loginNvr;
29
- private login;
30
- private bootstrapProtect;
31
- private launchUpdatesListener;
32
- private refreshDeviceClass;
33
- refreshDevices(): Promise<boolean>;
24
+ constructor(log?: ProtectLogging);
25
+ login(nvrAddress: string, username: string, password: string): Promise<boolean>;
26
+ private acquireCsrfToken;
27
+ private loginController;
28
+ private bootstrapController;
29
+ private launchEventsWs;
30
+ getBootstrap(): Promise<boolean>;
34
31
  isAllRtspConfigured(): boolean;
35
32
  private checkAdminUserStatus;
36
- updateCamera(device: ProtectCameraConfig, payload: ProtectCameraConfigPayload): Promise<ProtectCameraConfig | null>;
33
+ updateDevice<DeviceType extends ProtectKnownDeviceTypes>(device: DeviceType, payload: ProtectKnownDevicePayloads): Promise<DeviceType | null>;
37
34
  updateCameraChannels(device: ProtectCameraConfigInterface): Promise<ProtectCameraConfig | null>;
38
- updateLight(device: ProtectLightConfig, payload: ProtectLightConfigPayload): Promise<ProtectLightConfig | null>;
39
- updateViewer(device: ProtectViewerConfig, payload: ProtectViewerConfigPayload): Promise<ProtectViewerConfig | null>;
40
35
  enableRtsp(device: ProtectCameraConfigInterface): Promise<ProtectCameraConfig | null>;
41
- get bootstrap(): ProtectNvrBootstrap | null;
42
- get cameras(): ProtectCameraConfig[] | null;
43
- get eventsWs(): WebSocket | null;
44
- get lights(): ProtectLightConfig[] | null;
45
- get log(): ProtectLogging;
46
- get sensors(): ProtectSensorConfig[] | null;
47
- get viewers(): ProtectViewerConfig[] | null;
48
- getNvrName(): string;
49
36
  getDeviceName(device: ProtectKnownDeviceTypes, name?: string, deviceInfo?: boolean): string;
50
37
  getFullName(device: ProtectKnownDeviceTypes): string;
51
- camerasUrl(): string;
52
- lightsUrl(): string;
53
- viewersUrl(): string;
54
- wsUrl(): string;
55
- private authUrl;
56
- private bootstrapUrl;
57
- private systemUrl;
58
- private updatesUrl;
59
38
  clearLoginCredentials(): void;
60
39
  private canModifyCamera;
61
- getWsEndpoint(url: string): Promise<string | null>;
40
+ getWsEndpoint(endpoint: "livestream" | "talkback", params?: URLSearchParams): Promise<string | null>;
41
+ private _getWsEndpoint;
62
42
  fetch(url: RequestInfo, options?: RequestInit, logErrors?: boolean, decodeResponse?: boolean, isRetry?: boolean): Promise<Response | null>;
43
+ createLivestream(): ProtectLivestream;
44
+ getApiEndpoint(deviceType: string): string;
45
+ get bootstrap(): ProtectNvrBootstrap | null;
46
+ get log(): ProtectLogging;
47
+ get name(): string;
63
48
  }
64
49
  export {};