Skip to content

Commit

Permalink
Fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreif committed Dec 21, 2024
1 parent b9a35d7 commit 95c8c52
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 20 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions packages/examples/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
output
public
29 changes: 17 additions & 12 deletions packages/examples/api-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions packages/examples/browser-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')))
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/return-audio-example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
3 changes: 2 additions & 1 deletion packages/examples/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"extends": "tsconfig/tsconfig.json"
"extends": "tsconfig/tsconfig.json",
"exclude": ["public", "output"]
}
2 changes: 2 additions & 0 deletions packages/examples/util.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit 95c8c52

Please sign in to comment.