forked from abelaska/websockets-stomp-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
107 lines (99 loc) · 3.37 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Stomp test</title>
<!-- Include these three JS files: -->
<script type="text/javascript" src="web-socket-js/swfobject.js"></script>
<script type="text/javascript" src="web-socket-js/FABridge.js"></script>
<script type="text/javascript" src="web-socket-js/web_socket.js"></script>
<!-- INIT -->
<script type="text/javascript" src="stomple/src/stomple.js"></script>
</head>
<body><p>
<label for="inputText">Message: </label>
<input type="text" id="inputText" onkeydown='handleKeyDown(arguments[0]);'>
<br>
<button id="sendBtn" onclick='sendMsg();'>Send</button>
<button id="resetBtn" onclick='reset();'>Reset</button>
<button id="beginBtn" onclick='begin();'>Begin transaction</button>
<button id="commitBtn" onclick='commit();'>Commit transaction</button>
<button id="abortBtn" onclick='abort();'>Abort transaction</button>
<button id="disBtn" onclick='disconnect();'>Disconnect</button>
<p>
Chat:<br>
<div id="content"></div>
<script type="text/javascript">
// Set URL of your WebSocketMain.swf here:
WEB_SOCKET_SWF_LOCATION = "web-socket-js/WebSocketMain.swf";
// Set this to dump debug message from Flash to console.log:
WEB_SOCKET_DEBUG = true;
function begin() {
client.begin({});
}
function commit() {
client.commit({});
}
function abort() {
client.abort({});
}
function disconnect() {
client.disconnect({success: function(){console.log("dis");}, failure: function(){console.log(42);}});
}
function reset() {
document.getElementById('inputText').value = '';
document.getElementById('content').innerHTML = '';
}
var handleKeyDown = function (e) {
e = e || window.event;
var kc = e.keyCode,
ki = e.keyIdentifier;
if ((ki && ki.toLowerCase() === "enter") || (kc === 13)) {
sendMsg();
document.getElementById('inputText').value = '';
}
}
function sendMsg() {
var i = document.getElementById('inputText');
client.send({
body: client.session+": "+i.value,
});
}
if (!Stomple) {
document.getElementById('content').innerHTML = "Your browser doesn't support Stomple. Google Chrome does.";
document.getElementById('sendBtn').disabled = true;
document.getElementById('resetBtn').disabled = true;
document.getElementById('beginBtn').disabled = true;
document.getElementById('commitBtn').disabled = true;
document.getElementById('abortBtn').disabled = true;
document.getElementById('inputText').readonly = true;
handleKeyDown = function(){};
} else {
Stomple.debug = true;
var client = Stomple.create_client({
url: "ws://localhost:61614/stomp",
destination: "jms.topic.topicChat",
login: "guest",
passcode: "guest"
});
var msgHandler = {
fn: function(msg) {
var c = document.getElementById('content');
c.innerHTML = c.innerHTML + '<br>' + msg.body;
}
};
client.subscribe({
handler: msgHandler.fn,
scope: msgHandler,
success: function() {//did subscription succeed?
console.log("sub ok..");
},
failure: function(reason) {//did subscription fail?
console.log(reason);
}
});
document.getElementById('inputText').focus();
}
</script>
</body>
</html>