From afbc88d79fe6db52f87f70b47d8c8ff08e4c2b7a Mon Sep 17 00:00:00 2001 From: Tobias Oberstein Date: Thu, 13 Feb 2014 15:01:27 +0100 Subject: [PATCH] more examples --- .../wamp/basic/pubsub/basic/backend.html | 9 ++++ .../wamp/basic/pubsub/basic/backend.js | 23 +++++++++ .../wamp/basic/pubsub/basic/frontend.html | 9 ++++ .../wamp/basic/pubsub/basic/frontend.js | 29 +++++++++++ .../wamp/basic/pubsub/basic/frontend.py | 1 - .../wamp/basic/pubsub/complex/backend.html | 9 ++++ .../wamp/basic/pubsub/complex/backend.js | 31 ++++++++++++ .../wamp/basic/pubsub/complex/frontend.html | 9 ++++ .../wamp/basic/pubsub/complex/frontend.js | 35 +++++++++++++ .../wamp/basic/pubsub/options/backend.html | 9 ++++ .../wamp/basic/pubsub/options/backend.js | 31 ++++++++++++ .../wamp/basic/pubsub/options/frontend.html | 9 ++++ .../wamp/basic/pubsub/options/frontend.js | 33 +++++++++++++ .../basic/pubsub/unsubscribe/backend.html | 9 ++++ .../wamp/basic/pubsub/unsubscribe/backend.js | 23 +++++++++ .../basic/pubsub/unsubscribe/frontend.html | 9 ++++ .../wamp/basic/pubsub/unsubscribe/frontend.js | 49 +++++++++++++++++++ .../wamp/basic/rpc/arguments/backend.html | 2 +- .../wamp/basic/rpc/arguments/frontend.html | 2 +- .../wamp/basic/rpc/complex/backend.html | 2 +- .../wamp/basic/rpc/complex/frontend.html | 2 +- .../wamp/basic/rpc/options/backend.html | 2 +- .../wamp/basic/rpc/options/frontend.html | 2 +- .../wamp/basic/rpc/slowsquare/backend.html | 2 +- .../wamp/basic/rpc/slowsquare/frontend.html | 2 +- .../wamp/basic/rpc/timeservice/backend.html | 2 +- .../wamp/basic/rpc/timeservice/frontend.html | 2 +- 27 files changed, 336 insertions(+), 11 deletions(-) create mode 100644 examples/twisted/wamp/basic/pubsub/basic/backend.html create mode 100644 examples/twisted/wamp/basic/pubsub/basic/backend.js create mode 100644 examples/twisted/wamp/basic/pubsub/basic/frontend.html create mode 100644 examples/twisted/wamp/basic/pubsub/basic/frontend.js create mode 100644 examples/twisted/wamp/basic/pubsub/complex/backend.html create mode 100644 examples/twisted/wamp/basic/pubsub/complex/backend.js create mode 100644 examples/twisted/wamp/basic/pubsub/complex/frontend.html create mode 100644 examples/twisted/wamp/basic/pubsub/complex/frontend.js create mode 100644 examples/twisted/wamp/basic/pubsub/options/backend.html create mode 100644 examples/twisted/wamp/basic/pubsub/options/backend.js create mode 100644 examples/twisted/wamp/basic/pubsub/options/frontend.html create mode 100644 examples/twisted/wamp/basic/pubsub/options/frontend.js create mode 100644 examples/twisted/wamp/basic/pubsub/unsubscribe/backend.html create mode 100644 examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js create mode 100644 examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.html create mode 100644 examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js diff --git a/examples/twisted/wamp/basic/pubsub/basic/backend.html b/examples/twisted/wamp/basic/pubsub/basic/backend.html new file mode 100644 index 00000000..2fd336b7 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/basic/backend.html @@ -0,0 +1,9 @@ + + + +

Basic PubSub Backend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/basic/backend.js b/examples/twisted/wamp/basic/pubsub/basic/backend.js new file mode 100644 index 00000000..6d19aafe --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/basic/backend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/basic/frontend.html b/examples/twisted/wamp/basic/pubsub/basic/frontend.html new file mode 100644 index 00000000..69389baf --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/basic/frontend.html @@ -0,0 +1,9 @@ + + + +

Basic PubSub Frontend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/basic/frontend.js b/examples/twisted/wamp/basic/pubsub/basic/frontend.js new file mode 100644 index 00000000..978ba936 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/basic/frontend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/basic/frontend.py b/examples/twisted/wamp/basic/pubsub/basic/frontend.py index aef82e80..8bc7e333 100644 --- a/examples/twisted/wamp/basic/pubsub/basic/frontend.py +++ b/examples/twisted/wamp/basic/pubsub/basic/frontend.py @@ -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 diff --git a/examples/twisted/wamp/basic/pubsub/complex/backend.html b/examples/twisted/wamp/basic/pubsub/complex/backend.html new file mode 100644 index 00000000..54225abf --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/backend.html @@ -0,0 +1,9 @@ + + + +

PubSub Complex Event Backend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/complex/backend.js b/examples/twisted/wamp/basic/pubsub/complex/backend.js new file mode 100644 index 00000000..c8b8fa26 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/backend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/complex/frontend.html b/examples/twisted/wamp/basic/pubsub/complex/frontend.html new file mode 100644 index 00000000..256f9912 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/frontend.html @@ -0,0 +1,9 @@ + + + +

PubSub Complex Event Frontend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/complex/frontend.js b/examples/twisted/wamp/basic/pubsub/complex/frontend.js new file mode 100644 index 00000000..a2e395d1 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/complex/frontend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/options/backend.html b/examples/twisted/wamp/basic/pubsub/options/backend.html new file mode 100644 index 00000000..a843a476 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/backend.html @@ -0,0 +1,9 @@ + + + +

PubSub Options Backend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/options/backend.js b/examples/twisted/wamp/basic/pubsub/options/backend.js new file mode 100644 index 00000000..026f55b0 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/backend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/options/frontend.html b/examples/twisted/wamp/basic/pubsub/options/frontend.html new file mode 100644 index 00000000..760ab9ee --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/frontend.html @@ -0,0 +1,9 @@ + + + +

PubSub Options Frontend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/options/frontend.js b/examples/twisted/wamp/basic/pubsub/options/frontend.js new file mode 100644 index 00000000..7734a572 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/options/frontend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.html b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.html new file mode 100644 index 00000000..47beaa3b --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.html @@ -0,0 +1,9 @@ + + + +

PubSub Unsubscribe Backend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js new file mode 100644 index 00000000..6d19aafe --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/backend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.html b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.html new file mode 100644 index 00000000..a739fdd3 --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.html @@ -0,0 +1,9 @@ + + + +

PubSub Unsubscribe Frontend

+

Open JavaScript console to watch output.

+ + + + diff --git a/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js new file mode 100644 index 00000000..8860755f --- /dev/null +++ b/examples/twisted/wamp/basic/pubsub/unsubscribe/frontend.js @@ -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(); diff --git a/examples/twisted/wamp/basic/rpc/arguments/backend.html b/examples/twisted/wamp/basic/rpc/arguments/backend.html index e113b23a..eb41ac43 100644 --- a/examples/twisted/wamp/basic/rpc/arguments/backend.html +++ b/examples/twisted/wamp/basic/rpc/arguments/backend.html @@ -3,7 +3,7 @@

Arguments Backend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/arguments/frontend.html b/examples/twisted/wamp/basic/rpc/arguments/frontend.html index e9632dc8..c4d0f784 100644 --- a/examples/twisted/wamp/basic/rpc/arguments/frontend.html +++ b/examples/twisted/wamp/basic/rpc/arguments/frontend.html @@ -3,7 +3,7 @@

Arguments Frontend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/complex/backend.html b/examples/twisted/wamp/basic/rpc/complex/backend.html index c7a8b389..75070a62 100644 --- a/examples/twisted/wamp/basic/rpc/complex/backend.html +++ b/examples/twisted/wamp/basic/rpc/complex/backend.html @@ -3,7 +3,7 @@

Complex Backend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/complex/frontend.html b/examples/twisted/wamp/basic/rpc/complex/frontend.html index 6e255fa9..30d68011 100644 --- a/examples/twisted/wamp/basic/rpc/complex/frontend.html +++ b/examples/twisted/wamp/basic/rpc/complex/frontend.html @@ -3,7 +3,7 @@

Complex Frontend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/options/backend.html b/examples/twisted/wamp/basic/rpc/options/backend.html index 2d65afde..612aff81 100644 --- a/examples/twisted/wamp/basic/rpc/options/backend.html +++ b/examples/twisted/wamp/basic/rpc/options/backend.html @@ -3,7 +3,7 @@

RPC Options Backend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/options/frontend.html b/examples/twisted/wamp/basic/rpc/options/frontend.html index 7dbd0f9d..2057beb6 100644 --- a/examples/twisted/wamp/basic/rpc/options/frontend.html +++ b/examples/twisted/wamp/basic/rpc/options/frontend.html @@ -3,7 +3,7 @@

RPC Options Frontend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/slowsquare/backend.html b/examples/twisted/wamp/basic/rpc/slowsquare/backend.html index dcb79822..54fb30fc 100644 --- a/examples/twisted/wamp/basic/rpc/slowsquare/backend.html +++ b/examples/twisted/wamp/basic/rpc/slowsquare/backend.html @@ -3,7 +3,7 @@

Slow Square Backend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/slowsquare/frontend.html b/examples/twisted/wamp/basic/rpc/slowsquare/frontend.html index 6cd89150..0c0f592c 100644 --- a/examples/twisted/wamp/basic/rpc/slowsquare/frontend.html +++ b/examples/twisted/wamp/basic/rpc/slowsquare/frontend.html @@ -3,7 +3,7 @@

Slow Square Frontend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/timeservice/backend.html b/examples/twisted/wamp/basic/rpc/timeservice/backend.html index 448e84f8..6792a768 100644 --- a/examples/twisted/wamp/basic/rpc/timeservice/backend.html +++ b/examples/twisted/wamp/basic/rpc/timeservice/backend.html @@ -3,7 +3,7 @@

Timeservice Backend

Open JavaScript console to watch output.

- + diff --git a/examples/twisted/wamp/basic/rpc/timeservice/frontend.html b/examples/twisted/wamp/basic/rpc/timeservice/frontend.html index 7bed1d52..7bf418b6 100644 --- a/examples/twisted/wamp/basic/rpc/timeservice/frontend.html +++ b/examples/twisted/wamp/basic/rpc/timeservice/frontend.html @@ -3,7 +3,7 @@

Timeservice Frontend

Open JavaScript console to watch output.

- +