More work on JS Client documentation
This commit is contained in:
parent
12bc85694b
commit
a13e12bb5e
18 changed files with 530 additions and 24 deletions
|
|
@ -387,6 +387,30 @@ Issue a file command
|
|||
Upon success, a status code of :http:statuscode:`202` and a :ref:`sec-api-datamodel-files-fileabridged` in the response
|
||||
body will be returned.
|
||||
|
||||
copy
|
||||
Copies the file or folder to a new ``destination`` on the same ``location``. Additional parameters are:
|
||||
|
||||
* ``destination``: The path of the parent folder to which to copy the file or folder. It must already exist.
|
||||
|
||||
If there already exists a file or folder of the same name at ``destination``, the request will return a :http:statuscode:`409`.
|
||||
If the ``destination`` folder does not exist, a :http:statuscode:`404` will be returned.
|
||||
|
||||
Upon success, a status code of :http:statuscode:`201` and a :ref:`sec-api-datamodel-files-fileabridged` in the response
|
||||
body will be returned.
|
||||
|
||||
move
|
||||
Moves the file or folder to a new ``destination`` on the same ``location``. Additional parameters are:
|
||||
|
||||
* ``destination``: The path of the parent folder to which to move the file or folder.
|
||||
|
||||
If there already exists a file or folder of the same name at ``destination``, the request will return a :http:statuscode:`409`.
|
||||
If the ``destination`` folder does not exist, a :http:statuscode:`404` will be returned. If the ``path`` is currently
|
||||
in use by OctoPrint (e.g. it is a GCODE file that's currently being printed) a :http:statuscode:`409` will be
|
||||
returned.
|
||||
|
||||
Upon success, a status code of :http:statuscode:`201` and a :ref:`sec-api-datamodel-files-fileabridged` in the response
|
||||
body will be returned.
|
||||
|
||||
**Example Select Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
|
@ -441,6 +465,62 @@ Issue a file command
|
|||
}
|
||||
}
|
||||
|
||||
**Example Copy Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /api/files/local/some_folder/some_model.gcode HTTP/1.1
|
||||
Host: example.com
|
||||
Content-Type: application/json
|
||||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "copy",
|
||||
"destination": "some_other_folder/subfolder"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"origin": "local",
|
||||
"name": "some_model.gcode",
|
||||
"path": "some_other_folder/subfolder/some_model.gcode",
|
||||
"refs": {
|
||||
"download": "http://example.com/downloads/files/local/some_other_folder/subfolder/some_model.gcode",
|
||||
"resource": "http://example.com/api/files/local/some_other_folder/subfolder/some_model.gcode"
|
||||
}
|
||||
}
|
||||
|
||||
**Example Move Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /api/files/local/some_folder/and_a_subfolder HTTP/1.1
|
||||
Host: example.com
|
||||
Content-Type: application/json
|
||||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "move",
|
||||
"destination": "some_other_folder"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 201 Created
|
||||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"origin": "local",
|
||||
"name": "and_a_subfolder",
|
||||
"path": "some_other_folder/and_a_subfolder",
|
||||
"refs": {
|
||||
"resource": "http://example.com/api/files/local/some_other_folder/and_a_subfolder"
|
||||
}
|
||||
}
|
||||
|
||||
:param location: The target location on which to send the command for is located, either ``local`` (for OctoPrint's ``uploads``
|
||||
folder) or ``sdcard`` for the printer's SD card (if available)
|
||||
|
|
|
|||
|
|
@ -27,17 +27,21 @@ Each pushed message consists of a simple JSON object that follows this basic str
|
|||
``type`` indicates the type of message being pushed to the client, the attached ``payload`` is message specific. The
|
||||
following message types are currently available for usage by 3rd party clients:
|
||||
|
||||
* ``connected``: Initial connection information, sent only right after establishing the socket connection. See
|
||||
:ref:`the payload data model <sec-api-push-datamodel-connected>`.
|
||||
* ``current``: Rate limited general state update, payload contains information about the printer's state, job progress,
|
||||
accumulated temperature points and log lines since last update. OctoPrint will send these updates when new information
|
||||
is available, but not more often than twice per second in order to not flood the client with messages (e.g.
|
||||
during printing). See :ref:`the payload data model <sec-api-push-datamodel-currentandhistory>`.
|
||||
* ``history``: Current state, temperature and log history, sent upon initial connect to get the client up to date. Same
|
||||
payload data model as ``current``, see :ref:`below <sec-api-push-datamodel-currentandhistory>`.
|
||||
payload data model as ``current``, see :ref:`the payload data model <sec-api-push-datamodel-currentandhistory>`.
|
||||
* ``event``: Events triggered within OctoPrint, such as e.g. ``PrintFailed`` or ``MovieRenderDone``. Payload is the event
|
||||
type and payload, see :ref:`below <sec-api-push-datamodel-event>`. Sent when an event is triggered internally.
|
||||
type and payload, see :ref:`the payload data model <sec-api-push-datamodel-event>`. Sent when an event is triggered internally.
|
||||
* ``slicingProgress``: Progress updates from an active slicing background job, payload contains information about the
|
||||
model being sliced, the target file, the slicer being used and the progress as a percentage.
|
||||
See :ref:`the payload data model <sec-api-push-datamodel-slicingprogress>`.
|
||||
* ``plugin``: Messages generated by plugins. The payload data models are determined by the plugin which sent the
|
||||
message.
|
||||
|
||||
Clients must ignore any unknown messages.
|
||||
|
||||
|
|
@ -66,6 +70,48 @@ Example for a ``throttle`` client-server-message:
|
|||
Datamodel
|
||||
=========
|
||||
|
||||
.. _sec-api-push-datamodel-connected:
|
||||
|
||||
``connected`` payload
|
||||
---------------------
|
||||
|
||||
.. list-table::
|
||||
:widths: 15 5 10 30
|
||||
:header-rows: 1
|
||||
|
||||
* - Name
|
||||
- Multiplicity
|
||||
- Type
|
||||
- Description
|
||||
* - ``apikey``
|
||||
- 1
|
||||
- String
|
||||
- Current UI API KEY. The UI API KEY is a special API key that gets regenerated on every server restart and
|
||||
has no rights attached other than accessing the REST API. An additional browser session is needed to
|
||||
send valid requests when the UI API KEY is used.
|
||||
* - ``version``
|
||||
- 1
|
||||
- String
|
||||
- The server's version.
|
||||
* - ``branch``
|
||||
- 1
|
||||
- String
|
||||
- The source code branch from which the server was built.
|
||||
* - ``display_version``
|
||||
- 1
|
||||
- String
|
||||
- The server's version and branch in a human readable format.
|
||||
* - ``plugin_hash``
|
||||
- 1
|
||||
- String
|
||||
- A hash of all installed plugins. This allows to detect if there have been plugin changes between server
|
||||
restarts.
|
||||
* - ``config_hash``
|
||||
- 1
|
||||
- String
|
||||
- A hash of the currently active config. This allows to detect if there have been configuration changes between
|
||||
server restarts.
|
||||
|
||||
.. _sec-api-push-datamodel-currentandhistory:
|
||||
|
||||
``current`` and ``history`` payload
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ Setting up a Development environment
|
|||
Obtaining, building and running the source
|
||||
------------------------------------------
|
||||
|
||||
These describes the general steps in obtaining, building and running. OS specific instructions can be found
|
||||
This describes the general steps in obtaining, building and running. OS specific instructions can be found
|
||||
below.
|
||||
|
||||
* Prerequisites:
|
||||
|
|
@ -115,7 +115,7 @@ Mac OS X
|
|||
This guide is based on the `Setup Guide for Mac OS X on OctoPrint's wiki <https://github.com/foosel/OctoPrint/wiki/Setup-on-Mac/>`_.
|
||||
Please report back if it works for you, due to lack of access to a Mac I cannot test it myself. Thanks.
|
||||
|
||||
This assumes you'll host your OctoPrint development checkout at ``C:\Devel\OctoPrint``. If you want to use a different
|
||||
This assumes you'll host your OctoPrint development checkout at ``~/devel/OctoPrint``. If you want to use a different
|
||||
location, please substitute accordingly.
|
||||
|
||||
You'll need a user account with administrator privileges.
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@
|
|||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.select(location, filename, print, opts)
|
||||
.. js:function:: OctoPrint.files.select(location, path, print, opts)
|
||||
|
||||
Selects a file at ``location`` named ``filename`` for printing. If ``print`` is supplied and
|
||||
truthy, also starts printing the file immediately.
|
||||
|
|
@ -81,58 +81,95 @@
|
|||
See the ``select`` command in :ref:`Issue a file command <sec-api-fileops-filecommand>` for more details.
|
||||
|
||||
:param string location: The location of the file to select
|
||||
:param string filename: The name of the file to select
|
||||
:param string path: The name of the file to select
|
||||
:param boolean print: Whether to print the file after selection (true) or not (false, default)
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.slice(location, filename, parameters, opts)
|
||||
.. js:function:: OctoPrint.files.slice(location, path, parameters, opts)
|
||||
|
||||
Slices a file at ``location`` called ``filename``, using the supplied slice command ``parameters``.
|
||||
|
||||
See the ``slice`` command in :ref:`Issue a file command <sec-api-fileops-filecommand>` for more details.
|
||||
|
||||
:param string location: The location of the file to slice
|
||||
:param string filename: The name of the file to slice
|
||||
:param string path: The path of the file to slice
|
||||
:param object parameters: Additional parameters for the ``slice`` command
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.delete(location, filename, opts)
|
||||
.. js:function:: OctoPrint.files.delete(location, path, opts)
|
||||
|
||||
Deletes the file at ``location`` named ``filename``.
|
||||
Deletes the file or folder at ``location`` and ``path``.
|
||||
|
||||
See :ref:`Delete file <sec-api-fileops-delete>` for more details.
|
||||
|
||||
:param string location: The location of the file to delete
|
||||
:param string filename: The name of the file to delete
|
||||
:param string path: The path of the file to delete
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.copy(location, filename, destination, opts)
|
||||
.. js:function:: OctoPrint.files.copy(location, path, destination, opts)
|
||||
|
||||
.. todo::
|
||||
Copies file or folder ``path`` on ``location`` to new parent folder ``destination`` on ``location``.
|
||||
|
||||
Also needs API documentation.
|
||||
``destination`` must already exist.
|
||||
|
||||
**Example:**
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
OctoPrint.files.copy("local", "some/file.gco", "other/folder");
|
||||
|
||||
See :ref:`Issue a file command <sec-api-fileops-filecommand>` for more details.
|
||||
|
||||
:param string location: The location of the file to copy, currently only "local" is supported
|
||||
:param string path: The path of the file or folder to copy
|
||||
:param string destination: The path of the parent to which to copy the file or folder
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.move(location, filename, destination, opts)
|
||||
|
||||
.. todo::
|
||||
Moves file or folder ``path`` on ``location`` to new parent folder ``destination`` on ``location``.
|
||||
|
||||
Also needs API documentation.
|
||||
``destination`` must already exist.
|
||||
|
||||
**Example:**
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
OctoPrint.files.move("local", "some/file.gco", "other/folder");
|
||||
|
||||
See :ref:`Issue a file command <sec-api-fileops-filecommand>` for more details.
|
||||
|
||||
:param string location: The location of the file to move, currently only "local" is supported
|
||||
:param string path: The path of the file or folder to move
|
||||
:param string destination: The path of the parent to which to copy the file or folder
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.createFolder(location, name, path, opts)
|
||||
|
||||
.. todo::
|
||||
Creates a new folder ``name`` on ``location``. If ``path`` is provided and not empty the folder
|
||||
will be created as a new child of it.
|
||||
|
||||
Also needs API documentation.
|
||||
**Example:**
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
// creates new folder "folder" in the root of "local"
|
||||
OctoPrint.files.createFolder("local", "folder");
|
||||
|
||||
// creates new folder "subfolder" in parent "some/existing/folder" on "local"
|
||||
OctoPrint.files.createFolder("local", "subfolder", "some/existing/folder");
|
||||
|
||||
See :ref:`Upload file or create folder <sec-api-fileops-uploadfile>` for more details on the folder creation API.
|
||||
|
||||
:param string location: The location to create the folder on (currently only "local" is supported)
|
||||
:param string name: The name of the new folder
|
||||
:param string path: The path to the parent folder in which to create the new folder. May be left unset in which
|
||||
case the folder will be created in the root directory of ``location``.
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
|
|
@ -155,12 +192,12 @@
|
|||
An optional object or a serialized JSON string of additional user supplised data to associate with
|
||||
the uploaded file.
|
||||
|
||||
See :ref:`Upload file <sec-api-fileops-uploadfile>` for more details on the file upload API and
|
||||
See :ref:`Upload file or create folder <sec-api-fileops-uploadfile>` for more details on the file upload API and
|
||||
:js:func:`OctoPrint.upload` for more details on the underlying library upload mechanism, including
|
||||
what values are accepted for the ``file`` parameter.
|
||||
|
||||
:param string location: The location to upload the file to
|
||||
:param object or string file: The file to upload, either a
|
||||
:param object or string file: The file to upload, see :js:func:`OctoPrint.upload` for more details
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.files.download(location, path, opts)
|
||||
|
|
|
|||
|
|
@ -16,3 +16,12 @@ JavaScript Client Library
|
|||
languages.rst
|
||||
logs.rst
|
||||
printer.rst
|
||||
printerprofiles.rst
|
||||
settings.rst
|
||||
slicing.rst
|
||||
socket.rst
|
||||
system.rst
|
||||
timelapse.rst
|
||||
users.rst
|
||||
util.rst
|
||||
wizard.rst
|
||||
|
|
|
|||
|
|
@ -7,12 +7,29 @@
|
|||
|
||||
Retrieves information about the current job.
|
||||
|
||||
See :ref:`Retrieve information about the current job <sec-api-job-information>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.start(opts)
|
||||
|
||||
Starts the current job.
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.cancel(opts)
|
||||
|
||||
Cancels the current job.
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.restart(opts)
|
||||
|
||||
Restarts the current job. This is equivalent to cancelling and immediately restarting
|
||||
|
|
@ -31,15 +48,35 @@
|
|||
OctoPrint.job.start();
|
||||
});
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.pause(opts)
|
||||
|
||||
Pauses the current job if it's running, does nothing if it's already paused.
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.resume(opts)
|
||||
|
||||
Resumes the current job if it's currently pause, does nothing if it's running.
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.job.togglePause(opts)
|
||||
|
||||
Resumes a paused job and pauses a running a print.
|
||||
Resumes a paused and pauses a running job.
|
||||
|
||||
See :ref:`Issue a job command <sec-api-jobs-command>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,12 @@
|
|||
|
||||
.. js:function:: OctoPrint.languages.list(opts)
|
||||
|
||||
Retrieves a list of available language packs.
|
||||
|
||||
.. js:function:: OctoPrint.languages.upload(file)
|
||||
|
||||
Uploads a language pack.
|
||||
|
||||
.. js:function:: OctoPrint.languages.delete(locale, pack, opts)
|
||||
|
||||
Deletes the language pack ``pack`` for the specified locale ``locale``.
|
||||
|
|
|
|||
|
|
@ -3,8 +3,37 @@
|
|||
:mod:`OctoPrint.logs`
|
||||
---------------------
|
||||
|
||||
.. note::
|
||||
|
||||
All methods here require that the used API token or a the existing browser session
|
||||
has admin rights.
|
||||
|
||||
.. js:function:: OctoPrint.logs.list(opts)
|
||||
|
||||
.. js:function:: OctoPrint.logs.delete(opts)
|
||||
Retrieves a list of log files.
|
||||
|
||||
See :ref:`Retrieve a list of available log files <sec-api-logs-list>` for details.
|
||||
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.logs.delete(path, opts)
|
||||
|
||||
Deletes the specified log ``path``.
|
||||
|
||||
See :ref:`Delete a specific log file <sec-api-logs-delete>` for details.
|
||||
|
||||
:param string path: The path to the log file to delete
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.logs.download(path, opts)
|
||||
|
||||
Downloads the specified log ``file``.
|
||||
|
||||
See :js:func:`OctoPrint.download` for more details on the underlying library download mechanism.
|
||||
|
||||
:param string path: The path to the log file to download
|
||||
:param object opts: Additional options for the request
|
||||
:returns Promise: A `jQuery Promise <http://api.jquery.com/Types/#Promise>`_ for the request's response
|
||||
|
||||
.. js:function:: OctoPrint.logs.download(file, opts)
|
||||
|
|
|
|||
18
docs/jsclientlib/printerprofiles.rst
Normal file
18
docs/jsclientlib/printerprofiles.rst
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
.. sec-jsclientlib-printerprofiles:
|
||||
|
||||
:mod:`OctoPrint.printerprofiles`
|
||||
--------------------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.printerprofiles.list(opts)
|
||||
|
||||
.. js:function:: OctoPrint.printerprofiles.get(id, opts)
|
||||
|
||||
.. js:function:: OctoPrint.printerprofiles.add(profile, additional, opts)
|
||||
|
||||
.. js:function:: OctoPrint.printerprofiles.update(id, profile, additional, opts)
|
||||
|
||||
.. js:function:: OctoPrint.printerprofiles.delete(id, opts)
|
||||
16
docs/jsclientlib/settings.rst
Normal file
16
docs/jsclientlib/settings.rst
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
.. sec-jsclientlib-settings:
|
||||
|
||||
:mod:`OctoPrint.settings`
|
||||
-------------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.settings.get(opts)
|
||||
|
||||
.. js:function:: OctoPrint.settings.save(settings, opts)
|
||||
|
||||
.. js:function:: OctoPrint.settings.getPluginSettings(plugin, opts)
|
||||
|
||||
.. js:function:: OctoPrint.settings.savePluginSettings(plugin, settings, opts)
|
||||
20
docs/jsclientlib/slicing.rst
Normal file
20
docs/jsclientlib/slicing.rst
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
.. sec-jsclientlib-slicing:
|
||||
|
||||
:mod:`OctoPrint.slicing`
|
||||
------------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.slicing.listAllSlicersAndProfiles(opts)
|
||||
|
||||
.. js:function:: OctoPrint.slicing.listProfilesForSlicer(slicer, opts)
|
||||
|
||||
.. js:function:: OctoPrint.slicing.getProfileForSlicer(slicer, profileId, opts)
|
||||
|
||||
.. js:function:: OctoPrint.slicing.addProfileForSlicer(slicer, profileId, profile, opts)
|
||||
|
||||
.. js:function:: OctoPrint.slicing.updateProfileForSlicer(slicer, profileId, profile, opts)
|
||||
|
||||
.. js:function:: OctoPrint.slicing.deleteProfileForSlicer(slicer, profileId, opts)
|
||||
114
docs/jsclientlib/socket.rst
Normal file
114
docs/jsclientlib/socket.rst
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
.. sec-jsclientlib-socket:
|
||||
|
||||
:mod:`OctoPrint.socket`
|
||||
-----------------------
|
||||
|
||||
.. js:data:: OctoPrint.socket.options
|
||||
|
||||
The socket client's options.
|
||||
|
||||
``OctoPrint.socket.options.timeouts``
|
||||
A list of consecutive timeouts after which to attempt reconnecting to a
|
||||
disconnected sockets, in seconds. Defaults to ``[1, 1, 2, 3, 5, 8, 13, 20, 40, 100]``.
|
||||
The default setting here makes the client slowly back off after the first couple of very
|
||||
fast connection attempts don't succeed, and give up after 10 tries.
|
||||
|
||||
``OctoPrint.socket.options.rateSlidingWindowSize``
|
||||
Number of last rate measurements to take into account for timing analysis and
|
||||
communication throttling. See :ref:`Communication Throttling <sec-jsclient-socket-throttling>`
|
||||
below.
|
||||
|
||||
.. js:function:: OctoPrint.socket.connect(opts)
|
||||
|
||||
Connects the socket client to OctoPrint's `SockJS <http://sockjs.org/>`_ socket.
|
||||
|
||||
The optional parameter ``opts`` may be used to provide additional configuration options
|
||||
to the SockJS constructor. See the `SockJS documentation <https://github.com/sockjs/sockjs-client#sockjs-class>`_ on potential options.
|
||||
|
||||
:param object opts: Additional options for the SockJS constructor.
|
||||
|
||||
.. js:function:: OctoPrint.socket.reconnect()
|
||||
|
||||
Reconnects the socket client. If the socket is currently connected it will be disconnected first.
|
||||
|
||||
.. js:function:: OctoPrint.socket.disconnect()
|
||||
|
||||
Disconnects the socket client.
|
||||
|
||||
.. js:function:: OctoPrint.socket.onMessage(message, handler)
|
||||
|
||||
Registers the ``handler`` for messages of type ``message``.
|
||||
|
||||
To register for all message types, provide ``*`` as the type to register for.
|
||||
|
||||
``handler`` is expected to be a function accepting one object parameter ``eventObj``, consisting
|
||||
of the received message as property ``key`` and the received payload (if any) as property ``data``.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
OctoPrint.socket.onMessage("*", function(message) {
|
||||
// do something with the message object
|
||||
});
|
||||
|
||||
The socket client will measure how long message processing over all handlers will take and utilize
|
||||
that measurement to determine if the :ref:`communication throttling <sec-jsclient-socket-throttling>`
|
||||
needs to be adjusted or not.
|
||||
|
||||
Please refer to the :ref:`Push API documentation <sec-api-push>`
|
||||
for details on the possible message types and their payloads.
|
||||
|
||||
:param string message: The type of message for which to register
|
||||
:param function handler: The handler function
|
||||
|
||||
.. js:function:: OctoPrint.socket.sendMessage(type, payload)
|
||||
|
||||
Sends a message of type ``type`` with the provided ``payload`` to the server.
|
||||
|
||||
Note that at the time of writing, OctoPrint only supports the ``throttle`` message. See
|
||||
also the :ref:`Push API documentation <sec-api-push>`.
|
||||
|
||||
:param string type: Type of message to send
|
||||
:param object payload: Payload to send
|
||||
|
||||
.. js:function:: OctoPrint.socket.onRateTooLow(measured, minimum)
|
||||
|
||||
Called by the socket client when the measured message round trip times have been lower than
|
||||
the current lower processing limit over the full sliding window, indicating that messages
|
||||
are now processed faster than the current rate and a faster rate might be possible.
|
||||
|
||||
Can be overwritten with custom handler methods. The default implementation will call
|
||||
:js:func:`OctoPrint.socket.increaseRate`.
|
||||
|
||||
:param Number measured: Maximal measured message round trip time
|
||||
:param Number minimum: Lower round trip time limit for keeping the rate
|
||||
|
||||
.. js:function:: OctoPrint.socket.onRateTooHigh(measured, maximum)
|
||||
|
||||
Called by the socket client when the last measured round trip time was higher than the
|
||||
current upper procesisng limit, indicating that the messages are now processed slower than
|
||||
the current rate requires and a slower rate might be necessary.
|
||||
|
||||
Can be overwritten with custom handler methods. The default implementation will call
|
||||
:js:func:`OctoPrint.socket.decreaseRate`.
|
||||
|
||||
:param Number measured: Measured message round trip time
|
||||
:param Number minimum: Upper round trip time limit for keeping the rate
|
||||
|
||||
.. js:function:: OctoPrint.socket.increaseRate()
|
||||
|
||||
Instructs the server to increase the message rate by 500ms.
|
||||
|
||||
.. js:function:: OctoPrint.socket.decreaseRate()
|
||||
|
||||
Instructs the server to decrease the message rate by 500ms.
|
||||
|
||||
.. sec-jsclient-socket-throttling:
|
||||
|
||||
Communication Throttling
|
||||
========================
|
||||
|
||||
The socket client supports communication throttling. It will measure how long each incoming message takes
|
||||
to be processed by all registered handlers. If the processing times in a sliding window are longer than
|
||||
the current rate limit configured on the socket (default: 500ms between messages), the socket client will
|
||||
instruct the server to send slower. If the messages are handled faster than half the current rate limit,
|
||||
the socket client will instruct the server to send faster.
|
||||
14
docs/jsclientlib/system.rst
Normal file
14
docs/jsclientlib/system.rst
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
.. sec-jsclientlib-system:
|
||||
|
||||
:mod:`OctoPrint.system`
|
||||
-----------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.system.getCommands(opts)
|
||||
|
||||
.. js:function:: OctoPrint.system.getCommandsForSource(source, opts)
|
||||
|
||||
.. js:function:: OctoPrint.system.executeCommand(source, action, opts)
|
||||
24
docs/jsclientlib/timelapse.rst
Normal file
24
docs/jsclientlib/timelapse.rst
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
.. sec-jsclientlib-timelapse:
|
||||
|
||||
:mod:`OctoPrint.timelapse`
|
||||
--------------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.timelapse.get(opts)
|
||||
|
||||
.. js:function:: OctoPrint.timelapse.list(opts)
|
||||
|
||||
.. js:function:: OctoPrint.download(filename, opts)
|
||||
|
||||
.. js:function:: OctoPrint.delete(filename, opts)
|
||||
|
||||
.. js:function:: OctoPrint.deleteUnrendered(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.renderUnrendered(name, opts)
|
||||
|
||||
.. js:function:: getConfig(opts)
|
||||
|
||||
.. js:function:: saveConfig(config, opts)
|
||||
28
docs/jsclientlib/users.rst
Normal file
28
docs/jsclientlib/users.rst
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
.. sec-jsclientlib-users:
|
||||
|
||||
:mod:`OctoPrint.users`
|
||||
----------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.users.list(opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.get(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.add(user, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.update(name, active, admin, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.delete(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.changePassword(name, password, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.generateApiKey(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.resetApiKey(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.getSettings(name, opts)
|
||||
|
||||
.. js:function:: OctoPrint.users.saveSettings(name, settings, opts)
|
||||
16
docs/jsclientlib/util.rst
Normal file
16
docs/jsclientlib/util.rst
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
.. sec-jsclientlib-util:
|
||||
|
||||
:mod:`OctoPrint.util`
|
||||
---------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.util.test(command, data, opts)
|
||||
|
||||
.. js:function:: OctoPrint.util.testPath(path, additional, opts)
|
||||
|
||||
.. js:function:: OctoPrint.util.testExecutable(path, additional, opts)
|
||||
|
||||
.. js:function:: OctoPrint.util.testUrl(url, additional, opts)
|
||||
12
docs/jsclientlib/wizard.rst
Normal file
12
docs/jsclientlib/wizard.rst
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
.. sec-jsclientlib-wizard:
|
||||
|
||||
:mod:`OctoPrint.wizard`
|
||||
-----------------------
|
||||
|
||||
.. todo::
|
||||
|
||||
Needs to be documented
|
||||
|
||||
.. js:function:: OctoPrint.wizard.get(opts)
|
||||
|
||||
.. js:function:: OctoPrint.wizard.finish(handled, opts)
|
||||
|
|
@ -64,7 +64,7 @@
|
|||
var catchAllHandlers = registeredHandlers["*"];
|
||||
if (catchAllHandlers && catchAllHandlers.length) {
|
||||
_.each(catchAllHandlers, function(handler) {
|
||||
handler({event: eventObj})
|
||||
handler(eventObj);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue