Debian Codegraph @

_examples/survey/index.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title></title>
6 <script type="text/javascript" src="https://cdn.jsdelivr.net/gh/centrifugal/centrifuge-js@master/dist/centrifuge.min.js"></script>
7 <script type="text/javascript">
8 window.addEventListener('load', function() {
9 const container = document.getElementById('messages');
10
11 function drawText(text) {
12 let e = document.createElement('li');
13 e.innerHTML = [(new Date()).toString(), ' ' + text].join(':');
14 container.insertBefore(e, container.firstChild);
15 }
16
17 const centrifuge = new Centrifuge('ws://' + window.location.host + '/connection/websocket');
18
19 // bind listeners on centrifuge object instance events.
20 centrifuge.on('connect', function(ctx){
21 drawText('Connected with client ID ' + ctx.client + ' over ' + ctx.transport);
22 });
23
24 centrifuge.on('disconnect', function(ctx){
25 drawText('Disconnected: ' + ctx.reason + (ctx.reconnect?", will try to reconnect":", won't try to reconnect"));
26 });
27
28 // Subscribe to different channels on different example ports.
29 centrifuge.subscribe(window.location.host);
30
31 centrifuge.connect();
32 });
33 </script>
34 </head>
35 <body>
36 <ul id="messages"></ul>
37 </body>
38 </html>