-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.html
42 lines (38 loc) · 1.24 KB
/
client.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
<!DOCTYPE html>
<html>
<head>
<title>AMQP websockets example</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<!-- This example was adapted from a chat example included in the
excellent 'JavaScript: The Definitive Guide', by David Flanagan and
published by O'Reilly. -->
<script src="../../rhea.js"></script>
</head>
<body>
<input type="text" id="request" style="width:100%"/>
<script>
var server = prompt("Enter details of server to use", "ws://localhost:5673");
var input = document.getElementById("request");
input.focus();
function append(txt) {
var node = document.createTextNode(txt);
var div = document.createElement("div");
div.appendChild(node);
document.body.insertBefore(div, input);
input.scrollIntoView();
}
input.onchange = function() {
sender.send({"body":input.value});
input.value = "";
};
var client = require("rhea");
client.on("message", function (context) {
append(context.message.body);
});
var ws = client.websocket_connect(WebSocket);
var connection = client.connect({"connection_details":ws(server, ["binary", "AMQPWSB10", "amqp"]), "reconnect":false});
connection.open_receiver("examples");
var sender = connection.open_sender("examples");
</script>
</body>
</html>