Austin Schuh | 24adb6b | 2015-09-06 17:37:40 -0700 | [diff] [blame^] | 1 | var ws; |
| 2 | |
| 3 | $(function() { |
| 4 | ws = new WebSocket('ws://' + document.location.host + '/ws'); |
| 5 | ws.onopen = function() { |
| 6 | console.log('onopen'); |
| 7 | }; |
| 8 | ws.onclose = function() { |
| 9 | $('#message').text('Lost connection.'); |
| 10 | console.log('onclose'); |
| 11 | }; |
| 12 | ws.onmessage = function(message) { |
| 13 | console.log("got '" + message.data + "'"); |
| 14 | eval(message.data); |
| 15 | }; |
| 16 | ws.onerror = function(error) { |
| 17 | console.log('onerror ' + error); |
| 18 | console.log(error); |
| 19 | }; |
| 20 | $('#count').click(function() { |
| 21 | ws.send($('#count').val()); |
| 22 | }); |
| 23 | $('#close').click(function() { |
| 24 | ws.send('close'); |
| 25 | }); |
| 26 | $('#die').click(function() { |
| 27 | ws.send('die'); |
| 28 | }); |
| 29 | }); |
| 30 | |
| 31 | set = function(value) { |
| 32 | $('#count').val(value) |
| 33 | } |