Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer connections #78

Open
Deepp0925 opened this issue May 3, 2020 · 0 comments
Open

Peer connections #78

Deepp0925 opened this issue May 3, 2020 · 0 comments

Comments

@Deepp0925
Copy link

Deepp0925 commented May 3, 2020

even though two peers don't share a same room, the still get connected via Libp2p.

how to reproduce
run the code
in new terminal run the same code but change the room topic

const Room = require("ipfs-pubsub-room");
const Libp2p = require("libp2p");
const MPLEX = require("libp2p-mplex");
const SECIO = require("libp2p-secio");
const PUBSUB = require("libp2p-floodsub");
const WebRTCStar = require("libp2p-webrtc-star");
const TCP = require("libp2p-tcp");
const wrtc = require("wrtc");

const main = async () => {
  try {
    const libp2p = await Libp2p.create({
      modules: {
        transport: [TCP, WebRTCStar],
        connEncryption: [SECIO],
        streamMuxer: [MPLEX],
        pubsub: PUBSUB,
      },
      config: {
        transport: {
          WebRTCStar: {
            wrtc,
          },
        },
      },
    });

    const webrtcAddr =
           "/dns4/quiet-lowlands-16063.herokuapp.com/tcp/443/wss/p2p-webrtc-star/";
    libp2p.peerInfo.multiaddrs.add(webrtcAddr);

    await libp2p.start();
    console.log(`libp2p id is ${libp2p.peerInfo.id.toB58String()}`);

    libp2p.on("peer:connect", () => {
      console.log("peer connected");
    });

    libp2p.on("peer:disconnect", () => {
      console.log("peer disconnected");
    });

    const room = new Room(libp2p, "room-name");
    room.on("peer joined", (peer) => {
      console.log("Peer joined the room", peer);
    });

    room.on("peer left", (peer) => {
      console.log("Peer left...", peer);
    });

    // now started to listen to room
   // this never gets fired
    room.on("subscribed", () => {
      console.log("Now connected!");
    });
  } catch (error) {
    console.log("error", error);
  }
};

main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant