Created
May 18, 2018 04:04
Star
You must be signed in to star a gist
STREAM Server Snippet
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
const IlpStream = require('ilp-protocol-stream') | |
const createPlugin = require('ilp-plugin') | |
const serverPlugin = createPlugin() | |
const server = await IlpStream.createServer({ | |
plugin: serverPlugin | |
}) | |
server.on('connection', (connection) => { | |
console.log('server got connection') | |
connection.on('stream', (stream) => { | |
console.log(`server got a new stream: ${stream.id}`) | |
// Set the maximum amount of money this stream can receive | |
stream.setReceiveMax(10000) | |
// Handle incoming money | |
stream.on('money', (amount) => { | |
console.log(`server stream ${stream.id} got incoming payment for: ${amount}`) | |
}) | |
// Handle incoming data | |
stream.on('data', (chunk) => { | |
console.log(`server stream ${stream.id} got data: ${chunk.toString('utf8')}`) | |
}) | |
}) | |
}) | |
// These would need to be passed from the server to the client using | |
// some encrypted communication channel (not provided by STREAM) | |
const { destinationAccount, sharedSecret } = server.generateAddressAndSecret() | |
console.log(`server generated ILP address (${destinationAccount}) and shared secret (${sharedSecret.toString('hex')}) for client`) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment