Skip to content

Commit 381e103

Browse files
committed
Add more usage documentation
1 parent d8fcc7f commit 381e103

File tree

2 files changed

+71
-27
lines changed

2 files changed

+71
-27
lines changed

README.md

Lines changed: 65 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,81 @@ These sections provide instructions on usage without compiling the code yourself
1818
If you would like to compile the code yourself, see the
1919
Building From Source section below.
2020

21+
> [!WARNING]
22+
> Prior to running any of the commands, ensure that you have ffmpeg installed
23+
> on your system, and configured in your PATH (if applicable).
24+
2125
## Liveview Command
2226

23-
The liveview script is a simple tool that uses ffmpeg to watch the
27+
The liveview command is a simple tool that uses ffplay (ffmpeg) to watch the
2428
liveview stream from a Blink Smart Security Camera. It's primarily used for testing,
2529
but can be used as a standalone tool if desired.
2630

31+
Upon running the command, you should see a new window open with the liveview stream.
32+
The stream will be gracefully closed by terminating the CLI process.
33+
2734
```bash
2835
go run cmd/liveview/main.go \
2936
--region=<region> \
3037
--token=<api token> \
31-
--device-type=<lotus|owl|doorbell|etc> \
38+
--device-type=<device type> \
3239
--account-id=<account id> \
3340
--network-id=<network id> \
3441
--camera-id=<camera id>
3542
```
3643

44+
An explanation of the command line flags is provided below:
45+
46+
- `--region`: The region of the Blink account (e.g. `u014`, `u011`, etc.). This
47+
is returned via the Blink login flow
48+
- `--token`: The API token for the current session. This is also returned via
49+
the Blink login flow
50+
- `--device-type`: The type of (camera) device to connect to (e.g. `owl`, `doorbell`).
51+
- `--account-id`: The account ID of the Blink account
52+
- `--network-id`: The ID of the network that the camera is on
53+
- `--camera-id`: The ID of the camera to watch
54+
3755
## WebSocket Middleware
3856

57+
This section is broken down into two parts: the server and the client. The server
58+
is a WebSocket service that acts as middleware between a web application and the
59+
Blink Smart Security Camera. The client section provides an example of how to
60+
interface with the WebSocket server using JavaScript.
61+
62+
Out of the box, the server provides a demo UI that can be used to test the liveview
63+
stream via a web browser.
64+
3965
### Server Usage
4066

41-
The WebSocket server is a middleware service that can be used to proxy
42-
liveview streams from a Blink Smart Security Camera to a web application. It
43-
is designed to be used in conjunction with a web application that can send
44-
commands to the server to start and stop the liveview stream.
67+
The server is a basic Go HTTP server that utilizes the Gorilla WebSocket library.
68+
It has no built-in authentication or knowledge of the Blink API (beyond liveview),
69+
so it is entirely up to your implementing application to provide the necessary
70+
information to the server.
4571

46-
It has no built-in authentication or knowledge of the Blink API, so it is up to
47-
your implementing application to provide the necessary information to the server.
48-
Each client that connects to the WebSocket is independent of the others, so
49-
you can have multiple streams running at the same time without overlapping.
72+
Each client that connects to the WebSocket is independent
73+
of the others, so you can have multiple streams running at the same time
74+
without overlapping.
5075

5176
Start the server with the following command:
5277

5378
```bash
54-
go run cmd/server/main.go --address=:8080 --env=<development|production>
79+
go run cmd/server/main.go [--address=<addr>] [--env=<env>]
5580
```
5681

82+
An explanation of the command line flags is provided below:
83+
84+
- `--address`: The address to bind the server to (e.g. `:8080`)
85+
- `--env`: The environment to run the server in (`development`, `production`).
86+
If `production` is specified, the demo UI will be disabled.
87+
5788
Then open the sample web application in your browser. Provide the necessary
5889
authentication information on the demo UI and click the "Start Liveview" button:
5990

6091
<http://localhost:8080/index.html>
6192

62-
When deploying the service to production, this page is disabled by default.
93+
> [!NOTE]
94+
> The server does not currently limit the maximum number of clients that can
95+
> connect OR liveview at the same time. This may cause performance issues.
6396
6497
### Client Usage
6598

@@ -78,18 +111,20 @@ JavaScript:
78111
const ws = new WebSocket('ws://localhost:8080/liveview');
79112
ws.binaryType = "arraybuffer";
80113

81-
// Send the authentication information to the server
82-
// NOTE: This does not have to be done immediately after opening the connection
83114
ws.onopen = () => {
115+
// Send the authentication information to the server
116+
// NOTE: This should be done within 8 seconds of connecting,
117+
// or the server will close the connection
84118
const data = JSON.stringify({
85119
command: "liveview:start",
86120
data: {
87-
account_region: "",
88-
api_token: "",
89-
account_id: "",
90-
network_id: "",
91-
camera_id: "",
92-
camera_type: "",
121+
// Refer to the liveview CLI arguments for details on these fields
122+
account_region: "",
123+
api_token: "",
124+
account_id: "",
125+
network_id: "",
126+
camera_id: "",
127+
camera_type: "",
93128
},
94129
});
95130

@@ -99,21 +134,24 @@ ws.onopen = () => {
99134
// Handle incoming messages from the server
100135
ws.onmessage = (evt) => {
101136
if (evt.data instanceof ArrayBuffer) {
102-
// Handle incoming livestream packets
137+
// Handle incoming video packets
103138
return;
104139
}
105140

106141
const data = JSON.parse(evt.data);
107142
if (data?.command === "liveview:stop") {
108-
// Handle receipt of the stop command
109-
// The server stopped the livestream
143+
// The server stopped the liveview
144+
// Handle receipt of the stop command (e.g. stop the video player)
110145
} else if (data?.command === "liveview:start") {
111-
// The server opened the livestream
112-
// binary data will begin shortly
146+
// The server opened the liveview
147+
// binary data will begin shortly (delay of about 5 seconds)
113148
}
114149
};
115150
```
116151
152+
Refer to the demo UI [source code](static/index.html) for a more detailed example
153+
of how to connect and integrate the liveview stream into your web application.
154+
117155
## Building From Source
118156
119157
```bash
@@ -123,7 +161,7 @@ go build -a -o bin/server.exe cmd/server/main.go
123161
go build -a -o bin/liveview.exe cmd/liveview/main.go
124162
```
125163
126-
# Liveview Process
164+
# Blink Liveview Process
127165
128166
The general process behind obtaining a liveview stream from a Blink camera is
129167
outlined below, ignoring the specifics of the Blink API and any potential error states.
@@ -164,4 +202,5 @@ sequenceDiagram
164202
# Dependencies
165203
166204
- Go 1.23+
205+
- Gorilla WebSocket
167206
- ffmpeg / ffplay

liveview/liveview.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ func Run(region *string, token *string, deviceType *string, accountId *int, netw
4141
os.Exit(1)
4242
}
4343

44-
ffplayCmd := exec.Command("ffplay", "-f", "mpegts", "-err_detect", "ignore_err", "-")
44+
ffplayCmd := exec.Command("ffplay",
45+
"-f", "mpegts",
46+
"-err_detect", "ignore_err",
47+
"-window_title", "Blink Liveview Middleware",
48+
"-",
49+
)
4550
inputPipe, err := ffplayCmd.StdinPipe()
4651
if err != nil {
4752
log.Println("error creating ffplay stdin pipe", err)

0 commit comments

Comments
 (0)