diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 95ebf4d..3424948 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -132,7 +132,9 @@ Let's test it! Run ``runserver``, open a browser, navigate to a page on the serv (you can't use any page's console because of origin restrictions), and put the following into the JavaScript console to open a WebSocket and send some data down it (you might need to change the socket address if you're using a -development VM or similar):: +development VM or similar) + +.. code-block:: javascript // Note that the path doesn't matter for routing; any WebSocket // connection gets bumped over to WebSocket consumers @@ -246,7 +248,9 @@ views. With all that code, you now have a working set of a logic for a chat server. Test time! Run ``runserver``, open a browser and use that same JavaScript -code in the developer console as before:: +code in the developer console as before + +.. code-block:: javascript // Note that the path doesn't matter right now; any WebSocket // connection gets bumped over to WebSocket consumers @@ -508,7 +512,9 @@ chat to people with the same first letter of their username:: If you're just using ``runserver`` (and so Daphne), you can just connect and your cookies should transfer your auth over. If you were running WebSockets on a separate domain, you'd have to remember to provide the -Django session ID as part of the URL, like this:: +Django session ID as part of the URL, like this + +.. code-block:: javascript socket = new WebSocket("ws://127.0.0.1:9000/?session_key=abcdefg"); diff --git a/docs/javascript.rst b/docs/javascript.rst index b7e2f67..488a4c3 100644 --- a/docs/javascript.rst +++ b/docs/javascript.rst @@ -20,7 +20,9 @@ The library is deliberately quite low-level and generic; it's designed to be compatible with any JavaScript code or framework, so you can build more specific integration on top of it. -To process messages:: +To process messages + +.. code-block:: javascript const webSocketBridge = new channels.WebSocketBridge(); webSocketBridge.connect('/ws/'); @@ -28,11 +30,15 @@ To process messages:: console.log(action, stream); }); -To send messages, use the `send` method:: +To send messages, use the `send` method + +.. code-block:: javascript webSocketBridge.send({prop1: 'value1', prop2: 'value1'}); -To demultiplex specific streams:: +To demultiplex specific streams + +.. code-block:: javascript webSocketBridge.connect(); webSocketBridge.listen('/ws/'); @@ -43,11 +49,15 @@ To demultiplex specific streams:: console.info(action, stream); }); -To send a message to a specific stream:: +To send a message to a specific stream + +.. code-block:: javascript webSocketBridge.stream('mystream').send({prop1: 'value1', prop2: 'value1'}) -The `WebSocketBridge` instance exposes the underlaying `ReconnectingWebSocket` as the `socket` property. You can use this property to add any custom behavior. For example:: +The `WebSocketBridge` instance exposes the underlaying `ReconnectingWebSocket` as the `socket` property. You can use this property to add any custom behavior. For example + +.. code-block:: javascript webSocketBridge.socket.addEventListener('open', function() { console.log("Connected to WebSocket");