JavaScript API

From ElphelWiki
Revision as of 11:07, 19 November 2005 by Zimbatm (talk | contribs) (Api)
Jump to: navigation, search

in English | [[{{{de}}}|deutsch]] | [[{{{fr}}}|français]] | по-русски | автоперевод | 中文版 | 机械翻译


This work is under development

Authors : Khlut, zimbatm

The javascript library is intended to be used in different environments. The usage scenarios are HTML interfaces, which can easily be extended with the library. Interfaces can also be created, by using a simple extension syntax.

Goals

  • Easy to embed in existing HTML
  • Auto-configurable
  • HTML generation

Essay

Configuration

The configuration of a camera goes through a new object's creation.

The object automatically retrieves the data using asyncronous Http requests. Optionally, you can provide the data trough an object to avoid too much queries.

Example:

camera = new Camera('http://192.168.1.3')

alert(camera.model_name()) // fetches the data and returns it, the value gets cached

camera2 = new Camera('http://zimba:1234@192.168.1.3', {
  api: Api.Axis,
  model_name: '203'})

alert(camera.model_name()) // returns the data directly

Api

We need a way to make the lib compatible with the different apis and api versions.

Some implementation ideas :


if (camera.ptz) { // if the function is defined
  document.getElementById('ptz_control').innerHTML = (new Template.Ptz(camera)).source()
}

HTML Generation


Template.Image = function(camera_source) {
  this.template = '<img src="'+camera_source+'" />'
}
Template.prototype = new Template()

image = new Template(camera.picture_path())

document.getElementById('some_element').innerHTML = image.source()