Skip to content

Commit

Permalink
Handle some alarm push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Jun 22, 2024
1 parent 6bb8df2 commit 3be1452
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
15 changes: 12 additions & 3 deletions packages/ring-client-api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ProfileResponse,
PushNotification,
PushNotificationAction,
PushNotificationDingV2,
RingDeviceType,
ThirdPartyGarageDoorOpener,
UnknownDevice,
Expand Down Expand Up @@ -244,7 +245,7 @@ export class RingApi extends Subscribed {
debug: false,
}),
devicesById: { [id: number]: RingCamera | RingIntercom | undefined } = {},
sendToDevice = (id: number, notification: PushNotification) => {
sendToDevice = (id: number, notification: PushNotificationDingV2) => {
devicesById[id]?.processPushNotification(notification)
},
onPushNotificationToken = new Subject<string>()
Expand Down Expand Up @@ -324,8 +325,16 @@ export class RingApi extends Subscribed {
}
}

const notification = messageData as PushNotification,
deviceId = notification.data?.device?.id
const notification = messageData as PushNotification

if (!('android_config' in notification)) {
// This is not a v2 ding style notification, so we can't process it
logInfo('Received push notification in unknown format')
logInfo(JSON.stringify(message))
return
}

const deviceId = notification.data?.device?.id

if (deviceId) {
sendToDevice(deviceId, notification)
Expand Down
3 changes: 1 addition & 2 deletions packages/ring-client-api/ring-camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
SocketTicketResponse,
PeriodicFootageResponse,
PushNotificationAction,
PushNotification,
PushNotificationDingV2,
RingCameraModel,
VideoSearchResponse,
Expand Down Expand Up @@ -419,7 +418,7 @@ export class RingCamera extends Subscribed {
this.onActiveNotifications.next(otherDings)
}

processPushNotification(notification: PushNotification) {
processPushNotification(notification: PushNotificationDingV2) {
if (!('ding' in notification.data?.event)) {
// only process ding/motion notifications
return
Expand Down
4 changes: 2 additions & 2 deletions packages/ring-client-api/ring-intercom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
IntercomHandsetAudioData,
PushNotification,
PushNotificationAction,
PushNotificationDingV2,
} from './ring-types'
import { clientApi, commandsApi, RingRestClient } from './rest-client'
import { BehaviorSubject, Subject } from 'rxjs'
Expand Down Expand Up @@ -103,7 +103,7 @@ export class RingIntercom {
})
}

processPushNotification(notification: PushNotification) {
processPushNotification(notification: PushNotificationDingV2) {
if (notification.android_config.category === PushNotificationAction.Ding) {
this.onDing.next()
} else if (
Expand Down
12 changes: 11 additions & 1 deletion packages/ring-client-api/ring-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,10 @@ export enum PushNotificationAction {
Ding = 'com.ring.pn.live-event.ding',
Motion = 'com.ring.pn.live-event.motion',
IntercomUnlock = 'com.ring.pn.intercom.virtual.unlock',
AlarmModeNone = 'com.ring.push.HANDLE_NEW_SECURITY_PANEL_MODE_NONE_NOTICE',
AlarmModeSome = 'com.ring.push.HANDLE_NEW_SECURITY_PANEL_MODE_SOME_NOTICE',
AlarmSoundSiren = 'com.ring.push.HANDLE_NEW_USER_SOUND_SIREN',
AlarmSilenceSiren = 'com.ring.push.HANDLE_NEW_NON_ALARM_SIREN_SILENCED',
}

export interface PushNotificationDingV2 {
Expand Down Expand Up @@ -1074,7 +1078,13 @@ export interface PushNotificationAlarm {
}
}

export type PushNotification = PushNotificationDingV2
export interface PushNotificationAlarmV2 {
data: {
gcmData: PushNotificationAlarm
}
}

export type PushNotification = PushNotificationDingV2 | PushNotificationAlarmV2

export interface SocketTicketResponse {
ticket: string
Expand Down

0 comments on commit 3be1452

Please sign in to comment.