|
| 1 | +JS API: Camera Integration |
| 2 | +========================== |
| 3 | + |
| 4 | +.. code-block:: html |
| 5 | + |
| 6 | + <script src="/networktables/camera.js"></script> |
| 7 | + |
| 8 | +.. note:: These functions require `jQuery <http://jquery.com/>`_ to be |
| 9 | + loaded first! |
| 10 | + |
| 11 | +.. js:function:: loadCameraOnConnect(args) |
| 12 | + |
| 13 | + This useful helper function will create an img or svg element inside of the |
| 14 | + div element that you specify. The image will only be connected when a |
| 15 | + successful NetworkTables connection is detected, to prevent timeout issues. |
| 16 | + Additionally, this function will attempt to verify that the webcam server is |
| 17 | + actually up and running before creating the image. |
| 18 | + |
| 19 | + You should provide an object with an object that can have the following |
| 20 | + attributes: |
| 21 | + |
| 22 | + :param container: Where to draw things |
| 23 | + :param proto: optional, defaults to http:// |
| 24 | + :param host: optional, if null will use robot's autodetected IP |
| 25 | + :param port: optional, webserver port |
| 26 | + :param image_url: path to mjpg stream |
| 27 | + :param data_url: a file or page that must exist on the webcam server |
| 28 | + :param wait_img: optional image to show when not connected |
| 29 | + :param error_img: optional image to show when not connected |
| 30 | + :param attrs: optional attributes to set on svg or img element |
| 31 | + :param nosim: if true, connect to the webcam in simulation mode |
| 32 | + |
| 33 | + For example, to connect to mjpg-streamer on the RoboRIO: |
| 34 | + |
| 35 | + .. code-block:: javascript |
| 36 | +
|
| 37 | + loadCameraOnConnect({ |
| 38 | + container: '#my_div_element', |
| 39 | + port: 5800, |
| 40 | + image_url: '/?action=stream', |
| 41 | + data_url: '/program.json', |
| 42 | + attrs: { |
| 43 | + width: 640, |
| 44 | + height: 480 |
| 45 | + } |
| 46 | + }); |
| 47 | +
|
| 48 | +
|
| 49 | + .. note:: This has only been tested with mjpg-streamer, but should work for |
| 50 | + other HTTP webcams as well. |
0 commit comments