Last active
November 16, 2023 20:52
-
-
Save jaypsan/efadf83871b751b031ebed288cdf0408 to your computer and use it in GitHub Desktop.
Get snapshot from IP camera with Onvif protocol and send through express http response
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function handler(req, res) { | |
const {hostname, username, password} = req.body | |
new Cam({ | |
hostname | |
, username | |
, password | |
}, function(err){ | |
this.getSnapshotUri({protocol:'RTSP'}, function (err, stream){ | |
// Make GET request to snapshot uri from câmera | |
http.get(stream.uri, {auth: `${username}:${password}`}, (httpResponse) => { | |
// Array for the httpResponse buffers | |
var buffers = [] | |
// When receive data, push to array. | |
// When finished, send image to res | |
httpResponse.on('data', (data) => { | |
buffers.push(data) | |
}).on('end', () => { | |
res.contentType('image/jpeg') | |
res.send(new Buffer.concat(buffers)) | |
}) | |
}) | |
}) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment