WIP rpc framework
This commit is contained in:
@@ -249,7 +249,6 @@ define([
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var evt = Util.mkEvent();
|
||||
var respond = function (e, out) {
|
||||
evt.fire(e, out);
|
||||
@@ -259,9 +258,8 @@ define([
|
||||
try {
|
||||
var parsed = JSON.parse(raw);
|
||||
var txid = parsed.txid;
|
||||
var message = parsed.message;
|
||||
setTimeout(function () {
|
||||
service(message.command, message.content, function (e, result) {
|
||||
service(parsed.q, parsed.content, function (e, result) {
|
||||
respond(JSON.stringify({
|
||||
txid: txid,
|
||||
error: e,
|
||||
@@ -285,33 +283,56 @@ define([
|
||||
});
|
||||
}, "Test rpc factory");
|
||||
|
||||
/*
|
||||
assert(function (cb) {
|
||||
var getBlob = function (url, cb) {
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", url, true);
|
||||
xhr.responseType = "blob";
|
||||
xhr.onload = function () {
|
||||
cb(void 0, this.response);
|
||||
};
|
||||
xhr.send();
|
||||
};
|
||||
require([
|
||||
'/assert/frame/frame.js',
|
||||
], function (Frame) {
|
||||
Frame.create(document.body, '/assert/frame/frame.html', function (e, frame) {
|
||||
if (e) { return cb(false); }
|
||||
|
||||
var $img = $('img#thumb-orig');
|
||||
getBlob($img.attr('src'), function (e, blob) {
|
||||
console.log(e, blob);
|
||||
Thumb.fromImageBlob(blob, function (e, thumb) {
|
||||
console.log(thumb);
|
||||
var th = new Image();
|
||||
th.src = URL.createObjectURL(thumb);
|
||||
th.onload = function () {
|
||||
$(document.body).append($(th).addClass('thumb'));
|
||||
cb(th.width === Thumb.dimension && th.height === Thumb.dimension);
|
||||
};
|
||||
var channel = Frame.open(frame, [
|
||||
/.*/i,
|
||||
], 5000);
|
||||
|
||||
channel.send('HELO', null, function (e, res) {
|
||||
if (res === 'EHLO') { return cb(true); }
|
||||
cb(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
*/
|
||||
}, "PEWPEW");
|
||||
|
||||
(function () {
|
||||
var guid = Wire.uid();
|
||||
|
||||
var t = Wire.tracker({
|
||||
timeout: 1000,
|
||||
hook: function (txid, q, content) {
|
||||
console.info(JSON.stringify({
|
||||
guid: guid,
|
||||
txid: txid,
|
||||
q: q,
|
||||
content: content,
|
||||
}));
|
||||
},
|
||||
});
|
||||
|
||||
assert(function (cb) {
|
||||
t.call('SHOULD_TIMEOUT', null, function (e) {
|
||||
if (e === 'TIMEOUT') { return cb(true); }
|
||||
cb(false);
|
||||
});
|
||||
}, 'tracker should timeout');
|
||||
|
||||
assert(function (cb) {
|
||||
var id = t.call('SHOULD_NOT_TIMEOUT', null, function (e, out) {
|
||||
if (e) { return cb(false); }
|
||||
if (out === 'YES') { return cb(true); }
|
||||
cb(false);
|
||||
});
|
||||
t.respond(id, void 0, 'YES');
|
||||
}, "tracker should not timeout");
|
||||
}());
|
||||
|
||||
Drive.test(assert);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user