{"id":27193394,"url":"https://github.com/amattu2/blink-liveview-middleware","last_synced_at":"2025-04-09T18:55:47.518Z","repository":{"id":275518935,"uuid":"922612807","full_name":"amattu2/blink-liveview-middleware","owner":"amattu2","description":"A Blink Smart Security liveview package written in Go. Includes a CLI interface for desktop-based liveview and a WebSocket liveview proxy service.","archived":false,"fork":false,"pushed_at":"2025-03-11T22:40:16.000Z","size":103,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T23:28:59.956Z","etag":null,"topics":["blink","go","smart-security","websocket"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/amattu2.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-26T17:09:16.000Z","updated_at":"2025-03-11T22:40:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"adb4ffa8-f8e4-497e-9d2d-58abcebdc88a","html_url":"https://github.com/amattu2/blink-liveview-middleware","commit_stats":null,"previous_names":["amattu2/blink-liveview-middleware"],"tags_count":2,"template":false,"template_full_name":"amattu2/project-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amattu2%2Fblink-liveview-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amattu2%2Fblink-liveview-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amattu2%2Fblink-liveview-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/amattu2%2Fblink-liveview-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/amattu2","download_url":"https://codeload.github.com/amattu2/blink-liveview-middleware/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248094049,"owners_count":21046762,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blink","go","smart-security","websocket"],"created_at":"2025-04-09T18:55:46.616Z","updated_at":"2025-04-09T18:55:47.502Z","avatar_url":"https://github.com/amattu2.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\n\nThis project offers access into the liveview functionality of the Blink Smart\nSecurity cameras. It has three entrypoints:\n\n- A WebSocket service that can act as middleware between a web application and\nthe Blink Smart Security Camera\n- A command to login to a Blink account and list the cameras available for liveview\n- A command to watch the liveview stream from the command line (ffmpeg)\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/amattu2/blink-liveview-middleware)](https://goreportcard.com/report/github.com/amattu2/blink-liveview-middleware)\n[![Test](https://github.com/amattu2/blink-liveview-middleware/actions/workflows/test.yml/badge.svg)](https://github.com/amattu2/blink-liveview-middleware/actions/workflows/test.yml)\n[![CodeQL](https://github.com/amattu2/blink-liveview-middleware/actions/workflows/codeql.yml/badge.svg)](https://github.com/amattu2/blink-liveview-middleware/actions/workflows/codeql.yml)\n\n# Usage\n\nSee the following sections for more information on how to use each entry point.\nThese sections provide instructions on usage without compiling the code yourself.\nIf you would like to compile the code yourself, see the\nBuilding From Source section below.\n\n```bash\ngo run main.go \u003ccommand\u003e [flags]\n```\n\n\u003e [!WARNING]\n\u003e Prior to running any of the commands, ensure that you have ffmpeg installed\n\u003e on your system, and configured in your PATH (if applicable).\n\n## Account Command\n\nThe account command is a simple interface for interacting with the Blink Liveview\nAPIs without retrieving technical connection details on your own. Provide the email\naddress and password for the Blink account you wish to use, and the command will\nperform the necessary steps to obtain the API token and account information.\n\nOnce retrieved, it will prompt you to select a camera to watch the liveview stream\nfrom, and then open the liveview stream in a new window using ffplay.\n\nAdditionally, the command will output the API Token, Account ID, and Region, which\ncan be used to shortcut the process in the future.\n\n```bash\ngo run main.go account \\\n    [--email=\u003cemail\u003e] \\\n    [--token=\u003capi token\u003e --account-id=\u003caccount id\u003e --region=\u003cregion\u003e]\n```\n\nAn explanation of the command line flags is provided below:\n\nOption 1: Email \u0026 Password\n\n- `-e`, `--email`: The email address of the Blink account to use\n\n\u003e [!NOTE]\n\u003e The password is not provided as a command line flag for security reasons.\n\u003e You will be prompted to enter the password after running the command.\n\nOption 2: API Token, Account ID, \u0026 Region\n\n- `-t`, `--token`: The API token for the current session. This is returned via\nthe Blink login flow\n- `-a`, `--account-id`: The account ID of the Blink account\n- `-r`, `--region`: The region of the Blink account (e.g. `u014`, `u011`, etc.)\n\n## Liveview Command\n\nThe liveview command is a direct way to watch the liveview stream from a Blink\nSmart Security Camera. It can be used in place of the above \"account command\"\nif you already have all of the necessary information to connect to the Blink API.\n\nThis is made available primarily used for testing, but can be used as\na standalone tool if desired.\n\nUpon running the command, you should see a new ffplay window open with the\nliveview stream. The stream will be gracefully closed by terminating the CLI process.\n\n```bash\ngo run main.go liveview \\\n  --region=\u003cregion\u003e \\\n  --token=\u003capi token\u003e \\\n  --device-type=\u003cdevice type\u003e \\\n  --account-id=\u003caccount id\u003e \\\n  --network-id=\u003cnetwork id\u003e \\\n  --camera-id=\u003ccamera id\u003e\n```\n\nAn explanation of the command line flags is provided below:\n\n- `-r`, `--region`: The region of the Blink account (e.g. `u014`, `u011`, etc.).\nThis is returned via the Blink login flow\n- `-t`, `--token`: The API token for the current session. This is also returned via\nthe Blink login flow\n- `-d`, `--device-type`: The type of (camera) device to connect to (e.g. `owl`, `doorbell`).\n- `-a`, `--account-id`: The account ID of the Blink account\n- `-n`, `--network-id`: The ID of the network that the camera is on\n- `-c`, `--camera-id`: The ID of the camera to watch\n\n## WebSocket Middleware\n\nThis section is broken down into two parts: the server and the client. The server\nis a WebSocket service that acts as middleware between a web application and the\nBlink Smart Security Camera. The client section provides an example of how to\ninterface with the WebSocket server using JavaScript.\n\nOut of the box, the server provides a demo UI that can be used to test the liveview\nstream via a web browser.\n\n### Server Usage\n\nThe server is a basic Go HTTP server that utilizes the Gorilla WebSocket library.\nIt has no built-in authentication or knowledge of the Blink API (beyond liveview),\nso it is entirely up to your implementing application to provide the necessary\ninformation to the server.\n\nEach client that connects to the WebSocket is independent\nof the others, so you can have multiple streams running at the same time\nwithout overlapping.\n\nStart the server with the following command:\n\n```bash\ngo run main.go server [--address=\u003caddr\u003e] [--env=\u003cenv\u003e]\n```\n\nAn explanation of the command line flags is provided below:\n\n- `-a`, `--address`: The address to bind the server to (e.g. `:8080`)\n- `-e`, `--env`: The environment to run the server in (`development`, `production`).\nIf `production` is specified, the demo UI will be disabled.\n\nThen open the sample web application in your browser. Provide the necessary\nauthentication information on the demo UI and click the \"Start Liveview\" button:\n\n\u003chttp://localhost:8080/index.html\u003e\n\n\u003e [!NOTE]\n\u003e The server does not currently limit the maximum number of clients that can\n\u003e connect OR liveview at the same time. This may cause performance issues.\n\n### Client Usage\n\nEach client that connects to the WebSocket server is independent of the others,\nwhich means that each client must forward the Blink authentication information\nto the server once connected.\n\nBy default, the server will close the connection if the client does not start\nliveview or send some sort of command within `8 seconds` of connecting.\n\nThe following is an example of how to connect to the WebSocket server using\nJavaScript:\n\n```javascript\n// Open a WebSocket connection to the server\nconst ws = new WebSocket('ws://localhost:8080/liveview');\nws.binaryType = \"arraybuffer\";\n\nws.onopen = () =\u003e {\n    // Send the authentication information to the server\n    // NOTE: This should be done within 8 seconds of connecting,\n    // or the server will close the connection\n    const data = JSON.stringify({\n        command: \"liveview:start\",\n        data: {\n            // Refer to the liveview CLI arguments for details on these fields\n            account_region: \"\",\n            api_token: \"\",\n            account_id: \"\",\n            network_id: \"\",\n            camera_id: \"\",\n            camera_type: \"\",\n        },\n    });\n\n    ws.send(data);\n};\n\n// Handle incoming messages from the server\nws.onmessage = (evt) =\u003e {\n    if (evt.data instanceof ArrayBuffer) {\n        // Handle incoming video packets\n        return;\n    }\n\n    const data = JSON.parse(evt.data);\n    if (data?.command === \"liveview:stop\") {\n        // The server stopped the liveview\n        // Handle receipt of the stop command (e.g. stop the video player)\n    } else if (data?.command === \"liveview:start\") {\n        // The server opened the liveview\n        // binary data will begin shortly (delay of about 5 seconds)\n    }\n};\n```\n\nRefer to the demo UI [source code](static/index.html) for a more detailed example\nof how to connect and integrate the liveview stream into your web application.\n\n## Building From Source\n\n```bash\ngo build -a -o bin/blink-liveview-middleware.exe main.go\n```\n\n# Blink Liveview Process\n\nThe general process behind obtaining a liveview stream from a Blink camera is\noutlined below, ignoring the specifics of the Blink API and any potential error states.\n\n```mermaid\n---\ntitle: Blink Smart Security Liveview Process\n---\nsequenceDiagram\n    participant C as Client (You)\n    participant B as Blink HTTP API\n    participant T as Blink TCP Server\n\n    C-\u003e\u003eB: POST /liveview\n    B-\u003e\u003eC: Liveview response \n    Note over B,C: Returns TCP server and credentials\n    par TCP Connection\n        C-\u003e\u003eT: Open TCP connection\n        C-\u003e\u003eT: TCP Auth Frame (1/5)\n        C-\u003e\u003eT: TCP Auth Frame (2/5)\n        C-\u003e\u003eT: TCP Auth Frame (3/5)\n        C-\u003e\u003eT: TCP Auth Frame (4/5)\n        C-\u003e\u003eT: TCP Auth Frame (5/5)\n        loop\n            T-\u003e\u003eC: Binary stream data\n        end\n    and\n        loop\n            C-\u003e\u003eB: POST /command status\n            B-\u003e\u003eC: Command Response\n        end\n    end\n    C-\u003e\u003eB: POST /command/done\n    Note over B,C: Sent once the TCP connection is closed\n    B-\u003e\u003eC: Command Response\n```\n\n# Dependencies\n\n- Go 1.23+\n- Gorilla WebSocket\n- ffmpeg / ffplay\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famattu2%2Fblink-liveview-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Famattu2%2Fblink-liveview-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Famattu2%2Fblink-liveview-middleware/lists"}