Files
deb-python-autobahn/examples/pubsub/authorization/index.html
Tobias Oberstein c33c569987 more README
2012-06-21 15:36:51 +02:00

70 lines
2.1 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<!-- include AutobahnJS .. that's all you need -->
<script src="http://autobahn.s3.amazonaws.com/js/autobahn.min.js"></script>
<script>
// WAMP session object
var sess;
window.onload = function() {
// connect to WAMP server
ab.connect("ws://localhost:9000",
// WAMP session was established
function (session) {
sess = session;
console.log("Connected!");
sess.prefix("event", "http://example.com/event/");
sess.subscribe("event:simple", onEvent);
sess.subscribe("event:simple-foobar", onEvent);
sess.subscribe("event:foobar1", onEvent);
sess.subscribe("event:foobar2", onEvent);
},
// WAMP session is gone
function (code, reason) {
sess = null;
alert(reason);
}
);
};
function onEvent(topicUri, event) {
console.log(topicUri);
console.log(event);
}
function logerror(erroruri, errordesc) {
console.log(erroruri + ' ("' + errordesc + '")');
}
function test()
{
sess.publish("event:simple", {name: "foo",
created: new Date(),
num: 23,
rand: Math.random()});
sess.publish("event:simple-foobar", {name: "foo",
value: "bar",
num: 333});
sess.publish("event:foobar1", {count: 42});
sess.publish("event:foobar1", {count: -1});
sess.publish("event:foobar2", {count: 666});
sess.publish("event:foobarbaz", {count: 10});
}
</script>
</head>
<body>
<h1>AutobahnJS PubSub Client - PubSub with Authorization</h1>
<button onclick="test()">Publish Events</button>
</body>
</html>