This repository has been archived by the owner on Feb 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.scala.html
78 lines (63 loc) · 2 KB
/
index.scala.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
@(message: String)
@main(message) {
<h1>@message</h1>
<button id="life-button">
Get meaning of life
</button>
<br>
<button id="capital-button">
Capitalize word
</button>
<input id="capital-input" type="text">
<h2>Output:</h2>
<div id="output" class="well">
</div>
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.js"></script>
<script type="text/javascript" charset="utf-8">
// Get WAMP endpoint URL
var wsuri = "@ws.wamplay.controllers.routes.WAMPlayServer.connect().webSocketURL(request)";
var molURI = "http://example.com/calc#meaningOfLife";
var capitalURI = "http://example.com/calc#capital";
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
function write (output) {
var d = $('<div>');
if (output.uri) {
d.addClass("error")
d.html(output.uri + ", " + output.desc + ", " +output.detail)
} else {
d.html(output);
}
$('#output').append(d);
}
function setUpControls (session) {
$("#life-button").click(function() {
write("Sending call to: " + molURI);
session.call(molURI).then(write, write);
});
$("#capital-button").click(function() {
var message = $("#capital-input").val();
message = (isNumber(message))?parseFloat(message):message;
write("Sending call to: " + capitalURI);
session.call(capitalURI, message).then(write, write);
});
}
$(function() {
// connect to WAMPlay server
write("Connecting to WAMPlay server...");
ab.connect(wsuri,
// WAMP session was established
function (session) {
setUpControls(session);
write("Connected to " + wsuri);
},
// WAMP session is gone
function (code, reason) {
write("Connection lost (" + reason + ")", true);
},
{skipSubprotocolCheck:true, skipSubprotocolAnnounce:true} // Important! Play rejects all subprotocols...
);
});
</script>
}