@koush/ring-client-api
Version:
Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting
58 lines (57 loc) • 3.19 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
require("dotenv/config");
const api_1 = require("../api");
const util_1 = require("../api/util");
function example() {
return __awaiter(this, void 0, void 0, function* () {
const { env } = process, ringApi = new api_1.RingApi({
// Replace with your refresh token
refreshToken: env.RING_REFRESH_TOKEN,
}), locations = yield ringApi.getLocations(), location = locations[0], cameras = yield ringApi.getCameras(), camera = cameras[0];
// Locations API
location.onConnected.subscribe((connected) => {
const state = connected ? 'Connected' : 'Connecting';
console.log(`${state} to location ${location.name} - ${location.id}`);
});
const locationCameraEvents = yield location.getCameraEvents({
// same params as camera.getEvents
}), locationAlarmEvents = yield location.getHistory({
limit: 1,
category: 'alarm',
//offset: 100 - number of events to skip over for pagination
}), locationBeamsEvents = yield location.getHistory({
limit: 1,
category: 'beams',
});
console.log('Location Camera Event', locationCameraEvents.events[0]);
console.log('Location Alarm Event', locationAlarmEvents[0]);
console.log('Location Beams Event', locationBeamsEvents[0]);
console.log('Monitoring Status', yield location.getAccountMonitoringStatus());
// Camera API
const eventsResponse = yield 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((event) => event.recording_status === 'ready'), transcodedUrl = yield camera.getRecordingUrl(eventsWithRecordings[0].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 = yield camera.getRecordingUrl(eventsWithRecordings[0].ding_id_str);
console.log('Recording Transcoded URL', transcodedUrl);
console.log('Recording Untranscoded URL', untranscodedUrl);
});
}
example().catch(util_1.logError);