Created
September 4, 2017 03:19
-
-
Save balbany/f7c968b9b2c18aa81e2350972c5c3946 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import xs from 'xstream'; | |
import {adapt} from '@cycle/run/lib/adapt'; | |
import Room from 'ipfs-pubsub-room'; | |
export function makeIPFSRoomDriver(roomName) { | |
function ipfsRoomDriver(outgoing$) { | |
//Bootstrap the IPFS node | |
var ipfs = new window.Ipfs({ | |
repo: 'ipfs/pubsub-demo/' + Math.random(), | |
EXPERIMENTAL: { | |
pubsub: true // required, enables pubsub | |
} | |
}) | |
outgoing$.addListener({ | |
next: outgoing => { | |
let room = Room(ipfs, roomName); | |
room.broadcast(outgoing); | |
}, | |
error: () => {}, | |
complete: () => {}, | |
}); | |
const incoming$ = xs.create({ | |
start: listener => { | |
ipfs.once('ready', () => { | |
let room = Room(ipfs, roomName); | |
room.on('message', (message) => { | |
listener.next(message); | |
}) | |
}); | |
}, | |
stop: () => {}, | |
}); | |
return adapt(incoming$); | |
} | |
return ipfsRoomDriver | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment