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

I made a createServer equivalent for browsers #1522

Open
jimmywarting opened this issue Oct 4, 2018 · 13 comments
Open

I made a createServer equivalent for browsers #1522

jimmywarting opened this issue Oct 4, 2018 · 13 comments

Comments

@jimmywarting
Copy link
Contributor

@jimmywarting jimmywarting commented Oct 4, 2018

With the power of service worker:
https://github.com/jimmywarting/webtorrent-server-browser

Have a look if it's something of an intresse


the catch is you need to have the main window running to pipe a file stream to the service worker.
Would ofc be better if the service worker where able to read directly from say indexedDB or some storage layer and wouldn't need to communicate thought postMessage

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Oct 4, 2018

It's similar to how my StreamSaver lib works...

@stale

This comment has been minimized.

Copy link

@stale stale bot commented Jan 2, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Jan 2, 2019
@DiegoRBaquero

This comment has been minimized.

Copy link
Member

@DiegoRBaquero DiegoRBaquero commented Jan 3, 2019

Hadn't seen this, it's a really nice experiment. Do you maybe want to submit it to the list of things built with WebTorrent?

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Jan 3, 2019

Do you maybe want to submit it to the list of things built with WebTorrent?

Nah, it's not even a "thing" (so called project, module or a service) just a experiment as you said. (PoC)

What I perhaps would like to see is if it would be worth considering implementing this somehow maybe even replace the existing way of how media is played/streamed today. The benefit of my method is that you will take off lots of work from the main thread, keeping the main thread more responsive. You will also get more support for other containers like webm, mp4, ogg etc out of the box.

You would be able to get rid of this packages then:

  • mp4-box-encoding
  • mp4-stream
  • mediasource
  • render-media
  • videostream
  • range-slice-stream
  • stream-to-blob-url

what i have built is just a proof of concept... so it's not really a plug and play thing that you can add to webtorrent to make it work out of the box

@stale stale bot removed the stale label Jan 3, 2019
@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Jan 3, 2019

IMHO i think videostream and render-media and all of that is out of the scope of webtorrent. So I think that should be removed. it's not necessary for sharing things p2p

But serving the files in a streaming fashion from the torrent client isn't and that is what createServer is doing. and it just so happen to support streaming videos as well

@stale

This comment has been minimized.

Copy link

@stale stale bot commented Apr 3, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@WatchSoMuch

This comment has been minimized.

Copy link

@WatchSoMuch WatchSoMuch commented Jun 19, 2019

Its great idea Jimmy, have you tested it for streaming?
Is there any sample or code example how to set it u?

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Jun 19, 2019

  1. You need to set up the service worker (sw.js) on your own domain that listens to any request made by the website

  2. Since WebTorrent only runs in main thread it also has to have something to communicate too and you would also need to patch the createServer stuff so it works with service worker instead.

after that it's as simple as just adding

video.src = `./webtorrent/${torrent.infoHash}/${torrent.files[5].path}`

Is there any sample or code example how to set it u?

Did you even bother looking in the repo for demo and some code? There is not much else going on in that repo like compiling and doing other unrelated things. Looking at 3 files is not much.
The readme links to a demo that streams a video
https://jimmywarting.github.io/webtorrent-server-browser/

the browser handles the seeking. When you seek it will make a partial request and map that to the byte offset that it needs to download

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Jun 19, 2019

Like mention earlier: it's just a PoC not some pluggable plugin you can just add since you need to configure a service worker and it patches WebTorrent.

The idea was to showcase that

  1. it work
  2. you don't need all those other dependencies to play mp4 files
  3. you can have more supported video formats natively

... so that i could catch somebody's attention/interest and work towards implementing something like this into webtorrent itself

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Jun 19, 2019

if there where maybe one thing i would have changed about this old code is that i would have used transferable streams instead of using MessageChannel

@WatchSoMuch

This comment has been minimized.

Copy link

@WatchSoMuch WatchSoMuch commented Aug 7, 2019

I'm surprized ferros never commented on this, Its really like to know how does hi thinks about it?
Is there any reason main webtorrent didn't do this instead? why to use all those packages then?
Is there any browser incompatibility streaming like these? and many other questions

@jimmywarting

This comment has been minimized.

Copy link
Contributor Author

@jimmywarting jimmywarting commented Aug 7, 2019

@WatchSoMuch

I'm surprized ferros never commented on this, Its really like to know how does hi thinks about it?

@feross wants to have it in a service worker but it is currently not possible since service worker are sort lived and don't have WebRTC.

It's possible to work around it by using eg transferable-readable-whatwg-streams (or just messageChannel) and pipe it to a WebRTCPeerConnection and have the webrtc stuff in the main thread and the rest of the torrent application in the service worker.

Is there any reason main webtorrent didn't do this instead?
why to use all those packages then?

for reasons stated above

Is there any browser incompatibility streaming like these? and many other questions

I'm working on a fork of webtorrent and many submoddules that is stripped down to only work in the browser. it's more lightweight and somewhat faster. (less prone to browser freeze, use less memory and CPU) works both in main thread and inside service worker - it has this kind of built in "server" to give all chunks directly from indexedDB directly instead of asking main thread for them, weights in at around ~100kb something (still very much in developing stage for now)
I started working on this fork when @feross went idle and wasn't so much involved in webtorrent due to burnout, but now he is back in business and working with Brave. I see now that he is focusing much on Dependency hygiene (#1687) and trying to reduce the dependency tree
he has gotten it down 10kb so far. (i have some few tip and tricks but he have to make a big effort to be able to remove some large dependencies)

i wonder if he would wants to collaborate on some submodules i have created.
If i should create some pull request to webtorrent and perhaps try to merge them together. so we have one good single torrent client
Or if it would be good to have two separate competing web torrent clients to be somewhat competing to work towards a being better then the other

@WatchSoMuch

This comment has been minimized.

Copy link

@WatchSoMuch WatchSoMuch commented Aug 7, 2019

Nice, thanks for your answer, although this was too technical for me to completely understand, but it feels like good things are going to happen, I'm not familiar with browser service worker, but Im wondering if the videostream package is doing anything special that if we lose that anything bad happens?
I think webtorrent needs to be separated to a core and webtorrentStream if those packages are necessary

@feross feross reopened this Aug 7, 2019
@stale stale bot removed the stale label Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.