|
|
@ -81,17 +81,25 @@ define([
|
|
|
|
// If the type is a query, your handler will be invoked with a reply function that takes
|
|
|
|
// If the type is a query, your handler will be invoked with a reply function that takes
|
|
|
|
// one argument (the content to reply with).
|
|
|
|
// one argument (the content to reply with).
|
|
|
|
chan.on = function (queryType, handler, quiet) {
|
|
|
|
chan.on = function (queryType, handler, quiet) {
|
|
|
|
(handlers[queryType] = handlers[queryType] || []).push(function (data, msg) {
|
|
|
|
var h = function (data, msg) {
|
|
|
|
handler(data.content, function (replyContent) {
|
|
|
|
handler(data.content, function (replyContent) {
|
|
|
|
postMsg(JSON.stringify({
|
|
|
|
postMsg(JSON.stringify({
|
|
|
|
txid: data.txid,
|
|
|
|
txid: data.txid,
|
|
|
|
content: replyContent
|
|
|
|
content: replyContent
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
}, msg);
|
|
|
|
}, msg);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
(handlers[queryType] = handlers[queryType] || []).push(h);
|
|
|
|
if (!quiet) {
|
|
|
|
if (!quiet) {
|
|
|
|
event('EV_REGISTER_HANDLER', queryType);
|
|
|
|
event('EV_REGISTER_HANDLER', queryType);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
stop: function () {
|
|
|
|
|
|
|
|
var idx = handlers[queryType].indexOf(h);
|
|
|
|
|
|
|
|
if (idx === -1) { return; }
|
|
|
|
|
|
|
|
handlers[queryType].splice(idx, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// If a particular handler is registered, call the callback immediately, otherwise it will be called
|
|
|
|
// If a particular handler is registered, call the callback immediately, otherwise it will be called
|
|
|
|