Skip to content

Commit

Permalink
Update build target to ES2022
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Oct 14, 2024
1 parent 306f76d commit abd5e98
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 78 deletions.
6 changes: 6 additions & 0 deletions .changeset/slimy-lizards-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'homebridge-ring': minor
'ring-client-api': minor
---

Updated build target from ES2021 to ES2022. ES2022 is fully supported by Node 18, which is the current minimum supported version.
9 changes: 6 additions & 3 deletions packages/homebridge-ring/beam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import { PlatformAccessory } from 'homebridge'
import { logInfo } from 'ring-client-api/util'

export class Beam extends BaseDeviceAccessory {
isLightGroup =
this.device.data.deviceType === RingDeviceType.BeamsLightGroupSwitch
groupId = this.device.data.groupId
private isLightGroup
private groupId

constructor(
public readonly device: RingDevice,
Expand All @@ -17,6 +16,10 @@ export class Beam extends BaseDeviceAccessory {
) {
super()

this.isLightGroup =
this.device.data.deviceType === RingDeviceType.BeamsLightGroupSwitch
this.groupId = this.device.data.groupId

const { Characteristic, Service } = hap,
{ MotionSensor } = Service,
{
Expand Down
102 changes: 52 additions & 50 deletions packages/homebridge-ring/camera-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
SrtpSession,
SrtcpSession,
} from 'werift'
import type { StreamingSession } from 'ring-client-api/lib/streaming/streaming-session'
import type { StreamingSession } from 'ring-client-api/streaming/streaming-session'
import { OpusRepacketizer } from './opus-repacketizer'

const readFileAsync = promisify(readFile),
Expand Down Expand Up @@ -389,61 +389,63 @@ class StreamingSessionWrapper {
}

export class CameraSource implements CameraStreamingDelegate {
public controller = new hap.CameraController({
cameraStreamCount: 10,
delegate: this,
streamingOptions: {
supportedCryptoSuites: [SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80],
video: {
resolutions: [
[1280, 720, 30],
[1024, 768, 30],
[640, 480, 30],
[640, 360, 30],
[480, 360, 30],
[480, 270, 30],
[320, 240, 30],
[320, 240, 15], // Apple Watch requires this configuration
[320, 180, 30],
],
codec: {
profiles: [H264Profile.BASELINE],
levels: [H264Level.LEVEL3_1],
},
},
audio: {
codecs: this.useOpus
? [
{
type: AudioStreamingCodecType.OPUS,
// required by watch
samplerate: AudioStreamingSamplerate.KHZ_8,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_24,
},
]
: [
{
type: AudioStreamingCodecType.AAC_ELD,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
],
},
},
})
public controller
private sessions: { [sessionKey: string]: StreamingSessionWrapper } = {}
private cachedSnapshot?: Buffer

constructor(
private ringCamera: RingCamera,
private useOpus = false,
) {}
) {
this.controller = new hap.CameraController({
cameraStreamCount: 10,
delegate: this,
streamingOptions: {
supportedCryptoSuites: [SRTPCryptoSuites.AES_CM_128_HMAC_SHA1_80],
video: {
resolutions: [
[1280, 720, 30],
[1024, 768, 30],
[640, 480, 30],
[640, 360, 30],
[480, 360, 30],
[480, 270, 30],
[320, 240, 30],
[320, 240, 15], // Apple Watch requires this configuration
[320, 180, 30],
],
codec: {
profiles: [H264Profile.BASELINE],
levels: [H264Level.LEVEL3_1],
},
},
audio: {
codecs: this.useOpus
? [
{
type: AudioStreamingCodecType.OPUS,
// required by watch
samplerate: AudioStreamingSamplerate.KHZ_8,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
{
type: AudioStreamingCodecType.OPUS,
samplerate: AudioStreamingSamplerate.KHZ_24,
},
]
: [
{
type: AudioStreamingCodecType.AAC_ELD,
samplerate: AudioStreamingSamplerate.KHZ_16,
},
],
},
},
})
}

private previousLoadSnapshotPromise?: Promise<any>
async loadSnapshot(imageUuid?: string) {
Expand Down
10 changes: 6 additions & 4 deletions packages/homebridge-ring/camera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import { firstValueFrom } from 'rxjs'

export class Camera extends BaseDataAccessory<RingCamera> {
private inHomeDoorbellStatus: boolean | undefined
private cameraSource = new CameraSource(
this.device,
this.config.unbridgeCameras,
)
private cameraSource

constructor(
public readonly device: RingCamera,
Expand All @@ -23,6 +20,11 @@ export class Camera extends BaseDataAccessory<RingCamera> {
) {
super()

this.cameraSource = new CameraSource(
this.device,
this.config.unbridgeCameras,
)

if (!hap.CameraController) {
const error =
'HAP CameraController not found. Please make sure you are on homebridge version 1.0.0 or newer'
Expand Down
4 changes: 3 additions & 1 deletion packages/homebridge-ring/location-mode-switch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ function getStateFromMode(mode: LocationMode) {

export class LocationModeSwitch extends BaseAccessory<Location> {
private targetState: any
public device = this.location // for use in BaseAccessory
public device

constructor(
private readonly location: Location,
public readonly accessory: PlatformAccessory,
public readonly config: RingPlatformConfig,
) {
super()
this.device = location // for use in BaseAccessory

const {
Characteristic,
Service: { SecuritySystem, AccessoryInformation },
Expand Down
8 changes: 5 additions & 3 deletions packages/homebridge-ring/security-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ function isValidNightModeBypass(mode?: AlarmMode) {
}

export class SecurityPanel extends BaseDeviceAccessory {
private alarmStates: AlarmState[] = this.config.alarmOnEntryDelay
? allAlarmStates
: allAlarmStates.filter((x) => x !== 'entry-delay')
private alarmStates: AlarmState[]

constructor(
public readonly device: RingDevice,
Expand All @@ -28,6 +26,10 @@ export class SecurityPanel extends BaseDeviceAccessory {
) {
super()

this.alarmStates = this.config.alarmOnEntryDelay
? allAlarmStates
: allAlarmStates.filter((x) => x !== 'entry-delay')

const { Characteristic, Service } = hap,
validValues = [
Characteristic.SecuritySystemTargetState.AWAY_ARM,
Expand Down
3 changes: 2 additions & 1 deletion packages/ring-client-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
".": "./lib/index.js",
"./ffmpeg": "./lib/ffmpeg.js",
"./util": "./lib/util.js",
"./rest-client": "./lib/rest-client.js"
"./rest-client": "./lib/rest-client.js",
"./streaming/streaming-session": "./lib/streaming/streaming-session.js"
},
"scripts": {
"build": "rm -rf lib && tsc --declaration && chmod +x ./lib/ring-*-cli.js",
Expand Down
28 changes: 15 additions & 13 deletions packages/ring-client-api/rest-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,9 @@ function parseAuthConfig(rawRefreshToken?: string): AuthConfig | undefined {
}

export class RingRestClient {
public refreshToken =
'refreshToken' in this.authOptions
? this.authOptions.refreshToken
: undefined
private authConfig = parseAuthConfig(this.refreshToken)
private hardwareIdPromise =
this.authConfig?.hid || getHardwareId(this.authOptions.systemId)
public refreshToken
private authConfig
private hardwareIdPromise
private _authPromise: Promise<AuthTokenResponse> | undefined
private timeouts: ReturnType<typeof setTimeout>[] = []
private clearPreviousAuth() {
Expand Down Expand Up @@ -259,15 +255,21 @@ export class RingRestClient {
newRefreshToken: string
}>(1)
public onSession = new ReplaySubject<SessionResponse>(1)
public readonly baseSessionMetadata = {
api_version: apiVersion,
device_model:
this.authOptions.controlCenterDisplayName ?? 'ring-client-api',
}
public readonly baseSessionMetadata

constructor(
private authOptions: (EmailAuth | RefreshTokenAuth) & SessionOptions,
) {}
) {
this.refreshToken =
'refreshToken' in authOptions ? authOptions.refreshToken : undefined
this.authConfig = parseAuthConfig(this.refreshToken)
this.hardwareIdPromise =
this.authConfig?.hid || getHardwareId(authOptions.systemId)
this.baseSessionMetadata = {
api_version: apiVersion,
device_model: authOptions.controlCenterDisplayName ?? 'ring-client-api',
}
}

private getGrantData(twoFactorAuthCode?: string) {
if (this.authConfig?.rt && !twoFactorAuthCode) {
Expand Down
6 changes: 3 additions & 3 deletions packages/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"compilerOptions": {
"target": "ES2021",
"lib": ["ES2021", "dom"],
"module": "commonjs",
"target": "ES2022",
"lib": ["ES2023", "DOM"],
"module": "node16",
"esModuleInterop": true,
"allowJs": true,
"strict": true,
Expand Down

0 comments on commit abd5e98

Please sign in to comment.