Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
wip: get websockets to work in the browser
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Nov 8, 2016
1 parent 661fe73 commit e6344b1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
27 changes: 15 additions & 12 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,32 @@
const gulp = require('gulp')
const multiaddr = require('multiaddr')
const Node = require('libp2p-ipfs').Node
const Peer = require('peer-info')
const Id = require('peer-id')
const PeerInfo = require('peer-info')
const PeerId = require('peer-id')
const pull = require('pull-stream')

const sigServer = require('libp2p-webrtc-star/src/signalling-server')
let sigS

let node
const rawPeer = require('./test/peer.json')

gulp.task('libnode:start', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
Id.createFromPrivKey(rawPeer.privKey, (err, id) => {
let count = 0
const ready = () => ++count === 2 ? done() : null

sigS = sigServer.start(15555, ready)

PeerId.createFromJSON(rawPeer, gotId)

function gotId (err, pid) {
if (err) {
return done(err)
}
const peer = new PeerInfo(pid)

const peer = new Peer(id)
peer.multiaddr.add(mh)
const ma = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
peer.multiaddr.add(ma)

node = new Node(peer)
node.start(() => {
Expand All @@ -29,12 +37,7 @@ gulp.task('libnode:start', (done) => {
})
ready()
})

let count = 0
const ready = () => ++count === 2 ? done() : null

sigS = sigServer.start(15555, ready)
})
}
})

gulp.task('libnode:stop', (done) => {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ exports.Node = function Node (pInfo, pBook) {
// if we have `webrtc-star` addrs, then add
// the WebRTCStar transport
const wstar = new WebRTCStar()

if (wstar.filter(this.peerInfo.multiaddrs).length > 0) {
this.swarm.transport.add('wstar', wstar)
wstar.discovery.on('peer', (peerInfo) => {
Expand Down
3 changes: 1 addition & 2 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

const w = require('webrtcsupport')

require('./websockets-only')
// require('./websockets-only')

if (w.support) {
require('./webrtc-star-only')
require('./webrtc-star-and-websockets')
}
Empty file removed test/webrtc-star-and-websockets.js
Empty file.
1 change: 1 addition & 0 deletions test/websockets-only.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('libp2p-ipfs-browser (websockets only)', () => {

before((done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws/ipfs/' + rawPeer.id)

PeerId.createFromPrivKey(rawPeer.privKey, (err, id) => {
if (err) {
return done(err)
Expand Down

0 comments on commit e6344b1

Please sign in to comment.