Skip to content

Commit

Permalink
get/stop video and audio live streams, init camera configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fbertone committed Apr 12, 2017
1 parent f1a72fc commit 0fd40ed
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 5 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 1.2.0 (2017-04-12)

### Features

* **client:** (*camera*) Get snapshot
* **client:** (*camera*) Get video stream
* **client:** (*camera*) Stop video stream
* **client:** (*camera*) Get audio stream
* **client:** (*camera*) Stop audio stream

### Enhancements

* **client:** (*camera*) Better handling of pings
* **client:** (*camera*) Acks sending for responses, video and audio packets

# 1.1.0 (2017-03-31)

### Features
Expand Down
32 changes: 31 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ const client = function client (opts = {}, udpSocket) {
}

// TODO better buffer handling (deal with ordered sequence numbers, packet repetitions and packet losses)
// create a 'buffer' object and put packets as properties using seq as key.
// when a message is complete remove all parts and return complete

// TODO deal with retransmission of our packets lost during transmission
// -> must check remote acks and pings
// -> must keep a cache of our packets

socket.on('message',
function (msg, rinfo) { // check if message is from a server or the camera
Expand Down Expand Up @@ -84,7 +90,7 @@ const client = function client (opts = {}, udpSocket) {
camClient.sendPing(socket, {host: rinfo.address, port: rinfo.port})
let now = Date.now()
let past = now - currentCamSession.lastTimeReceivedPacket
if (past > 10000) {
if (past > 10000) { // TODO should send close message and reset the connection at this point
emitter.emit('lostConnection', {lastReceived: currentCamSession.lastTimeReceivedPacket, timePast: past, message: `not receiving packets since ${past / 1000} seconds`})
}
}
Expand Down Expand Up @@ -222,6 +228,26 @@ const client = function client (opts = {}, udpSocket) {
currentCamSession.mySeq++
}

const getAudioStream = function getAudioStream (stream = 1) {
camClient.getAudioStream(socket, currentCamSession.address, currentCamSession.mySeq, camCredentials, stream)
currentCamSession.mySeq++
}

const getVideoStream = function getVideoStream (stream = 10) {
camClient.getVideoStream(socket, currentCamSession.address, currentCamSession.mySeq, camCredentials, stream)
currentCamSession.mySeq++
}

const stopAudioStream = function stopAudioStream () {
camClient.stopAudioStream(socket, currentCamSession.address, currentCamSession.mySeq, camCredentials)
currentCamSession.mySeq++
}

const stopVideoStream = function stopVideoStream () {
camClient.stopVideoStream(socket, currentCamSession.address, currentCamSession.mySeq, camCredentials)
currentCamSession.mySeq++
}

const sendPing = function sendPing () {
camClient.sendPing(socket, currentCamSession.address)
}
Expand Down Expand Up @@ -254,6 +280,10 @@ const client = function client (opts = {}, udpSocket) {
sendMultipleGet,
sendGet,
getSnapshot,
getAudioStream,
getVideoStream,
stopAudioStream,
stopVideoStream,
sendPing,
on
}
Expand Down
176 changes: 172 additions & 4 deletions lib/camClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,26 @@ const getSnapshot = function getSnapshot (socket, address, seq, creds) {
sendGet(socket, address, seq, url)
}

const getAudiostream = function getAudiostream (socket, address, seq, streamid, creds) {
const getAudioStream = function getAudioStream (socket, address, seq, creds, streamid = 1) {
let url = `/audiostream.cgi?streamid=${streamid}&loginuse=${creds.user}&loginpas=${creds.pass}&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const getVideostream = function getVideostream (socket, address, seq, streamid, creds) {
const getVideoStream = function getVideoStream (socket, address, seq, creds, streamid = 10) {
let url = `/livestream.cgi?streamid=${streamid}&loginuse=${creds.user}&loginpas=${creds.pass}&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopAudioStream = function stopAudioStream (socket, address, seq, creds) {
let url = `/audiostream.cgi?streamid=16&loginuse=${creds.user}&loginpas=${creds.pass}&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopVideoStream = function stopVideoStream (socket, address, seq, creds) {
let url = `/livestream.cgi?streamid=16&loginuse=${creds.user}&loginpas=${creds.pass}&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const sendGet = function sendGet (socket, address, seq, url) {
let urlBuf = Buffer.from(url)
let payloadHead = Buffer.from([0xd1, 0x00, Math.floor(seq / 256), seq % 256, 0x01, 0x0a, 0x00, Math.floor((url.length + 4) / 256), (url.length + 4) % 256, 0x00, 0x00, 0x00, 0x47, 0x45, 0x54, 0x20])
Expand Down Expand Up @@ -170,6 +180,136 @@ const parseHttp = function parseHttp (msg, cb) {
cb({size: size, header: header, payload: payload})
}

const stepDown = function stepDown (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=2&onestep=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stepUp = function stepUp (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=0&onestep=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stepRight = function stepRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=6&onestep=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stepLeft = function stepLeft (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=4&onestep=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveDown = function moveDown (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=2&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveUp = function moveUp (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=0&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveRight = function moveRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=6&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveLeft = function moveLeft (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=4&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopMoveDown = function stopMoveDown (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=3&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopMoveUp = function stopMoveUp (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=1&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopMoveRight = function stopMoveRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=7&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopMoveLeft = function stopMoveLeft (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=5&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveDownRight = function moveDownRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=93&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveUpRight = function moveUpRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=91&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveUpLeft = function moveUpLeft (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=90&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const moveDownLeft = function moveDownLeft (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=92&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const stopMove = function stopMove (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=1&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const resetPosition = function resetPosition (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=25&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const upAndDown = function upAndDown (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=26&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const leftAndRight = function leftAndRight (socket, address, seq, creds) {
let url = `/decoder_control.cgi?command=28&onestep=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const reverseImage = function reverseImage (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=5&value=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const mirrorImage = function mirrorImage (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=5&value=2&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const resetImage = function resetImage (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=5&value=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const reverseAndMirrorImage = function reverseAndMirrorImage (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=5&value=3&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const activateInfrared = function activateInfrared (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=14&value=1&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

const deactivateInfrared = function deactivateInfrared (socket, address, seq, creds) {
let url = `/camera_control.cgi?param=14&value=0&user=${creds.user}&pwd=${creds.pass}&`
sendGet(socket, address, seq, url)
}

module.exports.openSession = openSession
module.exports.sendPing = sendPing
module.exports.sendPong = sendPong
Expand All @@ -180,11 +320,39 @@ module.exports.checkCredentials = checkCredentials
module.exports.sendMultipleGet = sendMultipleGet
module.exports.getParameters = getParameters
module.exports.getSnapshot = getSnapshot
module.exports.getAudiostream = getAudiostream
module.exports.getVideostream = getVideostream
module.exports.getAudioStream = getAudioStream
module.exports.getVideoStream = getVideoStream
module.exports.stopAudioStream = stopAudioStream
module.exports.stopVideoStream = stopVideoStream
module.exports.sendAuthenticatedGet = sendAuthenticatedGet
module.exports.getCameraParameters = getCameraParameters
module.exports.sendHttpAck = sendHttpAck
module.exports.sendAudioAck = sendAudioAck
module.exports.sendVideoAck = sendVideoAck
module.exports.parseHttp = parseHttp
module.exports.stepDown = stepDown
module.exports.stepUp = stepUp
module.exports.stepRight = stepRight
module.exports.stepLeft = stepLeft
module.exports.moveDown = moveDown
module.exports.moveUp = moveUp
module.exports.moveRight = moveRight
module.exports.moveLeft = moveLeft
module.exports.stopMoveDown = stopMoveDown
module.exports.stopMoveUp = stopMoveUp
module.exports.stopMoveRight = stopMoveRight
module.exports.stopMoveLeft = stopMoveLeft
module.exports.moveDownRight = moveDownRight
module.exports.moveUpRight = moveUpRight
module.exports.moveUpLeft = moveUpLeft
module.exports.moveDownLeft = moveDownLeft
module.exports.stopMove = stopMove
module.exports.resetPosition = resetPosition
module.exports.upAndDown = upAndDown
module.exports.leftAndRight = leftAndRight
module.exports.reverseImage = reverseImage
module.exports.mirrorImage = mirrorImage
module.exports.resetImage = resetImage
module.exports.reverseAndMirrorImage = reverseAndMirrorImage
module.exports.activateInfrared = activateInfrared
module.exports.deactivateInfrared = deactivateInfrared

0 comments on commit 0fd40ed

Please sign in to comment.