UNPKG

@koush/ring-client-api

Version:

Unofficial API for Ring doorbells, cameras, security alarm system and smart lighting

70 lines (69 loc) 2.83 kB
"use strict"; 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("util"); const util_2 = require("../api/util"); const fs = require('fs'), path = require('path'), express = require('express'); /** * This example creates an hls stream which is viewable in a browser * It also starts web app to view the stream at http://localhost:3000 **/ function example() { return __awaiter(this, void 0, void 0, function* () { const ringApi = new api_1.RingApi({ // Replace with your refresh token refreshToken: process.env.RING_REFRESH_TOKEN, debug: true, }), [camera] = yield ringApi.getCameras(); if (!camera) { console.log('No cameras found'); return; } const app = express(), publicOutputDirectory = path.join('public', 'output'); app.use('/', express.static('public')); app.listen(3000, () => { console.log('Listening on port 3000. Go to http://localhost:3000 in your browser'); }); if (!(yield (0, util_1.promisify)(fs.exists)(publicOutputDirectory))) { yield (0, util_1.promisify)(fs.mkdir)(publicOutputDirectory); } const sipSession = yield camera.streamVideo({ output: [ '-preset', 'veryfast', '-g', '25', '-sc_threshold', '0', '-f', 'hls', '-hls_time', '2', '-hls_list_size', '6', '-hls_flags', 'delete_segments', path.join(publicOutputDirectory, 'stream.m3u8'), ], }); sipSession.onCallEnded.subscribe(() => { console.log('Call has ended'); process.exit(); }); setTimeout(function () { console.log('Stopping call...'); sipSession.stop(); }, 5 * 60 * 1000); // Stop after 5 minutes. }); } example().catch(util_2.logError);