libkernel
Advanced tools
Comparing version 0.0.3 to 0.0.4
export { sayHello, sayGoodbye } from './hello-world'; | ||
export { kernelBridgeInit, kernelBridgeRequestTest } from './messages'; | ||
export { init, testMessage } from './messages'; |
export { sayHello, sayGoodbye } from './hello-world'; | ||
export { kernelBridgeInit, kernelBridgeRequestTest } from './messages'; | ||
export { init, testMessage } from './messages'; |
@@ -1,2 +0,2 @@ | ||
export declare function kernelBridgeInit(): void; | ||
export declare function kernelBridgeRequestTest(): void; | ||
export declare function init(): void; | ||
export declare function testMessage(): Promise<unknown>; |
@@ -1,7 +0,9 @@ | ||
// kernelBridgeInit will add an event listener for messages from the kernel | ||
// bridge. | ||
// TODO: Need to write the nonce framework. | ||
var nextNonce = 0; | ||
var queries = new Object(); | ||
// init will add an event listener for messages from the kernel bridge. | ||
// | ||
// TODO: Init should check whether the bridge exists and throw an error if it | ||
// does not. | ||
export function kernelBridgeInit() { | ||
// does not. Ideally init can tell if there's a browser extension. | ||
export function init() { | ||
window.addEventListener("message", function (event) { | ||
@@ -14,17 +16,24 @@ if (!("data" in event) || !("method" in event.data)) { | ||
} | ||
console.log("got message from bridge"); | ||
console.log("got message from bridge\n", event, "\n", event.data); | ||
}); | ||
} | ||
// kernelBridgeRequestTest will send a message to the bridge asking for a | ||
// kernel test. | ||
// kernelRequestTest will send a message to the bridge asking for a kernel | ||
// test. | ||
// | ||
// TODO: Function should know if the bridge exists and if the init worked. | ||
export function kernelBridgeRequestTest() { | ||
window.postMessage({ | ||
method: "kernelMessage", | ||
nonce: 1, | ||
kernelMessage: { | ||
kernelMethod: "requestTest", | ||
}, | ||
}, window.location.origin); | ||
// | ||
// TODO: Need to block until kenrel is loaded. | ||
export function testMessage() { | ||
return new Promise(resolve => { | ||
let nonce = nextNonce; | ||
nextNonce++; | ||
queries[nonce] = resolve; | ||
window.postMessage({ | ||
method: "kernelMessage", | ||
nonce, | ||
kernelMessage: { | ||
kernelMethod: "requestTest", | ||
}, | ||
}, window.location.origin); | ||
}); | ||
} |
{ | ||
"name": "libkernel", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "helper library to interact with the skynet kernel", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
1947
52