Last active
December 16, 2023 16:49
-
-
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`.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"dependencies": { | |
"hyperdown": "github:benzmuircroft/hyperdown" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;(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