Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JS requesting #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions common.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,51 +328,59 @@ var common = (function() {
return true;
}

function retmsg(msg)
function retmsg(msg, cb)
{
common.naclModule.postMessage(msg);
console.log("sent: "+msg);
console.log(cb);
postCall("js", msg, cb, function() {
// nothing
});
console.log("sent: "+msg+" "+cb);
}

function handleMessage(message_event)
{
if(isJson(message_event.data))
{
console.log("AAAA");
var request = JSON.parse(message_event.data);
var cb = request.pointer;
console.log(request);
if(request.method == "NxtAPI")
{
console.log(request.requestType);
if(request.params == undefined) request.params = "{}";
Jay.request(request.requestType, JSON.parse(request.params), function(ans) {
retmsg(ans);
retmsg(ans, cb);
})
}
else if(request.method == "status")
{
retmsg("{'status':'doing alright'}");
retmsg("{'status':'doing alright'}", cb);
}
else if(request.method == "signBytes")
{
var out = converters.byteArrayToHexString(signBytes(converters.hexStringToByteArray(request.bytes), request.secretPhrase));
var ret = {};
ret.signature = out;
retmsg(JSON.stringify(ret));
retmsg(JSON.stringify(ret), cb);
}
else if(request.method == "createToken")
{
var out = createToken(request.data, request.secretPhrase);
var ret = {};
ret.token = out;
retmsg(JSON.stringify(ret));
retmsg(JSON.stringify(ret), cb);
}
else if(request.method == "parseToken")
{
var out = parseToken(request.token, request.data);
retmsg(JSON.stringify(out));
retmsg(JSON.stringify(out), cb);
}
console.log(request);
else
{
retmsg('{"error":"method not found"}', cb);
}
}


if (typeof message_event.data === 'string') {
for (var type in defaultMessageTypes) {
Expand Down Expand Up @@ -464,6 +472,8 @@ var common = (function() {
hideModule: hideModule,
removeModule: removeModule,
logMessage: logMessage,
postMessage: postMessage,
handleMessage: handleMessage,
updateStatus: updateStatus
};

Expand Down
17 changes: 17 additions & 0 deletions handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,3 +1214,20 @@ int HandleSuperNET(struct PP_Var params,struct PP_Var *output,const char **out_e
RESPONSE_STRING(retstr);
return 0;
}

int HandleJS(struct PP_Var params, struct PP_Var* output, const char** out_error) {
PostMessage("JS?");
CHECK_PARAM_COUNT(js, 2);
PARAM_STRING(0, jsonstr);
PARAM_STRING(1, ptr);

int64_t nptr = strtoll(ptr, NULL, 10);

char * addr = (char *)nptr;

strcpy(addr, jsonstr);

CREATE_RESPONSE(js);
RESPONSE_STRING(ptr);
return 0;
}
1 change: 1 addition & 0 deletions handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ int HandleConnect(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleSend(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleRecv(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleClose(struct PP_Var params, struct PP_Var* out, const char** error);
int HandleJS(struct PP_Var params, struct PP_Var* out, const char** error);

#endif /* HANDLERS_H_ */
6 changes: 0 additions & 6 deletions js/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
else SPNAPI.submitRequest();
});

$(".submit_api_request").on("click", function () {

SPNAPI.submitRequest();

});

$(".clear-response").on("click", function () {

$(".hljs").html("JSON response");
Expand Down
49 changes: 49 additions & 0 deletions js/jay.min.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,5 +225,3 @@ var SPNAPI = (function(SPNAPI, $, undefined) {

return SPNAPI;
}(SPNAPI || {}, jQuery));


1 change: 1 addition & 0 deletions js/sites.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var SPNAPI = (function(SPNAPI, $, undefined) {
$(".json_submit_url").html("");
$(".api_formfill").html("");
$(".api-panel-title").html("Panel Title");
SPNAPI.page = page;

$('.navigation[data-page=' + page + ']').addClass('active');

Expand Down
13 changes: 13 additions & 0 deletions nacl_io_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ static FuncNameMapping g_function_map[] = {
{"send", HandleSend},
{"recv", HandleRecv},
{"close", HandleClose},
{"js", HandleJS},
{NULL, NULL},
};

Expand Down Expand Up @@ -683,6 +684,18 @@ void msleep(uint32_t milliseconds);
void *SuperNET(void *threads)
{
static const char *argv[2] = { "127.0.0.1" }; // int32_t sock2;


// the code to reqeust from js...
/*char * dest=malloc(100);
strcpy(dest, "\0");
PostMessage("{\"pointer\":\"%u\",\"method\":\"NxtAPI\",\"requestType\":\"getTime\",\"param\":\"{}\"}",dest);
while(dest[0] == '\0')
{
msleep(100);
}
PostMessage("Response: %s", dest);*/

SuperNET_init(1,argv);
while ( 1 )
{
Expand Down
1 change: 1 addition & 0 deletions pnacl/Release/dir.stamp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Directory Stamp
Binary file modified tools/getos.pyc
Binary file not shown.
Binary file modified tools/oshelpers.pyc
Binary file not shown.