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

Adding browser example with communication between peers #616

Closed
wants to merge 19 commits into from
Closed

Adding browser example with communication between peers #616

wants to merge 19 commits into from

Conversation

svdo
Copy link

@svdo svdo commented Apr 24, 2020

I'm trying to use libp2p-js to communicate between browser windows. I'm having some issues, so I thought I'd add an example of what I'm trying to accomplish.

This example is NOT working. You can only send one single message to the other peer, then it stops working.

Can somebody help me by telling me what I'm doing wrong? Thanks!!!

examples/chat-in-the-browser/index.js Outdated Show resolved Hide resolved
examples/chat-in-the-browser/index.js Outdated Show resolved Hide resolved
@alexcastillo
Copy link

Hey @svdo,

Thanks for putting this example together. I had the same question.

Assuming we get past this issue:

If you deploy this example to a remote server (e.g. https://example.com), are you able to get the peers to connect? I tried with a very similar example and the peers discover each other but they don't connect.

@jacobheun, any ideas?

@jacobheun
Copy link
Contributor

I tried with a very similar example and the peers discover each other but they don't connect.

@alexcastillo Do you have code or logs to look at? There could be a number of reasons causing the issue. The quickest thing to maybe check is increasing the minConnections configuration for the connection manager, https://github.com/libp2p/js-libp2p/blob/v0.27.7/doc/CONFIGURATION.md#configuring-connection-manager. If it's 0 (default), you won't auto dial peers. Try with a min of 25 and a max of 50 for browser nodes to see if that helps.

If that doesn't help can you open a new issue to discuss. I want to avoid splintering the discussion here.

@alexcastillo
Copy link

Thanks @jacobheun. Your suggestion didn't work so I'll go ahead an open a new issue later today. Thank you!

@svdo
Copy link
Author

svdo commented Apr 28, 2020

By the way, I've been doing my work in TypeScript, so as a bonus I converted this example to TypeScript as well; may it help others :)

@svdo svdo marked this pull request as ready for review April 29, 2020 09:41
@svdo svdo changed the title [wip] Adding browser example with communication between peers Adding browser example with communication between peers Apr 29, 2020
@svdo
Copy link
Author

svdo commented Apr 29, 2020

I think this example is pretty much done. Do you want to merge it @jacobheun?

@svdo
Copy link
Author

svdo commented Apr 29, 2020

(I think the build errors and coverage change are not due to this PR?)

@jacobheun
Copy link
Contributor

@svdo our plan is to create a repository for registering/cataloging community created examples / projects like this, it's being tracked at #512.

As that's not yet ready, what I'd like to do is have you add this example to a standalone repo, and then add a link and brief summary of it to the examples readme here. Once we create the community repo/site, I can then add yours and any other examples that get added in the mean time there.

@svdo
Copy link
Author

svdo commented Apr 29, 2020

Hmm I was hoping that your suggestion was going to end with something like "since we're not there yet we will merge this example and move it later" or something like that. I thought maybe this example adds enough value to justify being here. Reason I'm saying this is that I don't see myself converting and maintaining this code in the future, so it would be "instant legacy".

@jacobheun
Copy link
Contributor

The project I mentioned is still going to just reference projects/examples, not include them directly. I appreciate that you likely won't be able to maintain the example with new releases, but there is still value to having it and we can add metadata to the version it does support. We will eventually integrate some examples and projects into CI testing and help to keep those updated, but we unfortunately don't have the bandwidth to directly support updating an increasing list of them.

If this still isn't something you're interested in considering we could look at amending the existing browser example to include dialing and sending data.

@svdo
Copy link
Author

svdo commented Apr 29, 2020

Right, I completely understand that you're also mindful of the "bandwidth thing" :) I'll go ahead and post it to a repo of my own. I'll add the link here and close the pull request afterwards.

@svdo
Copy link
Author

svdo commented Apr 30, 2020

Ok I moved the example to its own repo, here you go: https://github.com/svdo/js-libp2p-example-chat-in-the-browser.

@svdo svdo closed this Apr 30, 2020
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

Successfully merging this pull request may close these issues.

3 participants