|
@@ -1,69 +0,0 @@
|
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
|
|
- $("#messages").html("");
|
13
|
|
-}
|
14
|
|
-
|
15
|
|
-function connect() {
|
16
|
|
- var socket = new SockJS('/vault-socket');
|
17
|
|
- stompClient = Stomp.over(socket);
|
18
|
|
- stompClient.connect({}, function (frame) {
|
19
|
|
- setConnected(true);
|
20
|
|
- console.log('Connected: ' + frame);
|
21
|
|
- stompClient.subscribe('/topic/posts', function (greeting) {
|
22
|
|
- showGreeting(JSON.parse(greeting.body).message, JSON.parse(greeting.body).userName);
|
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
|
|
-var userId = 1;
|
36
|
|
-var userPostUrl = "/app/posts";
|
37
|
|
-
|
38
|
|
-function user1() {
|
39
|
|
- $('#user1').prop("disabled", true);
|
40
|
|
- $('#user2').prop("disabled", false);
|
41
|
|
- userId = 1;
|
42
|
|
-}
|
43
|
|
-
|
44
|
|
-function user2() {
|
45
|
|
- $('#user1').prop("disabled", false);
|
46
|
|
- $('#user2').prop("disabled", true);
|
47
|
|
- userId = 2;
|
48
|
|
-}
|
49
|
|
-
|
50
|
|
-
|
51
|
|
-function sendName() {
|
52
|
|
-
|
53
|
|
- stompClient.send(userPostUrl, {}, JSON.stringify({'id': '','message': $("#message").val(),'userId': userId}))
|
54
|
|
-}
|
55
|
|
-
|
56
|
|
-function showGreeting(message, userName) {
|
57
|
|
- $("#messages").append("<tr><td>" + userName + ": " + message + "</td></tr>");
|
58
|
|
-}
|
59
|
|
-
|
60
|
|
-$(function () {
|
61
|
|
- $("form").on('submit', function (e) {
|
62
|
|
- e.preventDefault();
|
63
|
|
- });
|
64
|
|
- $( "#connect" ).click(function() { connect(); });
|
65
|
|
- $( "#disconnect" ).click(function() { disconnect(); });
|
66
|
|
- $( "#send" ).click(function() { sendName(); });
|
67
|
|
- $( "#user1" ).click(function() { user1(); });
|
68
|
|
- $( "#user2" ).click(function() { user2(); })
|
69
|
|
-});
|