File: frontend.js

package info (click to toggle)
python-autobahn 23.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,424 kB
  • sloc: python: 38,620; javascript: 2,705; makefile: 899; ansic: 373; sh: 63
file content (47 lines) | stat: -rw-r--r-- 1,057 bytes parent folder | download | duplicates (5)
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
try {
   var autobahn = require('autobahn');
   var when = require('when');
} catch (e) {
   // When running in browser, AutobahnJS will
   // be included without a module system
   var when = autobahn.when;
}

var connection = new autobahn.Connection({
   url: 'ws://127.0.0.1:8080/ws',
   realm: 'crossbardemo'}
);

connection.onopen = function (session) {

   function on_event(val) {
      console.log("Someone requested to square non-positive:", val);
   }

   session.subscribe('com.myapp.square_on_nonpositive', on_event);

   var dl = [];

   var vals = [2, 0, -2];
   for (var i = 0; i < vals.length; ++i) {

      dl.push(session.call('com.myapp.square', [vals[i]], {}, {}).then(
         function (res) {
            console.log("Squared", res);
         },
         function (error) {
            console.log("Call failed:", error);
         }
      ));
   }

   when.all(dl).then(
      function () {
         console.log("All finished.");
      },
      function () {
         console.log("Error", arguments);
      });
};

connection.open();