Integrate signalhub into the server

parent d3724543
# Hypha Spike: Multiwriter 1
Note: Signalhub is now integrated into this spike and is automatically run on port 444 over TLS. You do not have to run a separate server yourself.
[Blog post](https://ar.al/2019/01/22/hypha-spike-multiwriter-1/)
Based on [Hypha Spike: DAT 1](https://source.ind.ie/hypha/spikes/dat-1)
......@@ -245,7 +245,7 @@ function generateKeys() {
// Also join a WebRTC swarm so that we can peer-to-peer replicate
// this hypercore (browser to browser).
const webSwarm = swarm(signalhub(nodeDiscoveryKeyInHex, ['https://localhost:445']))
const webSwarm = swarm(signalhub(nodeDiscoveryKeyInHex, ['https://localhost:444']))
webSwarm.on('peer', function (remoteWebStream) {
console.log(`WebSwarm [peer for ${nodeReadKeyInHex} (discovery key: ${nodeDiscoveryKeyInHex})] About to replicate.`)
......@@ -268,7 +268,7 @@ function generateKeys() {
//
// TEST
//
const NUMBER_TO_APPEND = 100
const NUMBER_TO_APPEND = 3
let counter = 0
const intervalToUpdateInMS = 500
......
......@@ -12,6 +12,8 @@ const ram = require('random-access-memory')
const hyperdb = require('hyperdb')
const hyperswarm = require('@hyperswarm/network')
const signalHubServer = require('signalhub/server')
const budo = require('budo')
const babelify = require('babelify')
......@@ -19,6 +21,25 @@ const router = express.Router()
const hyperdbs = {}
// Create secure signalhub server.
const signalHub = signalHubServer({
key: fs.readFileSync('server/localhost-key.pem'),
cert: fs.readFileSync('server/localhost.pem')
})
signalHub.on('subscribe', channel => {
console.log('[Signal Hub] Subscribe: ', channel)
})
signalHub.on('broadcast', (channel, message) => {
console.log('[Signal Hub] Broadcast: ', channel, message.length)
})
signalHub.listen(444, 'localhost', () => {
console.log(`[Signal Hub] Listening on port ${signalHub.address().port}.`)
})
// Create secure development web server via budo.
const server = budo('client/index.js', {
live: false,
port: 443,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment