more examples
This commit is contained in:
9
examples/twisted/wamp/basic/pubsub/basic/backend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/basic/backend.html
Normal 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>
|
||||
23
examples/twisted/wamp/basic/pubsub/basic/backend.js
Normal file
23
examples/twisted/wamp/basic/pubsub/basic/backend.js
Normal 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();
|
||||
9
examples/twisted/wamp/basic/pubsub/basic/frontend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/basic/frontend.html
Normal 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>
|
||||
29
examples/twisted/wamp/basic/pubsub/basic/frontend.js
Normal file
29
examples/twisted/wamp/basic/pubsub/basic/frontend.js
Normal 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();
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
9
examples/twisted/wamp/basic/pubsub/complex/backend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/complex/backend.html
Normal 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>
|
||||
31
examples/twisted/wamp/basic/pubsub/complex/backend.js
Normal file
31
examples/twisted/wamp/basic/pubsub/complex/backend.js
Normal 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();
|
||||
9
examples/twisted/wamp/basic/pubsub/complex/frontend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/complex/frontend.html
Normal 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>
|
||||
35
examples/twisted/wamp/basic/pubsub/complex/frontend.js
Normal file
35
examples/twisted/wamp/basic/pubsub/complex/frontend.js
Normal 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();
|
||||
9
examples/twisted/wamp/basic/pubsub/options/backend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/options/backend.html
Normal 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>
|
||||
31
examples/twisted/wamp/basic/pubsub/options/backend.js
Normal file
31
examples/twisted/wamp/basic/pubsub/options/backend.js
Normal 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();
|
||||
9
examples/twisted/wamp/basic/pubsub/options/frontend.html
Normal file
9
examples/twisted/wamp/basic/pubsub/options/frontend.html
Normal 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>
|
||||
33
examples/twisted/wamp/basic/pubsub/options/frontend.js
Normal file
33
examples/twisted/wamp/basic/pubsub/options/frontend.js
Normal 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();
|
||||
@@ -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>
|
||||
23
examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js
Normal file
23
examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js
Normal 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();
|
||||
@@ -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>
|
||||
49
examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js
Normal file
49
examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js
Normal 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();
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user