Matteo Scandolo | bd13aab | 2017-08-08 13:05:24 -0700 | [diff] [blame^] | 1 | |
| 2 | <!-- |
| 3 | Copyright 2017-present Open Networking Foundation |
| 4 | |
| 5 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | you may not use this file except in compliance with the License. |
| 7 | You may obtain a copy of the License at |
| 8 | |
| 9 | http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, software |
| 12 | distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | See the License for the specific language governing permissions and |
| 15 | limitations under the License. |
| 16 | --> |
| 17 | |
| 18 | |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 19 | <!doctype html> |
| 20 | <html> |
| 21 | <head> |
| 22 | <title>Socket.IO chat</title> |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame] | 23 | <script src="http://localhost:4000/socket.io/socket.io.js"></script> |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 24 | <script |
| 25 | src="https://code.jquery.com/jquery-1.12.4.min.js" |
| 26 | integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" |
| 27 | crossorigin="anonymous"></script> |
| 28 | <script src="https://rawgit.com/notifyjs/notifyjs/master/dist/notify.js"></script> |
| 29 | |
| 30 | <style> |
| 31 | body { |
| 32 | max-width: 100%; |
| 33 | } |
| 34 | </style> |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame] | 35 | <script> |
| 36 | /* global io $ alert*/ |
| 37 | function enableSocket(auth) { |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 38 | |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame] | 39 | auth.user = JSON.parse(auth.user); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 40 | |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame] | 41 | var socket = io.connect('http://localhost:4000', { |
| 42 | query: 'name=' + auth.user.username + '&token=' + auth.xoscsrftoken + '&sessionId=' + auth.xossessionid + '&id=' + auth.user.id |
| 43 | }); |
| 44 | socket.on('event', function(data) { |
| 45 | var p = $('body').append('<p></p>'); |
| 46 | p.append('<b>' + data.model + '</b><br/>'); |
| 47 | p.append('<i>' + JSON.stringify(data.msg.changed_fields) + '</i>'); |
| 48 | p.append('<pre>' + JSON.stringify(data.msg.object) + '</pre>'); |
| 49 | console.log(data.object); |
| 50 | $.notify(data.model + ': ' + JSON.stringify(data.msg.object.name) + 'updated', 'success'); |
| 51 | }); |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 52 | } |
Matteo Scandolo | f05d8a6 | 2016-12-06 13:36:49 -0800 | [diff] [blame] | 53 | |
| 54 | function login() { |
| 55 | var username = $('#username').val(); |
| 56 | var password = $('#password').val(); |
| 57 | |
| 58 | $.get('http://localhost:4000/api/utility/login?username='+username+'&password='+password, |
| 59 | function(res) { |
| 60 | enableSocket(res); |
| 61 | $('#login').hide(); |
| 62 | } |
| 63 | ) |
| 64 | .fail(function(e) { |
| 65 | alert( 'error' ); |
| 66 | console.log(e); |
| 67 | }); |
| 68 | } |
| 69 | </script> |
Matteo Scandolo | e3ed016 | 2016-12-01 10:09:12 -0800 | [diff] [blame] | 70 | </head> |
| 71 | <body> |
| 72 | <form onsubmit="login()" id="login"> |
| 73 | <input type="text" id="username"> |
| 74 | <input type="password" id="password"> |
| 75 | <input type="button" value="Login" onclick="login()"> |
| 76 | </form> |
| 77 | </body> |
| 78 | </html> |