diff --git a/README.md b/README.md index 03a1002..f660de7 100644 --- a/README.md +++ b/README.md @@ -11,14 +11,14 @@ This add-on wraps around [Dgreif's excellent work](https://github.com/dgreif/rin 2. Configure your Ring Refresh Token and port (see configuration below). 3. Start the "Ring Livestream" add-on. Check for errors in the logs. 4. For remote access, open up the port in your router. -5. Open the stream at http://hassio.local:port/public/stream.m3u8 to make sure it works before going any further. We recommend using VLC or equivalent. +5. Open the stream at http://homeassistant.local:port/public/stream.m3u8 to make sure it works before going any further. We recommend using VLC or equivalent. 6. Add a camera to Home Assistant, such as: ```yaml camera: - platform: generic name: Ring Livestream - stream_source: http://hassio.local:port/public/stream.m3u8 - still_image_url: http://hassio.local:port/public/stream.m3u8 + stream_source: http://homeassistant.local:port/public/stream.m3u8 + still_image_url: http://homeassistant.local:port/public/stream.m3u8 ``` (Don't worry about the `still_image_url` not pointing to an actual image, we are not going to use it, but it is required.) 7. Add a card `Picture Glance` card to your UI, set the 'Camera Entity` to the camera you have just created. @@ -26,12 +26,12 @@ This add-on wraps around [Dgreif's excellent work](https://github.com/dgreif/rin ## Configuration Example configuration: -```json -{ - "ring_refresh_token": your_refresh_token -} +```yaml +ring_refresh_token: your_refresh_token +camera_name: Front Door ``` -You need to create a refresh token - see https://github.com/dgreif/ring/wiki/Refresh-Tokens on how to do that. Note that you will have to have node and npm installed on your machine. +* You need to create a refresh token - see https://github.com/dgreif/ring/wiki/Refresh-Tokens on how to do that. Note that you will have to have node and npm installed on your machine. +* The camera name is the name entred when setting up the camera in the Ring app. ## Taking a snapshot Currently the addon does not support taking snapshots, but when it does this is the configuration you will need: diff --git a/ring_hassio/config.json b/ring_hassio/config.json index ed74d69..51b075b 100644 --- a/ring_hassio/config.json +++ b/ring_hassio/config.json @@ -1,6 +1,6 @@ { "name": "Ring Livestream", - "version": "1.3", + "version": "1.35", "slug": "ringlivestream", "description": "A Home Assistant add-on to enable live streams of Ring Cameras.", "url": "https://github.com/jeroenterheerdt/ring-hassio", @@ -22,10 +22,12 @@ "webui": "http://[HOST]:[PORT:3000]/index.html", "options": { "ring_refresh_token": "refresh_token", + "camera_name": "Front Door", "port": 3000 }, "schema": { "ring_refresh_token":"str", + "camera_name": "str", "port":"port" }, "map": [ diff --git a/ring_hassio/livestream.js b/ring_hassio/livestream.js index 7701cd9..25f2879 100644 --- a/ring_hassio/livestream.js +++ b/ring_hassio/livestream.js @@ -41,14 +41,50 @@ require("dotenv/config"); var ring_client_api_1 = require("ring-client-api"); var util_1 = require("util"); var fs = require('fs'), path = require('path'), http = require('http'), url = require('url'), zlib = require('zlib'); -//const PORT = 3000; var PORT = process.env.RING_PORT; +// +var CAMERA_NAME = process.env.CAMERA_NAME; +var chosenCamera = CAMERA_NAME; /** * This example creates an hls stream which is viewable in a browser * It also starts web app to view the stream at http://localhost:PORT **/ function startStream() { return __awaiter(this, void 0, void 0, function () { + /////////////// + function getCamera() { + return __awaiter(this, void 0, void 0, function () { + var cameras, camera, i, cameraName; + return __generator(this, function (_a) { + switch (_a.label) { + case 0: return [4 /*yield*/, ringApi.getCameras()]; + case 1: + cameras = _a.sent(); + // + if (!chosenCamera) { + for (i = 0; i < cameras.length; i++) { + cameraName = cameras[i].initialData.description; + console.log("Checking If " + cameraName + " Is the same as the camera we are looking for (" + chosenCamera + ")"); + if (chosenCamera == cameraName) { + camera = cameras[i]; + console.log("Matched " + cameraName); + } + } + } + else { + camera = cameras[0]; + } + // + if (!cameras) { + console.log('No cameras found'); + return [2 /*return*/]; + } + // + return [2 /*return*/, camera]; + } + }); + }); + } var ringApi, camera, publicOutputDirectory, server, sockets, nextSocketId, sipSession; return __generator(this, function (_a) { switch (_a.label) { @@ -58,36 +94,24 @@ function startStream() { refreshToken: process.env.RING_REFRESH_TOKEN, debug: true }); - return [4 /*yield*/, ringApi.getCameras()]; + return [4 /*yield*/, getCamera() + /////////////// + ]; case 1: - camera = (_a.sent())[0]; - if (!camera) { - console.log('No cameras found'); - return [2 /*return*/]; - } + camera = _a.sent(); publicOutputDirectory = path.join('public/'); - /*fs.readdir(publicOutputDirectory, (err, files) => { - if (err) throw err; - for (const file of files) { - var filepath = path.join(publicOutputDirectory,file); - if (path.extname(file) == ".ts") { - fs.unlink(filepath,err => { - if (err) throw err; - }); - } - } - });*/ console.log('output directory: ' + publicOutputDirectory); server = http.createServer(function (req, res) { + // Get URL var uri = url.parse(req.url).pathname; console.log('requested uri: ' + uri); + // If Accessing The Main Page if (uri == '/index.html' || uri == '/') { res.writeHead(200, { 'Content-Type': 'text/html' }); - res.write('