|
@@ -0,0 +1,101 @@
|
|
1
|
+// var stompClient = null;
|
|
2
|
+//
|
|
3
|
+// function setConnected(connected) {
|
|
4
|
+// $("#connect").prop("disabled", connected);
|
|
5
|
+// $("#disconnect").prop("disabled", !connected);
|
|
6
|
+// if (connected) {
|
|
7
|
+// $("#conversation").show();
|
|
8
|
+// }
|
|
9
|
+// else {
|
|
10
|
+// $("#conversation").hide();
|
|
11
|
+// }
|
|
12
|
+// $("#greetings").html("");
|
|
13
|
+// }
|
|
14
|
+//
|
|
15
|
+// function connect() {
|
|
16
|
+// var socket = new SockJS('/gs-guide-websocket');
|
|
17
|
+// stompClient = Stomp.over(socket);
|
|
18
|
+// stompClient.connect({}, function (frame) {
|
|
19
|
+// setConnected(true);
|
|
20
|
+// console.log('Connected: ' + frame);
|
|
21
|
+// stompClient.subscribe('/topic/posts', function (post) {
|
|
22
|
+// showGreeting(JSON.parse(post.body).message);
|
|
23
|
+// });
|
|
24
|
+// });
|
|
25
|
+// }
|
|
26
|
+//
|
|
27
|
+// function disconnect() {
|
|
28
|
+// if (stompClient !== null) {
|
|
29
|
+// stompClient.disconnect();
|
|
30
|
+// }
|
|
31
|
+// setConnected(false);
|
|
32
|
+// console.log("Disconnected");
|
|
33
|
+// }
|
|
34
|
+//
|
|
35
|
+// function sendName() {
|
|
36
|
+// stompClient.send("/users/1/posts/", {}, JSON.stringify({'message': $("#message").val(), 'userId': '1'}));
|
|
37
|
+// }
|
|
38
|
+//
|
|
39
|
+// function showGreeting(message) {
|
|
40
|
+// $("#greetings").append("<tr><td>" + message + "</td></tr>");
|
|
41
|
+// }
|
|
42
|
+//
|
|
43
|
+// $(function () {
|
|
44
|
+// $("form").on('submit', function (e) {
|
|
45
|
+// e.preventDefault();
|
|
46
|
+// });
|
|
47
|
+// $( "#connect" ).click(function() { connect(); });
|
|
48
|
+// $( "#disconnect" ).click(function() { disconnect(); });
|
|
49
|
+// $( "#send" ).click(function() { sendName(); });
|
|
50
|
+// });
|
|
51
|
+
|
|
52
|
+var stompClient = null;
|
|
53
|
+
|
|
54
|
+function setConnected(connected) {
|
|
55
|
+ $('#connect').prop("disabled", connected);
|
|
56
|
+ $('#disconnect').prop("disabled", !connected);
|
|
57
|
+ if (connected) {
|
|
58
|
+ $("#conversation").show();
|
|
59
|
+ }
|
|
60
|
+ else {
|
|
61
|
+ $("#conversation").hide();
|
|
62
|
+ }
|
|
63
|
+ $("#greetings").html("");
|
|
64
|
+}
|
|
65
|
+
|
|
66
|
+function connect() {
|
|
67
|
+ var socket = new SockJS('/gs-guide-websocket');
|
|
68
|
+ stompClient = Stomp.over(socket);
|
|
69
|
+ stompClient.connect({}, function (frame) {
|
|
70
|
+ setConnected(true);
|
|
71
|
+ console.log('Connected: ' + frame);
|
|
72
|
+ stompClient.subscribe('/topic/greetings', function (greeting) {
|
|
73
|
+ showGreeting(JSON.parse(greeting.body).content);
|
|
74
|
+ });
|
|
75
|
+ });
|
|
76
|
+}
|
|
77
|
+
|
|
78
|
+function disconnect() {
|
|
79
|
+ if (stompClient !== null) {
|
|
80
|
+ stompClient.disconnect();
|
|
81
|
+ }
|
|
82
|
+ setConnected(false);
|
|
83
|
+ console.log("Disconnected");
|
|
84
|
+}
|
|
85
|
+
|
|
86
|
+function sendName() {
|
|
87
|
+ stompClient.send("/app/hello", {}, JSON.stringify({'name': $("#name").val()}));
|
|
88
|
+}
|
|
89
|
+
|
|
90
|
+function showGreeting(message) {
|
|
91
|
+ $("#greetings").append("<tr><td>" + message + "</td></tr>");
|
|
92
|
+}
|
|
93
|
+
|
|
94
|
+$(function () {
|
|
95
|
+ $("form").on('submit', function (e) {
|
|
96
|
+ e.preventDefault();
|
|
97
|
+ });
|
|
98
|
+ $( "#connect" ).click(function() { connect(); });
|
|
99
|
+ $( "#disconnect" ).click(function() { disconnect(); });
|
|
100
|
+ $( "#send" ).click(function() { sendName(); });
|
|
101
|
+});
|