https://github.com/konsumer/blink-data
Interact with blink camera servers in javascript
https://github.com/konsumer/blink-data
Last synced: 11 months ago
JSON representation
Interact with blink camera servers in javascript
- Host: GitHub
- URL: https://github.com/konsumer/blink-data
- Owner: konsumer
- Created: 2019-12-05T01:46:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:21:47.000Z (over 3 years ago)
- Last Synced: 2024-05-02T01:29:05.122Z (about 2 years ago)
- Language: JavaScript
- Size: 1.9 MB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# blink-data
Interact with blink camera servers in javascript
This will allow you to interact with [blink cameras](https://blinkforhome.com/). You can use it in node, electron, or a browser (with CORS security disabled.)
## install
```
npm i blink-data
```
## usage
### basics
```js
import { Blink } from 'blink-data'
async function run () {
const blink = new Blink()
await blink.login('me@demo.com', 'mypassword')
// get current user-info
const user = await blink.user()
console.log(user)
// get list of current user's networks
const networks = await blink.networks()
console.log(networks)
// get details about a network
const network = await blink.network(networks[0].id)
console.log(network)
// get a list of videos
const videos = await blink.videos()
console.log(videos)
// get details about a camera
const camera = await blink.camera(networks[0].network_id, networks[0].cameras[0].id)
console.log(camera)
}
run()
```
I haven't setup API-docs yet, but you can see usage examples iun the [unit-test](https://github.com/konsumer/blink-data/blob/master/src/blink-data.test.js).
### browser
You will need to disable CORS security for this to work directly from blink servers, in a browser:
Close all instances of Chrome browser (open taskmanager and kill any resilient Chrome process). Execute
Windows
```
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe --disable-web-security --user-data-dir=.
```
MacOS
```
open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --args --disable-web-security --user-data-dir=
```
You can also do this in your own electron app:
```js
const win = new BrowserWindow({
webPreferences: { webSecurity: false }
})
```
Alternatively, if you want to do it all in IPC-space, you can:
```js
const Blink = require('electron').remote.require('blink-data')
```
And CORS-security should be disabled for just blink.
### rehydrate
If you are using this on a webserver, or just want to login via a token (instead of email/password), you can rehydrate them to work with their session:
```js
const blink = new Blink()
blink.hydrate (token, account, region)
blink.user().then(console.log)
```
You can get `token`, `account`, and `region` from the output of `blink.login()`, so store this, and send it via a cookie/session/header.
Here is a client-side example using `localStorage`:
```js
// at login time
const blink = new Blink()
const { authtoken, account, region } = await blink.login(email, password)
localStorage.user = JSON.stringify({ token: authtoken.authtoken, id: account.id, region: Object.keys(region)[0] })
// later
const blink = new Blink()
const { token, id, region } = JSON.parse(localStorage.user)
blink.hydrate(token, id, region)
blink.user().then(console.log)
```
## TODO
* Still need to support programs
* There are a lot of other API endpoints to wrap
* need to use commandPolling to check for things finishing and resolve/reject when finished
* need to work out video proxy for `rtsps://`. [this](https://www.npmjs.com/package/node-rtsp-stream) should help.
* Better cross-platform (browser vs node) binary support for images & videos
## related
* [Here](https://github.com/konsumer/blink-desktop) is my desktop-client, using electron.
## credit
Big shout-out to [MattTW's BlinkMonitorProtocol](https://github.com/MattTW/BlinkMonitorProtocol/). This is totally generated from that. [bling-viewer](https://github.com/lurume84/bling-viewer) is also great, and helped work out some parts.