Skip to content

Instantly share code, notes, and snippets.

@benzmuircroft
Last active December 16, 2023 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benzmuircroft/8918fde8c91af13fb0e0ec23e5fe58f0 to your computer and use it in GitHub Desktop.
Save benzmuircroft/8918fde8c91af13fb0e0ec23e5fe58f0 to your computer and use it in GitHub Desktop.
make a folder and put these 2 files. then `npm install`, `node test.js`.
{
"dependencies": {
"hyperdown": "github:benzmuircroft/hyperdown"
}
}
;(async function() {
const Keychain = (await import('keypear')).default;
const sk = new Keychain().get();
const server = await require('hyperdown')({
uniqueKeyPair: sk,
folderName: 'topic',
testFolder: 'server',
isServer: true,
onClientConsumedEvents:
function(remotePublicKey, eventsArray) {
// do something ...
// console.log('server: client used the event', remotePublicKey, eventsArray);
}
});
const ck = new Keychain().get();
const client = await require('hyperdown')({
uniqueKeyPair: ck,
folderName: 'topic',
testFolder: 'client',
eventHandler:
function(id, data, cb) {
// do something ...
// console.log('client: event from server', id, data, cb);
// cb(id, true);
}
});
// await server.addEvent(ck.publicKey, JSON.stringify({ prize: 500, game: 'robots' })); // give a client an event
await server.put('server', 'h');
await client.put('client', 'a');
await server.get('client');
await client.get('server');
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment