@@ -18,48 +18,81 @@ These sections provide instructions on usage without compiling the code yourself
18
18
If you would like to compile the code yourself, see the
19
19
Building From Source section below.
20
20
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
+
21
25
## Liveview Command
22
26
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
24
28
liveview stream from a Blink Smart Security Camera. It's primarily used for testing,
25
29
but can be used as a standalone tool if desired.
26
30
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
+
27
34
``` bash
28
35
go run cmd/liveview/main.go \
29
36
--region=< region> \
30
37
--token=< api token> \
31
- --device-type=< lotus | owl | doorbell | etc > \
38
+ --device-type=< device type > \
32
39
--account-id=< account id> \
33
40
--network-id=< network id> \
34
41
--camera-id=< camera id>
35
42
```
36
43
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
+
37
55
## WebSocket Middleware
38
56
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
+
39
65
### Server Usage
40
66
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.
45
71
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.
50
75
51
76
Start the server with the following command:
52
77
53
78
``` bash
54
- go run cmd/server/main.go --address=:8080 --env=< development | production >
79
+ go run cmd/server/main.go [ --address=< addr > ] [ --env=< env > ]
55
80
```
56
81
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
+
57
88
Then open the sample web application in your browser. Provide the necessary
58
89
authentication information on the demo UI and click the "Start Liveview" button:
59
90
60
91
< http://localhost:8080/index.html >
61
92
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.
63
96
64
97
### Client Usage
65
98
@@ -78,18 +111,20 @@ JavaScript:
78
111
const ws = new WebSocket (' ws://localhost:8080/liveview' );
79
112
ws .binaryType = " arraybuffer" ;
80
113
81
- // Send the authentication information to the server
82
- // NOTE: This does not have to be done immediately after opening the connection
83
114
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
84
118
const data = JSON .stringify ({
85
119
command: " liveview:start" ,
86
120
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: " " ,
93
128
},
94
129
});
95
130
@@ -99,21 +134,24 @@ ws.onopen = () => {
99
134
// Handle incoming messages from the server
100
135
ws .onmessage = (evt ) => {
101
136
if (evt .data instanceof ArrayBuffer ) {
102
- // Handle incoming livestream packets
137
+ // Handle incoming video packets
103
138
return ;
104
139
}
105
140
106
141
const data = JSON .parse (evt .data );
107
142
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)
110
145
} 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)
113
148
}
114
149
};
115
150
` ` `
116
151
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
+
117
155
## Building From Source
118
156
119
157
` ` ` bash
@@ -123,7 +161,7 @@ go build -a -o bin/server.exe cmd/server/main.go
123
161
go build - a - o bin/ liveview .exe cmd/ liveview/ main .go
124
162
` ` `
125
163
126
- # Liveview Process
164
+ # Blink Liveview Process
127
165
128
166
The general process behind obtaining a liveview stream from a Blink camera is
129
167
outlined below, ignoring the specifics of the Blink API and any potential error states.
@@ -164,4 +202,5 @@ sequenceDiagram
164
202
# Dependencies
165
203
166
204
- Go 1.23+
205
+ - Gorilla WebSocket
167
206
- ffmpeg / ffplay
0 commit comments