webtorrent / webtorrent-hybrid

WebTorrent (with WebRTC support in Node.js)
https://webtorrent.io
MIT License
519 stars 98 forks source link

How to implement Webtorrent-hybrid in browser?Any docs? #107

Closed adamwoo2444 closed 5 years ago

adamwoo2444 commented 5 years ago

I am successfully able to use webtorrent-hybrid on nodejs. Is there any documentation available how to implement webtorrent-hybrid on browser?

adamwoo2444 commented 5 years ago

@feross @watson i shall be very thankful to you.If you can help me out. Thanks.

adamwoo2444 commented 5 years ago

@Stiveknx @watson @mvayngrib @Flet @greenkeeperio-bot

SilentBot1 commented 5 years ago

Hi @adamwoo2444,

Webtorrent-hybrid (WTH) utilises tcp/udp sockets to communicate with regular bittorrent clients and also WebRTC connections to speak to WebTorrent clients within NodeJS.

These tcp/udp sockets that WTH uses are unavailable to use within a browser due to the security implications that these would bring.

There is no way currently to use WTH within the browser.

If you have any other questions, please let us know.

Kind regards, Brad

adamwoo2444 commented 5 years ago

Okay. Can you tell me any way that i can stream non wrtc torrents in the browser? Actually, I saw some people are streaming non wrtc torrents in the browser.

If I seed these torrents on webrtc network will they stream on browser?

SilentBot1 commented 5 years ago

Hi @adamwoo2444,

You can cross seed torrents between the networks by having a NodeJS webtorrent-hybrid client seeding the torrent after downloading the torrent or via downloading the torrent and creating a web seed and adding this to the original torrent to initially seed the content within the WebRTC network and this will allow supported video formats to be streamed within the browser.

There are many ways to implement streaming of non-webrtc torrents, with the two I've personally implemented before including, server side transcoding (or remuxing) or seeding-on-demand via webseeds but each of these have their own downsides and implementation issues.

Again, if you have any more questions, please let us know.

Kind regards, Brad

adamwoo2444 commented 5 years ago

Hi @SilentBot1 Thank you so much for the detail information 👍 Do you have any code example? it would be very easy for me to proceed further. Or you can tell me.

mikekok commented 4 years ago

@SilentBot1 hello! I've been reading your replies on this topic and I have some questions. You said that you could stream torrents in the browser by first seeding them in the node.js client. Is there any way to achieve this while the torrent is being downloaded and not completed? How does webtorrent desktop do something similar?

SilentBot1 commented 4 years ago

Hi @mikekok,

Is there any way to achieve this while the torrent is being downloaded and not completed?

By default WebTorrent-Hybrid downloads the full torrent. In order to proxy the individual pieces like requested, you will need to create some custom logic to mimic having the full torrent (or mimic the current torrents availability), even when this isn't the case in order to allow you to download and proxy these pieces to clients.

Alternatively you can utilize / modify the already included torrent.createServer logic available here to create a dynamic WebSeed which is able to proxy between the two networks.

I have a working prototype of the WebSeed proxy but the code is just over two years old and isn't in the best shape at the moment.

How does webtorrent desktop do something similar?

In a high level overview, WebTorrent Desktop uses Electron which provides the Chromium browser the ability to speak with a NodeJS process and thus full access to TCP, UDP and Web sockets in order to be able to communicate with the two individual swarms.

If you have any further questions or would like to discuss this further, please let me know.

Kind regards, Brad Marsden

mikekok commented 4 years ago

@SilentBot1 thank you for your detailed answer.

I'm using electron as well and I'm trying to achieve something similar to webtorrent desktop, but just a really basic version of it (downloading a torrent in the main node.js process and playing the video file in the chromium browser side while it's being downloaded).

Is there any working example available that is easy to understand and work on?

Thank you!

mikekok commented 4 years ago

@SilentBot1 I happened to have a look at torrent-stream and I was wondering if it would be easier to achieve what I'm looking for using this package instead of webtorrent. Webtorrent seems way better for my purpose but I just can't figure out how to make it work in electron with non-WebRTC torrents, unlike torrent-stream, which works for every kind of torrent but doesn't support rendering the content to a video player.

SilentBot1 commented 4 years ago

Hi Mike

The best example of using Webtorrent-Hybrid in an electron application is to look at the WebTorrent-desktop application itself.

Your webtorrent instance will exist within the main electron process and use an IPC channel to speak between the rendering process and the main process (as these are two different processes).

I don't have an amazing understanding of webtorrent-desktop but this should point you in the right direction.

I'll try and look into this further to provide you better parts of the application to look into to understand how it works but currently I'm quite constrained for time.

If you have any more questions in the mean while, please let me know.

Kind regards, Brad Marsden

On Wed, 13 Nov 2019, 18:03 Mike Kokkolios, notifications@github.com wrote:

I happened to have a look at torrent-stream https://github.com/mafintosh/torrent-stream and I was wondering if it would be easier to achieve what I'm looking for using this package instead of webtorrent. Webtorrent seems way better for my purpose but I just can't figure out how to make it work in electron with non-WebRTC torrents, unlike torrent-stream, which works for every kind of torrent but doesn't support rendering the content to a video player.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/webtorrent/webtorrent-hybrid/issues/107?email_source=notifications&email_token=ADS6FYPFVWO3FKX4DZGJPWDQTQ6QNA5CNFSM4IOABIRKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOED7C2TI#issuecomment-553528653, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADS6FYIJRBZ4RI3AI4MXH4LQTQ6QNANCNFSM4IOABIRA .

mikekok commented 4 years ago

I will definitely have a look into its source code and see if I can figure it out.

Thank you for your time, Brad, I appreciate it!

rojerv commented 4 years ago

@mikekok , Hello! is there any progress in resolving the issue? I'm interested too

mikekok commented 4 years ago

@mikekok , Hello! is there any progress in resolving the issue? I'm interested too

Just use peerflix instead of WebTorrent, it's much easier to use for this specific purpose.