Skip to content

Commit

Permalink
Support complete dingId (dgreif#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
djm181 authored May 23, 2023
1 parent 96a073b commit af7f44e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/real-onions-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ring-client-api': patch
---

Update push notifications to include a full and accurate ding `id`. Note, this is technically a breaking change because the `id` was previously a `number` instead of a `string`, but the last few digits were truncated due to number rounding. We are releasing this as a patch because the `number` version was unusable for fetching additional information about the ding.
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion packages/ring-client-api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { setFfmpegPath } from './ffmpeg'
import { Subscribed } from './subscribed'
import PushReceiver from '@eneris/push-receiver'
import { RingIntercom } from './ring-intercom'
import JSONbig from 'json-bigint'

export interface RingApiOptions extends SessionOptions {
locationIds?: string[]
Expand Down Expand Up @@ -270,7 +271,9 @@ export class RingApi extends Subscribed {
const dataJson = message.data?.gcmData as string

try {
const notification = JSON.parse(dataJson) as PushNotification
const notification = JSONbig({ storeAsString: true }).parse(
dataJson
) as PushNotification

if ('ding' in notification) {
sendToDevice(notification.ding.doorbot_id, notification)
Expand Down
2 changes: 2 additions & 0 deletions packages/ring-client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"colors": "1.4.0",
"debug": "^4.3.4",
"got": "^11.8.5",
"json-bigint": "^1.0.0",
"msw": "^1.2.1",
"rxjs": "^7.8.0",
"socket.io-client": "^2.5.0",
Expand All @@ -37,6 +38,7 @@
"devDependencies": {
"@types/debug": "4.1.7",
"@types/jest": "29.5.0",
"@types/json-bigint": "^1.0.1",
"@types/node": "18.15.9",
"@types/uuid": "9.0.1",
"@types/ws": "^8.5.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/ring-client-api/ring-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class RingCamera extends Subscribed {
return new StreamingSession(this, connection)
}

private removeDingById(idToRemove: number) {
private removeDingById(idToRemove: string) {
const allActiveDings = this.activeNotifications,
otherDings = allActiveDings.filter(({ ding }) => ding.id !== idToRemove)

Expand Down
2 changes: 1 addition & 1 deletion packages/ring-client-api/ring-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ export interface PushNotificationDing {
device_kind: RingCameraKind
detection_type: NotificationDetectionType
human_detected?: boolean
id: number
id: string
pod_id: number
request_id: string
image_uuid: string
Expand Down

0 comments on commit af7f44e

Please sign in to comment.