* 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
()
| 11 | **/ |
| 12 | |
| 13 | async function example() { |
| 14 | const ringApi = new RingApi({ |
| 15 | // Replace with your refresh token |
| 16 | refreshToken: process.env.RING_REFRESH_TOKEN!, |
| 17 | debug: true, |
| 18 | }), |
| 19 | [camera] = await ringApi.getCameras() |
| 20 | |
| 21 | if (!camera) { |
| 22 | console.log('No cameras found') |
| 23 | return |
| 24 | } |
| 25 | |
| 26 | const app = express(), |
| 27 | __dirname = new URL('.', import.meta.url).pathname, |
| 28 | publicOutputDirectory = path.join(__dirname, 'public/output') |
| 29 | |
| 30 | app.use('/', express.static(path.join(__dirname, 'public'))) |
| 31 | app.listen(3000, () => { |
| 32 | console.log( |
| 33 | 'Listening on port 3000. Go to http://localhost:3000 in your browser', |
| 34 | ) |
| 35 | }) |
| 36 | |
| 37 | if (!(await fs.stat(publicOutputDirectory))) { |
| 38 | await fs.mkdir(publicOutputDirectory) |
| 39 | } |
| 40 | |
| 41 | const call = await camera.streamVideo({ |
| 42 | output: [ |
| 43 | '-preset', |
| 44 | 'veryfast', |
| 45 | '-g', |
| 46 | '25', |
| 47 | '-sc_threshold', |
| 48 | '0', |
| 49 | '-f', |
| 50 | 'hls', |
| 51 | '-hls_time', |
| 52 | '2', |
| 53 | '-hls_list_size', |
| 54 | '6', |
| 55 | '-hls_flags', |
| 56 | 'delete_segments', |
| 57 | path.join(publicOutputDirectory, 'stream.m3u8'), |
| 58 | ], |
| 59 | }) |
| 60 | |
| 61 | call.onCallEnded.subscribe(() => { |
| 62 | console.log('Call has ended') |
| 63 | process.exit() |
| 64 | }) |
| 65 | |
| 66 | setTimeout( |
| 67 | function () { |
| 68 | console.log('Stopping call...') |
| 69 | call.stop() |
| 70 | }, |
no test coverage detected