From 13aa5a4e2581e9f74c892c38dbf330fa0d6b7cc4 Mon Sep 17 00:00:00 2001 From: orel Date: Fri, 5 Feb 2021 16:58:55 +0100 Subject: [PATCH 1/2] Enhance jsclient-socket documentation --- docs/jsclientlib/socket.rst | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 925528490..7bffa2f54 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -64,12 +64,24 @@ 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 + Note that at the time of writing, OctoPrint only supports the ``throttle`` and ``auth`` messages. See also the :ref:`Push API documentation `. :param string type: Type of message to send :param object payload: Payload to send +.. js:function:: OctoPrintClient.socket.sendAuth(userId, session) + + Sends an ``auth`` message with the provided ``userId`` and ``session`` to the server. + + ``session`` is expected to be the ``session`` value retrieved + from any valid :ref:`OctoPrint.browser.login(userId,...) ` response. + + See also the :ref:`Push API documentation `. + + :param string userId: An existing OctoPrint username + :param string session: A valid session id for the provided username + .. js:function:: OctoPrintClient.socket.onRateTooLow(measured, minimum) Called by the socket client when the measured message round trip times have been lower than @@ -102,6 +114,17 @@ Instructs the server to decrease the message rate by 500ms. +Sample to setup an authed socket +================================ + +.. code-block:: javascript + + OctoPrint.socket.connect(); + OctoPrint.browser.login("myusername", "mypassword", true) + .done(function(response) { + client.socket.sendAuth("myusername", response.session); + }); + .. _sec-jsclient-socket-throttling: Communication Throttling From eddc288d9eb9ec9056d1e8f6f65dd9e8034b2dcc Mon Sep 17 00:00:00 2001 From: orel Date: Fri, 5 Feb 2021 17:05:04 +0100 Subject: [PATCH 2/2] Fix typo as there is no instanciated client in the sample... --- docs/jsclientlib/socket.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/jsclientlib/socket.rst b/docs/jsclientlib/socket.rst index 7bffa2f54..70b9bc5dc 100644 --- a/docs/jsclientlib/socket.rst +++ b/docs/jsclientlib/socket.rst @@ -122,7 +122,7 @@ Sample to setup an authed socket OctoPrint.socket.connect(); OctoPrint.browser.login("myusername", "mypassword", true) .done(function(response) { - client.socket.sendAuth("myusername", response.session); + OctoPrint.socket.sendAuth("myusername", response.session); }); .. _sec-jsclient-socket-throttling: