0.12.1 • Published 5 years ago
blink-cameras v0.12.1
blink - Blink Camera API for Node.js, written in Typescript.
API wrapper for the the undocumented API used by Blink.
Installation
npm install --save blink
Features
- Commands such as
arm()
,disarm()
, etc., poll the "command status" API endpoint so we know when they're complete. This avoids us sending multiple commands at the same time and getting HTTP 409 (Conflict) errors back. Allowing you to disable/enable multpile cameras using HomeKit scenes (see https://github.com/jonathandann/homebridge-blink). - Access tokens are cached in-memory (see
Blink._account
). We fetch a new access token when the token expires and API calls fail with HTTP 401 (Unauthorized) and re-try the original command.
Typescript
The NPM module ships pre-compiled js
files, and d.ts
files so it still can be used from typescript directly.
// File.ts
import { Blink } from 'blink'
const blink = new Blink("username", "password")
await blink.update() // Fetch networks and cameras
const networks = blink.networks()
const cameras = blink.cameras() // Optionally pass a Network
const network = // One of the networks
const camera = // One of the cameras
// Get the current state of a network or camera
const updatedCamera = await blink.updateCamera(camera)
const updatedNetwork = await blink.updateNetwork(network)
// Arm/activate a network or camera
const armedNetwork = await blink.arm(network)
const enabledCamera = await camera.enableMotionDetection(camera)
const disarmedNetwork = await blink.disarm(network)
const disabledCamera = await camera.disableMotionDetection(camera)
Building from Source
git clone https://github.com/jonathandann/blink-cameras.git && cd blink-cameras && npm install
After running npm install
, npm
should automatically run npm run build
, which runs node_modules/typescript/bin/tsc
to compile the typescript files. If it doesn't then you can run either node_modules/typescript/bin/tsc
or npm run build
.
There are useful configs already included for prettier and Visual Studio Code.
Visual Studio Code is configured to use the version of typescript installed as a development dependency in the npm package.
Experimenting in the Node.js REPL
- Checkout the repo:
git clone https://github.com/jonathandann/blink-cameras.git && cd blink-cameras && npm install
- Launch the repl:
node --experimental-repl-await
- Import the things you need and make some API calls:
var Logger = require("./dist/Logger.js")
var Blink = require("./dist/Blink.js")
var b = new Blink.Blink("username", "password", new Logger.Logger(1 | 2 | 4, console.log))
await b.update()
var cameras = await b.cameras()
cameras // Logs the output