message.html.twig 840 Bytes
Newer Older
Mat's avatar
Mat committed
1 2 3
{% extends "base.html.twig" %}

{% block layout %}
4 5 6 7 8 9 10 11 12 13
<section style="margin: 2em;">

    <h5>
        Hello World!
    </h5>

    <input id="message" type="text">
    <button id="send">Envoyer</button>

</section>
Mat's avatar
Mat committed
14 15
{% endblock %}

16 17 18 19 20 21 22 23 24 25 26 27
{% block javascripts %}
    <script>

        // pas nécessaire en ECMAscript 6
        //"use strict"; // une sécurité, oblige à écrire correctement le javascript

        $(document).ready(function() {

            let connection = new WebSocket('ws://0.0.0.0:8088/');

            connection.onopen = function(e)
            {
28 29
                let message = $('#message').val();
                connection.send(message);
30 31 32 33
            };

            connection.onmessage = function(e)
            {
Mat's avatar
Mat committed
34
                console.log(JSON.parse(e.data));
35 36 37 38 39 40
            };

        });
    </script>
{% endblock %}