mafintosh / discovery-swarm

A network swarm that uses discovery-channel to find peers
MIT License
374 stars 57 forks source link

Browser support #48

Closed alvesjtiago closed 6 years ago

alvesjtiago commented 6 years ago

Hi, thank you for your work on hypercore, hyperdb and discovery-swarm @mafintosh. I've been trying to setup hyperdb with discovery-swarm on the browser but it seems that with the default settings (tcp enabled) it fails on net.createServer. With utp enabled and tcp disabled it successfully creates the swarm but when calling join it throws Cannot read property 'on' of null because the server (tcp or udp) is null.

Example code for each situation:

1.

import discovery from 'discovery-swarm';
var swarm = discovery()

2.

import discovery from 'discovery-swarm';
var swarm = discovery({
  tcp: false,
  utp: true,
})
swarm.join('9cc3821431bd1609eccf09bfc471a67e230455b2c92899414fd6bdad94f0fe5f')

Is there any way to get discovery-swarm working on the browser? Thank you

joehand commented 6 years ago

Hello! Unfortuantely, discovery swarm does not work in the browser because you cannot make tcp/udp connections directly in browsers. You have to either use an http gateway, websockets, or webrtc-swarm.

alvesjtiago commented 6 years ago

Thank you @joehand.