fix demos
This commit is contained in:
@@ -25,6 +25,8 @@ connection.onopen = function (session) {
|
||||
session.publish('com.myapp.topic2', [randint(0, 100), 23], {c: "Hello", d: obj});
|
||||
|
||||
counter += 1;
|
||||
|
||||
console.log("events published");
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
|
||||
@@ -16,14 +16,14 @@ connection.onopen = function (session) {
|
||||
console.log("Got heartbeat (publication ID " + details.publication + ")");
|
||||
}
|
||||
|
||||
session.subscribe(on_heartbeat, 'com.myapp.heartbeat');
|
||||
session.subscribe('com.myapp.heartbeat', on_heartbeat);
|
||||
|
||||
|
||||
function on_topic2(args, kwargs) {
|
||||
console.log("Got event:", args, kwargs);
|
||||
}
|
||||
|
||||
session.subscribe(on_topic2, 'com.myapp.topic2');
|
||||
session.subscribe('com.myapp.topic2', on_topic2);
|
||||
|
||||
|
||||
setTimeout(function () {
|
||||
|
||||
@@ -27,7 +27,7 @@ connection.onopen = function (session) {
|
||||
}
|
||||
}
|
||||
|
||||
session.subscribe(on_event, 'com.myapp.topic1');
|
||||
session.subscribe('com.myapp.topic1', on_event);
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
@@ -17,6 +17,7 @@ connection.onopen = function (session) {
|
||||
setInterval(function () {
|
||||
session.publish('com.myapp.topic1', [counter]);
|
||||
counter += 1;
|
||||
console.log("events published");
|
||||
}, 1000);
|
||||
};
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ connection.onopen = function (session) {
|
||||
}
|
||||
}
|
||||
|
||||
session.subscribe(on_event, 'com.myapp.topic1').then(
|
||||
session.subscribe('com.myapp.topic1', on_event).then(
|
||||
function (subscription) {
|
||||
sub = subscription;
|
||||
console.log("Subscribed with subscription ID " + subscription.id);
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
try {
|
||||
var autobahn = require('autobahn');
|
||||
var when = require('when');
|
||||
} catch (e) {
|
||||
// when running in browser, AutobahnJS will
|
||||
// When running in browser, AutobahnJS will
|
||||
// be included without a module system
|
||||
var when = autobahn.when;
|
||||
}
|
||||
|
||||
var connection = new autobahn.Connection({
|
||||
@@ -41,11 +43,21 @@ connection.onopen = function (session) {
|
||||
return [args.length, Object.keys(kwargs).length];
|
||||
}
|
||||
|
||||
session.register('com.arguments.ping', ping)
|
||||
session.register('com.arguments.add2', add2)
|
||||
session.register('com.arguments.stars', stars)
|
||||
session.register('com.arguments.orders', orders)
|
||||
session.register('com.arguments.arglen', arglen)
|
||||
var dl = [];
|
||||
|
||||
dl.push(session.register('com.arguments.ping', ping));
|
||||
dl.push(session.register('com.arguments.add2', add2));
|
||||
dl.push(session.register('com.arguments.stars', stars));
|
||||
dl.push(session.register('com.arguments.orders', orders));
|
||||
dl.push(session.register('com.arguments.arglen', arglen));
|
||||
|
||||
when.all(dl).then(
|
||||
function () {
|
||||
console.log("All registered.");
|
||||
},
|
||||
function () {
|
||||
console.log("Registration failed!", arguments);
|
||||
});
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
@@ -25,7 +25,14 @@ connection.onopen = function (session) {
|
||||
return res;
|
||||
}
|
||||
|
||||
session.register('com.myapp.sqrt', sqrt);
|
||||
session.register('com.myapp.sqrt', sqrt).then(
|
||||
function (registration) {
|
||||
console.log("Procedure registered:", registration.id);
|
||||
},
|
||||
function (error) {
|
||||
console.log("Registration failed:", error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
@@ -18,7 +18,7 @@ connection.onopen = function (session) {
|
||||
console.log("Someone requested to square non-negative:", val);
|
||||
}
|
||||
|
||||
session.subscribe(on_event, 'com.myapp.square_on_nonpositive');
|
||||
session.subscribe('com.myapp.square_on_nonpositive', on_event);
|
||||
|
||||
var dl = [];
|
||||
|
||||
@@ -35,10 +35,15 @@ connection.onopen = function (session) {
|
||||
));
|
||||
}
|
||||
|
||||
when.all(dl).then(function () {
|
||||
console.log("All finished.");
|
||||
connection.close();
|
||||
});
|
||||
when.all(dl).then(
|
||||
function () {
|
||||
console.log("All finished.");
|
||||
connection.close();
|
||||
},
|
||||
function () {
|
||||
console.log("Error", arguments);
|
||||
connection.close();
|
||||
});
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
@@ -42,7 +42,14 @@ connection.onopen = function (session) {
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
session.register('com.myapp.longop', longop);
|
||||
session.register('com.myapp.longop', longop).then(
|
||||
function (registration) {
|
||||
console.log("Procedure registered:", registration.id);
|
||||
},
|
||||
function (error) {
|
||||
console.log("Registration failed:", error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
@@ -39,7 +39,14 @@ connection.onopen = function (session) {
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
session.register('com.math.slowsquare', slowsquare);
|
||||
session.register('com.math.slowsquare', slowsquare).then(
|
||||
function (registration) {
|
||||
console.log("Procedure registered:", registration.id);
|
||||
},
|
||||
function (error) {
|
||||
console.log("Registration failed:", error);
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
connection.open();
|
||||
|
||||
Reference in New Issue
Block a user