0.12.1 • Published 4 years ago

blink-cameras v0.12.1

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

blink - Blink Camera API for Node.js, written in Typescript.

npm Known Vulnerabilities npm

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

  1. Checkout the repo:
git clone https://github.com/jonathandann/blink-cameras.git && cd blink-cameras && npm install
  1. Launch the repl:
node --experimental-repl-await
  1. 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
0.12.1

4 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.10.0

4 years ago

0.9.1

4 years ago

0.9.0

4 years ago