123456789101112131415161718192021222324252627 |
- function get_url()
- {
- var url = "";
- if(window.location.protocol == "http:") {
- url += "ws://"
- } else {
- url = "wss://"
- }
- url += window.location.host + '/v1/ws/counter/';
- url += document.getElementsByTagName('body')[0].dataset.cid;
- return url;
- }
- function do_websocket()
- {
- const socket = new WebSocket(get_url());
- socket.onmessage = function(evt) {
- var msg = JSON.parse(evt.data)
- counter = document.getElementsByTagName('text')[0];
- counter.textContent = msg.value.toString()
- }
- socket.onclose = function() {
- setTimeout(do_websocket, 3000)
- }
- socket.onerror = socket.onclose
- }
- do_websocket()
|