more examples

This commit is contained in:
Tobias Oberstein
2014-02-13 15:01:27 +01:00
parent e615b95f41
commit afbc88d79f
27 changed files with 336 additions and 11 deletions

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>Basic PubSub Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,23 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var counter = 0;
setInterval(function () {
session.publish('com.myapp.topic1', [counter]);
counter += 1;
}, 1000);
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>Basic PubSub Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,29 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var received = 0;
function onevent1(args) {
console.log("Got event:", args[0]);
received += 1;
if (received > 5) {
console.log("Closing ..");
connection.close();
}
}
session.subscribe(onevent1, 'com.myapp.topic1');
};
connection.open();

View File

@@ -19,7 +19,6 @@
from twisted.internet import reactor
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.util import sleep
from autobahn.twisted.wamp import ApplicationSession

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Complex Event Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,31 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
function randint(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}
connection.onopen = function (session) {
var counter = 0;
setInterval(function () {
session.publish('com.myapp.heartbeat');
var obj = {'counter': counter, 'foo': [1, 2, 3]};
session.publish('com.myapp.topic2', [randint(0, 100), 23], {c: "Hello", d: obj});
counter += 1;
}, 1000);
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Complex Event Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,35 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
function on_heartbeat(args, kwargs, details) {
console.log("Got heartbeat (publication ID " + details.publication + ")");
}
session.subscribe(on_heartbeat, 'com.myapp.heartbeat');
function on_topic2(args, kwargs) {
console.log("Got event:", args, kwargs);
}
session.subscribe(on_topic2, 'com.myapp.topic2');
setTimeout(function () {
console.log("Closing ..");
connection.close();
}, 5000);
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Options Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,31 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var counter = 0;
setInterval(function () {
var options = {acknowledge: true, discloseme: true};
session.publish('com.myapp.topic1', [counter], {}, options).then(
function (publication) {
console.log("Event published with publication ID " + publication.id);
}
);
counter += 1;
}, 1000);
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Options Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,33 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var received = 0;
function on_event(args, kwargs, details) {
console.log("Got event, publication ID " +
details.publication + ", publisher " +
details.publisher + ": " + args[0]);
received += 1;
if (received > 5) {
console.log("Closing ..");
connection.close();
}
}
session.subscribe(on_event, 'com.myapp.topic1');
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Unsubscribe Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,23 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var counter = 0;
setInterval(function () {
session.publish('com.myapp.topic1', [counter]);
counter += 1;
}, 1000);
};
connection.open();

View File

@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<body>
<h1>PubSub Unsubscribe Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -0,0 +1,49 @@
try {
var autobahn = require('autobahn');
} catch (e) {
// when running in browser, AutobahnJS will
// be included without a module system
}
var connection = new autobahn.Connection({
url: 'ws://127.0.0.1:9000/',
realm: 'realm1'}
);
connection.onopen = function (session) {
var runs = 0;
function test() {
var received = 0;
var sub = null;
function on_event(args) {
console.log("Got event", args[0]);
received += 1;
if (received > 5) {
runs += 1;
if (runs > 1) {
console.log("Closing ..");
connection.close();
} else {
sub.unsubscribe();
console.log("Unsubscribed .. continue in 2s ..");
setTimeout(test, 2000);
}
}
}
session.subscribe(on_event, 'com.myapp.topic1').then(
function (subscription) {
sub = subscription;
console.log("Subscribed with subscription ID " + subscription.id);
}
);
}
test();
};
connection.open();

View File

@@ -3,7 +3,7 @@
<body>
<h1>Arguments Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Arguments Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Complex Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Complex Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>RPC Options Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>RPC Options Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Slow Square Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Slow Square Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Timeservice Backend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="backend.js"></script>
</body>
</html>

View File

@@ -3,7 +3,7 @@
<body>
<h1>Timeservice Frontend</h1>
<p>Open JavaScript console to watch output.</p>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.js"></script>
<script src="https://autobahn.s3.amazonaws.com/autobahnjs/latest/autobahn.min.jgz"></script>
<script src="frontend.js"></script>
</body>
</html>