JSON-RPC

Author(s):



// send RPC request to firefox content script
$rootScope.rpcList = [];
$rootScope.sendRPC = function(data){
$scope.rpcList.push(data); // save objecy on list
var data2 = {
url:<url>
,auth:<auth>
,method:data.method
,params:data.params
,id:data.id
,phase:1
};
window.postMessage(data2,"http://localhost/");
};

document.defaultView.addEventListener('message',function(event){ // throws error
var obj = event.data;
if(obj){
if(obj.phase === 2){ // arrived at content script, sent to add-on
// ignore
}else if(obj.phase === 6) { // reply from content script
if(obj.id){
for(var i=0; i<$scope.rpcList.length; i++){
if(obj.id === $scope.rpcList[i].id){ // find request in list
var obj2 = $scope.rpcList.splice(i,1)[0]; // original request obj with response function
if(obj.error!=null){
obj2.response(true,obj.error);
}else{
obj2.response(false,obj.result); // return result to caller
}
}
}
}
}
}
});

Download files:

json-rpc-0.5.1-signed.1-signed.xpi


This page is part of the LegacyCollector website.
Disclaimer: All material on this site is property of their respective owners and available under
open licenses to the best of our knowledge. If you are an author and would like anything removed,
then please write an e-mail to legacy [at] collector dot org.