Skip to content

Instantly share code, notes, and snippets.

@okdistribute
Last active January 28, 2019 08:29
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save okdistribute/6c0594ae9fc215d2b750c39e7e4f8973 to your computer and use it in GitHub Desktop.
Save okdistribute/6c0594ae9fc215d2b750c39e7e4f8973 to your computer and use it in GitHub Desktop.
dat with webrtc
var webrtc = require('webrtc-swarm')
var signalhub = require('signalhub')
var hyperdrive = require('hyperdrive')
var memdb = require('memdb')
var pump = require('pump')
var DEFAULT_SIGNALHUBS = 'https://signalhub.mafintosh.com'
var drive = hyperdrive(memdb())
var archive = drive.createArchive()
var swarmKey = 'dat-' + archive.discoveryKey.toString('hex')
var swarm = webrtc(signalhub(swarmKey, DEFAULT_SIGNALHUBS))
swarm.on('peer', function (peer) {
var peer = archive.replicate({
upload: true,
download: true
})
pump(conn, peer, conn)
})
{
"name": "webrtc-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"hyperdrive": "^7.14.2",
"memdb": "^1.3.1",
"pump": "^1.0.2",
"signalhub": "^4.8.0",
"webrtc-swarm": "^2.8.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment