amp.js 842 B

1234567891011121314151617181920212223242526272829303132
  1. var stompClient = null;
  2. function connect() {
  3. var socket = new SockJS('http://localhost:8081/amp/websocket');
  4. stompClient = Stomp.over(socket);
  5. stompClient.connect({}, function (frame) {
  6. console.log('Connected: ' + frame);
  7. stompClient.subscribe('/public/transactions', function (msg) {
  8. var msgJ = JSON.parse(msg.body);
  9. console.log('/public/transactions', msgJ);
  10. });
  11. stompClient.subscribe('/channel/transactions', function (msg) {
  12. var msgJ = JSON.parse(msg.body);
  13. console.log('/channel/transactions', msgJ);
  14. });
  15. });
  16. }
  17. function disconnect() {
  18. if (stompClient !== null) {
  19. stompClient.disconnect();
  20. }
  21. setConnected(false);
  22. console.log("Disconnected");
  23. }
  24. $(document).ready(function() {
  25. connect();
  26. });