aboutsummaryrefslogtreecommitdiffstats
path: root/templates/main/ws_test_rst.html
blob: a0bae79bd011c3a406c4a9249e9428803f68b6ac (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{% extends "main/base.html" %}
{% block title %}WS Test{% endblock %}
{% block og_title %}WS Test{% endblock %}
{% block og_description %}A test page for our Websockets implementation{% endblock %}
{% block content %}
    <div class="uk-container uk-section">
        <h1>Enter some text to test.</h1>

        <textarea title="RST Input" id="rst"></textarea>
        <input type="button" value="Submit" id="submit-button" />

        <br />

        <div id="output"></div>

        <script type="application/javascript">
            let ws = new WebSocket("wss://api.{{ server_name }}/ws/rst");

            ws.onopen = function(event) {
                console.log("WS opened! Use send() to send a message.");
            };

            ws.onmessage = function (event) {
                document.getElementById("output").innerHTML = event.data;
            };

            function send(text) {
                console.log("-> " + text);
                ws.send(text);
            }

            document.getElementById("submit-button").onclick = function() {
                send(
                    document.getElementById("rst").value
                );
            }
        </script>
    </div>
{% endblock %}