libkernel
Advanced tools
Comparing version 0.0.17 to 0.0.18
@@ -0,1 +1,14 @@ | ||
// log provides syntactic sugar for the logging functions. This function is | ||
// intended to be wrapped by whatever page imports it so that the logSource is | ||
// different for each page. The first argument is the name of the page, the | ||
// second argument is the message type, and the remaining arguments are the | ||
// same as any inputs you would pass to console.log. | ||
var log = function (err, ...inputs) { | ||
if (err === true) { | ||
console.error("[libkernel] ERROR: ", ...inputs); | ||
} | ||
else { | ||
console.log("[libkernel] ", ...inputs); | ||
} | ||
}; | ||
var initialized; | ||
@@ -33,3 +46,3 @@ var bridgeExists; | ||
if (bridgeExists !== false) { | ||
console.log("[libkernel] bridge confirmed to be available"); | ||
log(false, "bridge confirmed to be available"); | ||
bridgeExists = true; | ||
@@ -39,3 +52,3 @@ bridgeAvailable.resolve(); | ||
else { | ||
console.error("[libkernel] received late signal from bridge"); | ||
log(true, "received late signal from bridge"); | ||
} | ||
@@ -48,3 +61,3 @@ } | ||
if (!("nonce" in event.data) || !(event.data.nonce in queries)) { | ||
console.error("[libkernel] nonce of kernelResponse not found\n", event, "\n", queries); | ||
log(true, "nonce of kernelResponse not found\n", event, "\n", queries); | ||
return; | ||
@@ -56,3 +69,3 @@ } | ||
if (!("resp" in event.data) || !("err" in event.data)) { | ||
console.error("[libkernel] malformed kernel response\n", event); | ||
log(true, "malformed kernel response\n", event); | ||
return; | ||
@@ -68,6 +81,6 @@ } | ||
else { | ||
console.error("[libkernel] received malformed response from bridge\n", event); | ||
log(true, "received malformed response from bridge\n", event); | ||
} | ||
} | ||
// handleMessage will handle a message from the kernel, using the reponse to | ||
// handleMessage will handle a message from the kernel, using the response to | ||
// resolve the appropriate promise in the set of queries. | ||
@@ -114,3 +127,3 @@ function handleMessage(event) { | ||
bridgeAvailable.reject("bridge unavailable, need skynet extension"); | ||
console.error("[libkernel] bridge not found"); | ||
log(true, "bridge did not respond after 2 seconds"); | ||
} | ||
@@ -117,0 +130,0 @@ }, 2000); |
import { init, postKernelMessage } from './init'; | ||
// testMessage will send a test message to the kernel, ensuring that basic | ||
// kernel communications are working. | ||
// | ||
// NOTE: Anyone looking to extend libkernel can use this function as an example | ||
// of how messaging works within libkernel. | ||
export function testMessage() { | ||
@@ -8,0 +5,0 @@ // Retrun a promise that will resolve when a response is received from |
{ | ||
"name": "libkernel", | ||
"version": "0.0.17", | ||
"version": "0.0.18", | ||
"description": "helper library to interact with the skynet kernel", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
6549
168