Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>Socket.IO chat</title> |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame^] | 5 | <script src="http://localhost:4000/socket.io/socket.io.js"></script> |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 6 | <script |
| 7 | src="https://code.jquery.com/jquery-1.12.4.min.js" |
| 8 | integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" |
| 9 | crossorigin="anonymous"></script> |
| 10 | <script src="https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js"></script> |
| 11 | |
| 12 | <style> |
| 13 | body { |
| 14 | max-width: 100%; |
| 15 | } |
| 16 | </style> |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame^] | 17 | <script> |
| 18 | /* global io $ alert*/ |
| 19 | function enableSocket(auth) { |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 20 | |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame^] | 21 | auth.user = JSON.parse(auth.user); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 22 | |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame^] | 23 | var socket = io.connect('http://localhost:4000', { |
| 24 | query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id |
| 25 | }); |
| 26 | socket.on('event', function(data) { |
| 27 | var p = $('body').append('<p></p>'); |
| 28 | p.append('<b>' + data.model + '</b><br/>'); |
| 29 | p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>'); |
| 30 | p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>'); |
| 31 | console.log(data.object); |
| 32 | $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success'); |
| 33 | }); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 34 | } |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame^] | 35 | |
| 36 | function login() { |
| 37 | var username = $('#username').val(); |
| 38 | var password = $('#password').val(); |
| 39 | |
| 40 | $.get('http://localhost:4000/api/utility/login?username='+username+'&password='+password, |
| 41 | function(res) { |
| 42 | enableSocket(res); |
| 43 | $('#login').hide(); |
| 44 | } |
| 45 | ) |
| 46 | .fail(function(e) { |
| 47 | alert( 'error' ); |
| 48 | console.log(e); |
| 49 | }); |
| 50 | } |
| 51 | </script> |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 52 | </head> |
| 53 | <body> |
| 54 | <form onsubmit="login()" id="login"> |
| 55 | <input type="text" id="username"> |
| 56 | <input type="password" id="password"> |
| 57 | <input type="button" value="Login" onclick="login()"> |
| 58 | </form> |
| 59 | </body> |
| 60 | </html> |