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