diff --git a/package.json b/package.json index abe93b08..b4f8552b 100644 --- a/package.json +++ b/package.json @@ -9,12 +9,12 @@ "lint": "turbo run lint", "lint:fix": "turbo run lint -- --fix", "test:watch": "npm run test:watch -w ring-client-api", - "example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/example.ts", - "api-example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/api-example.ts", - "record-example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/record-example.ts", - "return-audio-example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/return-audio-example.ts", - "stream-example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/stream-example.ts", - "browser-example": "turbo build --filter=ring-client-api && DEBUG=ring node -r @swc-node/register ./packages/examples/browser-example.ts", + "example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/example.ts", + "api-example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/api-example.ts", + "record-example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/record-example.ts", + "return-audio-example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/return-audio-example.ts", + "stream-example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/stream-example.ts", + "browser-example": "turbo build --filter=ring-client-api && DEBUG=ring node --experimental-transform-types ./packages/examples/browser-example.ts", "auth-cli": "turbo build --filter=ring-client-api && ./packages/ring-client-api/lib/ring-auth-cli.js", "device-data-cli": "turbo build --filter=ring-client-api && ./packages/ring-client-api/lib/ring-device-data-cli.js", "push-with-tags": "git push --follow-tags", diff --git a/packages/examples/.gitignore b/packages/examples/.gitignore index 53752db2..a30bad98 100644 --- a/packages/examples/.gitignore +++ b/packages/examples/.gitignore @@ -1 +1,2 @@ output +public diff --git a/packages/examples/api-example.ts b/packages/examples/api-example.ts index 4e31568f..6ba5fd3f 100644 --- a/packages/examples/api-example.ts +++ b/packages/examples/api-example.ts @@ -38,24 +38,29 @@ async function example() { // Camera API const eventsResponse = await camera.getEvents({ - limit: 10, - kind: 'ding', - state: 'accepted', - // olderThanId: previousEventsResponse.meta.pagination_key - // favorites: true - }) - console.log('Got events', eventsResponse.events[0]) - const eventsWithRecordings = eventsResponse.events.filter( + limit: 10, + kind: 'ding', + state: 'accepted', + // olderThanId: previousEventsResponse.meta.pagination_key + // favorites: true + }), + [firstRecordedEvent] = eventsResponse.events.filter( (event) => event.recording_status === 'ready', - ), - transcodedUrl = await camera.getRecordingUrl( - eventsWithRecordings[0].ding_id_str, // MUST use the ding_id_str, not ding_id + ) + + if (!firstRecordedEvent) { + console.log('No events with recordings found') + return + } + + const transcodedUrl = await camera.getRecordingUrl( + firstRecordedEvent.ding_id_str, // MUST use the ding_id_str, not ding_id { transcoded: true, // get transcoded version of the video. false by default. transcoded has ring log and timestamp }, ), untranscodedUrl = await camera.getRecordingUrl( - eventsWithRecordings[0].ding_id_str, + firstRecordedEvent.ding_id_str, ) console.log('Recording Transcoded URL', transcodedUrl) diff --git a/packages/examples/browser-example.ts b/packages/examples/browser-example.ts index dc827d8e..2d42d968 100644 --- a/packages/examples/browser-example.ts +++ b/packages/examples/browser-example.ts @@ -24,6 +24,7 @@ async function example() { } const app = express(), + __dirname = new URL('.', import.meta.url).pathname, publicOutputDirectory = path.join(__dirname, 'public/output') app.use('/', express.static(path.join(__dirname, 'public'))) diff --git a/packages/examples/return-audio-example.ts b/packages/examples/return-audio-example.ts index eb52eb27..72f84708 100644 --- a/packages/examples/return-audio-example.ts +++ b/packages/examples/return-audio-example.ts @@ -25,7 +25,8 @@ async function example() { await cleanOutputDirectory() console.log(`Starting Return Audio to ${camera.name}...`) - const call = await camera.startLiveCall() + const call = await camera.startLiveCall(), + __dirname = new URL('.', import.meta.url).pathname console.log('Call started, activating return audio...') await Promise.all([ diff --git a/packages/examples/tsconfig.json b/packages/examples/tsconfig.json index 9e623966..0b9b7f6b 100644 --- a/packages/examples/tsconfig.json +++ b/packages/examples/tsconfig.json @@ -1,3 +1,4 @@ { - "extends": "tsconfig/tsconfig.json" + "extends": "tsconfig/tsconfig.json", + "exclude": ["public", "output"] } diff --git a/packages/examples/util.ts b/packages/examples/util.ts index 97ea79a1..01d311a9 100644 --- a/packages/examples/util.ts +++ b/packages/examples/util.ts @@ -1,6 +1,8 @@ import { join } from 'node:path' import { mkdir, rm } from 'node:fs/promises' +const __dirname = new URL('.', import.meta.url).pathname + export const outputDirectory = join(__dirname, 'output') export async function cleanOutputDirectory() {