Comran Morshed | fe7f9ea | 2015-02-19 23:52:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | From Seasocks version 1.1.2, under /src/ws_test_web |
| 3 | |
| 4 | Copyright (c) 2013, Matt Godbolt |
| 5 | All rights reserved. |
| 6 | |
| 7 | Redistribution and use in source and binary forms, with or without |
| 8 | modification, are permitted provided that the following conditions are met: |
| 9 | |
| 10 | Redistributions of source code must retain the above copyright notice, this |
| 11 | list of conditions and the following disclaimer. |
| 12 | Redistributions in binary form must reproduce the above copyright notice, this |
| 13 | list of conditions and the following disclaimer in the documentation and/or |
| 14 | other materials provided with the distribution. |
| 15 | |
| 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
| 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
| 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | var ws; |
| 29 | |
| 30 | $(function() { |
| 31 | ws = new WebSocket('ws://' + document.location.host + '/ws'); |
| 32 | ws.onopen = function() { |
| 33 | console.log('onopen'); |
| 34 | }; |
| 35 | ws.onclose = function() { |
| 36 | $('#message').text('Lost connection.'); |
| 37 | console.log('onclose'); |
| 38 | }; |
| 39 | ws.onmessage = function(message) { |
| 40 | console.log("got '" + message.data + "'"); |
| 41 | eval(message.data); |
| 42 | }; |
| 43 | ws.onerror = function(error) { |
| 44 | console.log('onerror ' + error); |
| 45 | console.log(error); |
| 46 | }; |
| 47 | $('#count').click(function() { |
| 48 | ws.send($('#count').val()); |
| 49 | }); |
| 50 | $('#close').click(function() { |
| 51 | ws.send('close'); |
| 52 | }); |
| 53 | $('#die').click(function() { |
| 54 | ws.send('die'); |
| 55 | }); |
| 56 | }); |
| 57 | |
| 58 | set = function(value) { |
| 59 | $('#count').val(value) |
| 60 | } |