Client to get sequential images from URL and take snapshots with auth basic support.
Using the standard tag, we are unable to include authentication (e.g. http://user:pass@ip:port/path), if necessary, due to browser limitations.
To solve this problem we adapted this client, enabling continuous frame request, emulating stream playback for cameras that only have snapshot feature.
New features and bugfixes will be available here, which also supports MJPEG streams.
Add the jpeg.js script to your HTML page:
<script src="jpeg.js"></script>
Create the player and set connection parameters/events as needed:
var player = new JPEG.Player("player", "http://<address>:<port>/<path>", "<username>", "<password>", {onError: onErr, onStart: onStarted, onStop: onStopped});
Parameters available:
- container element
- URL
- Username (optional)
- Password (optional)
- Options
- Image class
- Image alternative text
- Image title
- Timeout (in ms)
- Refresh Rate
- Events (see below)
- start()
- stop()
- snapshot()
Start sequential capture:
var player = new JPEG.Player("player", "http://<address>:<port>/<path>", "<username>", "<password>", {onStart: onStarted});
player.start();
Stop sequential capture or abort current connection:
var player = new JPEG.Player("player", "http://<address>:<port>/<path>", "<username>", "<password>", {onStop: onStopped});
player.stop();
Take snapshot:
var player = new JPEG.Player("player", "http://<address>:<port>/<path>", "<username>", "<password>", {onError: onErr, onStart: onStarted, onStop: onStopped});
player.snapshot();
Events are assigned at object creation:
- onStart
- onStop
- onError(JSON)
- JSON: Displays the returned status code and request body text.
- onFrame
- event: Event triggered by onload.
function onErr(text) {
console.error(text);
player.stop();
}
function onStarted() {
console.log('Started');
}
function onStopped() {
console.warn('Stopped');
}
function onFrame(e) {
e.preventDefault();
e.stopPropagation();
console.log('New frame',e);
}