https://github.com/sango-tech/camera_proxy_node
Nodejs + MJPEG
https://github.com/sango-tech/camera_proxy_node
Last synced: about 1 year ago
JSON representation
Nodejs + MJPEG
- Host: GitHub
- URL: https://github.com/sango-tech/camera_proxy_node
- Owner: sango-tech
- Created: 2021-08-16T09:59:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-17T03:23:53.000Z (almost 5 years ago)
- Last Synced: 2025-02-06T05:30:09.997Z (over 1 year ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Introduction
This module proxies MJPEG streams (from an IP camera, for example) to a given endpoint of your choice using [express.js](https://expressjs.com/).
### Events
* `error` If the stream errors.
* `addClient` When a new client begins consuming the proxy stream.
* `dropClient` When a client closes the connection with the proxy stream.
### Example Usage
```javascript
var express = require("express");
var proxy = require("express-mjpeg-proxy").Proxy;
var url = "Insert MJPEG stream here";
var server = express();
server.get("/", new proxy(url).requestHandler);
server.listen(8080);
```
### How to run
Run `npm start [PORT]` to start a sample express.js server running the stream. Note that you will need to have express.js installed in the package already (`npm install express`) in order for this to work.
### Details
When a new Proxy object is created, it will establish a connection to the MJPEG stream. Any new data from the stream will be sent to any client in the `clients` array.
The argument can either be a string (in the form a URL) or an object acceptable by [http.request](https://nodejs.org/api/http.html#http_http_request_options_callback):
```javascript
var proxy = new Proxy("URL"); // Works
var proxy = new Proxy({
host: "...",
port: "80",
method: "GET"
path: "/cam.mjpeg"
}); // Also works
```
When requestHandler is executed, it will add the new client to the clients array. When the client closes the connection, it will be removed from the clients array. requestHandler will also send headers to every new client that preserve the boundary value in the Content-Type header.