ring-client-api 11.7.0-beta.2 → 11.7.0-beta.4

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/lib/api.d.ts CHANGED
@@ -37,7 +37,7 @@ export declare class RingApi extends Subscribed {
37
37
  unknownDevices: UnknownDevice[];
38
38
  }>;
39
39
  private listenForDeviceUpdates;
40
- registerPushReceiver(cameras: RingCamera[]): Promise<void>;
40
+ private registerPushReceiver;
41
41
  fetchRawLocations(): Promise<UserLocation[]>;
42
42
  fetchAmazonKeyLocks(): Promise<any[] & import("./rest-client").ExtendedResponse>;
43
43
  fetchAndBuildLocations(): Promise<Location[]>;
package/lib/api.js CHANGED
@@ -121,14 +121,17 @@ class RingApi extends subscribed_1.Subscribed {
121
121
  onUpdateReceived.next(null); // kick off polling
122
122
  }
123
123
  }
124
- async registerPushReceiver(cameras) {
124
+ async registerPushReceiver(cameras, intercoms) {
125
125
  const pushReceiver = new push_receiver_1.default({
126
126
  logLevel: 'NONE',
127
127
  senderId: '876313859327', // for Ring android app. 703521446232 for ring-site
128
- }), camerasById = cameras.reduce((byId, camera) => {
129
- byId[camera.id] = camera;
130
- return byId;
131
- }, {});
128
+ }), devicesById = {};
129
+ for (const camera of cameras) {
130
+ devicesById[camera.id] = camera;
131
+ }
132
+ for (const intercom of intercoms) {
133
+ devicesById[intercom.id] = intercom;
134
+ }
132
135
  pushReceiver.onCredentialsChanged(async ({ newCredentials: { fcm: { token }, }, }) => {
133
136
  try {
134
137
  await this.restClient.request({
@@ -159,7 +162,7 @@ class RingApi extends subscribed_1.Subscribed {
159
162
  // We may get notification that are not for a ding/motion, which can be ignored
160
163
  return;
161
164
  }
162
- camerasById[notification.ding.doorbot_id]?.processPushNotification(notification);
165
+ devicesById[notification.ding.doorbot_id]?.processPushNotification(notification);
163
166
  }
164
167
  catch (e) {
165
168
  (0, util_1.logError)(e);
@@ -199,7 +202,7 @@ class RingApi extends subscribed_1.Subscribed {
199
202
  locationModePollingSeconds: this.options.locationModePollingSeconds,
200
203
  }, this.restClient));
201
204
  this.listenForDeviceUpdates(cameras, ringChimes, ringIntercoms);
202
- this.registerPushReceiver(cameras).catch((e) => {
205
+ this.registerPushReceiver(cameras, ringIntercoms).catch((e) => {
203
206
  (0, util_1.logError)(e);
204
207
  });
205
208
  return locations;
@@ -84,7 +84,7 @@ class RingCamera extends subscribed_1.Subscribed {
84
84
  this.hasLight = this.initialData.led_status !== undefined;
85
85
  this.hasSiren = this.initialData.siren_status !== undefined;
86
86
  this.onBatteryLevel = this.onData.pipe((0, operators_1.map)((data) => {
87
- if (!('battery_level' in data)) {
87
+ if (!('battery_life' in data)) {
88
88
  return null;
89
89
  }
90
90
  return getBatteryLevel(data);
@@ -125,7 +125,7 @@ class RingCamera extends subscribed_1.Subscribed {
125
125
  return notifications[notifications.length - 1];
126
126
  }
127
127
  get batteryLevel() {
128
- if (!('battery_level' in this.data)) {
128
+ if (!('battery_life' in this.data)) {
129
129
  return null;
130
130
  }
131
131
  return getBatteryLevel(this.data);
@@ -1,4 +1,4 @@
1
- import { IntercomHandsetAudioData } from './ring-types';
1
+ import { IntercomHandsetAudioData, PushNotification } from './ring-types';
2
2
  import { RingRestClient } from './rest-client';
3
3
  import { BehaviorSubject, Subject } from 'rxjs';
4
4
  export declare class RingIntercom {
@@ -9,6 +9,7 @@ export declare class RingIntercom {
9
9
  onData: BehaviorSubject<IntercomHandsetAudioData>;
10
10
  onRequestUpdate: Subject<unknown>;
11
11
  onBatteryLevel: import("rxjs").Observable<number | null>;
12
+ onDing: Subject<void>;
12
13
  constructor(initialData: IntercomHandsetAudioData, restClient: RingRestClient);
13
14
  updateData(update: IntercomHandsetAudioData): void;
14
15
  requestUpdate(): void;
@@ -17,4 +18,8 @@ export declare class RingIntercom {
17
18
  get isOffline(): boolean;
18
19
  get batteryLevel(): number | null;
19
20
  unlock(): Promise<import("./rest-client").ExtendedResponse>;
21
+ private doorbotUrl;
22
+ subscribeToDingEvents(): Promise<void & import("./rest-client").ExtendedResponse>;
23
+ unsubscribeFromDingEvents(): Promise<void & import("./rest-client").ExtendedResponse>;
24
+ processPushNotification(notification: PushNotification): void;
20
25
  }
@@ -1,19 +1,28 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RingIntercom = void 0;
4
+ const ring_types_1 = require("./ring-types");
4
5
  const rest_client_1 = require("./rest-client");
5
6
  const rxjs_1 = require("rxjs");
6
7
  const operators_1 = require("rxjs/operators");
7
8
  const ring_camera_1 = require("./ring-camera");
9
+ const util_1 = require("./util");
8
10
  class RingIntercom {
9
11
  constructor(initialData, restClient) {
10
12
  this.initialData = initialData;
11
13
  this.restClient = restClient;
12
14
  this.onRequestUpdate = new rxjs_1.Subject();
15
+ this.onDing = new rxjs_1.Subject();
13
16
  this.id = this.initialData.id;
14
17
  this.deviceType = this.initialData.kind;
15
18
  this.onData = new rxjs_1.BehaviorSubject(this.initialData);
16
19
  this.onBatteryLevel = this.onData.pipe((0, operators_1.map)((data) => (0, ring_camera_1.getBatteryLevel)(data)), (0, operators_1.distinctUntilChanged)());
20
+ if (!initialData.subscribed) {
21
+ this.subscribeToDingEvents().catch((e) => {
22
+ (0, util_1.logError)('Failed to subscribe ' + initialData.description + ' to ding events');
23
+ (0, util_1.logError)(e);
24
+ });
25
+ }
17
26
  }
18
27
  updateData(update) {
19
28
  this.onData.next(update);
@@ -50,5 +59,25 @@ class RingIntercom {
50
59
  },
51
60
  });
52
61
  }
62
+ doorbotUrl(path = '') {
63
+ return (0, rest_client_1.clientApi)(`doorbots/${this.id}/${path}`);
64
+ }
65
+ subscribeToDingEvents() {
66
+ return this.restClient.request({
67
+ method: 'POST',
68
+ url: this.doorbotUrl('subscribe'),
69
+ });
70
+ }
71
+ unsubscribeFromDingEvents() {
72
+ return this.restClient.request({
73
+ method: 'POST',
74
+ url: this.doorbotUrl('unsubscribe'),
75
+ });
76
+ }
77
+ processPushNotification(notification) {
78
+ if (notification.action === ring_types_1.PushNotificationAction.Ding) {
79
+ this.onDing.next();
80
+ }
81
+ }
53
82
  }
54
83
  exports.RingIntercom = RingIntercom;
@@ -864,7 +864,9 @@ export declare enum NotificationDetectionType {
864
864
  }
865
865
  export declare enum PushNotificationAction {
866
866
  Ding = "com.ring.push.HANDLE_NEW_DING",
867
- Motion = "com.ring.push.HANDLE_NEW_motion"
867
+ Motion = "com.ring.push.HANDLE_NEW_motion",
868
+ LowBattery = "com.ring.push.LOW_BATTERY_ALERT",
869
+ IntercomUnlock = "com.ring.push.INTERCOM_UNLOCK_FROM_APP"
868
870
  }
869
871
  export interface PushNotification {
870
872
  ding: {
package/lib/ring-types.js CHANGED
@@ -179,6 +179,8 @@ var PushNotificationAction;
179
179
  (function (PushNotificationAction) {
180
180
  PushNotificationAction["Ding"] = "com.ring.push.HANDLE_NEW_DING";
181
181
  PushNotificationAction["Motion"] = "com.ring.push.HANDLE_NEW_motion";
182
+ PushNotificationAction["LowBattery"] = "com.ring.push.LOW_BATTERY_ALERT";
183
+ PushNotificationAction["IntercomUnlock"] = "com.ring.push.INTERCOM_UNLOCK_FROM_APP";
182
184
  })(PushNotificationAction = exports.PushNotificationAction || (exports.PushNotificationAction = {}));
183
185
  // eslint-disable-next-line no-shadow
184
186
  var DispatchSignalType;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ring-client-api",
3
- "version": "11.7.0-beta.2",
3
+ "version": "11.7.0-beta.4",
4
4
  "description": "Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting",
5
5
  "main": "lib/index.js",
6
6
  "exports": {