You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Don't use public trackers in production](#dont-use-public-trackers-in-production)
6
7
-[How to achieve better P2P ratio for live streams?](#how-to-achieve-better-p2p-ratio-for-live-streams)
@@ -20,6 +21,8 @@ Table of contents:
20
21
Few [public trackers](https://openwebtorrent.com/) are configured in the library by default for easy development and testing but [don't use public trackers in production](#dont-use-public-trackers-in-production).
21
22
22
23
Any compatible WebTorrent tracker works for `P2P Media Loader`:
24
+
25
+
-[Aquatic](https://github.com/greatest-ape/aquatic) - A high-performance BitTorrent tracker written in Rust.
23
26
-[wt-tracker](https://github.com/Novage/wt-tracker) - high-performance WebTorrent tracker by Novage that uses [uWebSockets.js](https://github.com/uNetworking/uWebSockets.js) for I/O.
24
27
-[bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker) - tracker from WebTorrent project that uses Node.js I/O
25
28
@@ -32,60 +35,29 @@ That is why they can't be used in production environments. Consider running your
32
35
33
36
## How to achieve better P2P ratio for live streams?
34
37
35
-
The default configuration works best for live streams with 15-20 segments in the playlist. The segments duration sohould be about 5 seconds.
38
+
The default configuration works best for live streams with 15-20 segments in the playlist. The segments duration should be about 5 seconds.
36
39
37
40
## How to achieve better P2P ratio for VOD streams?
38
41
39
-
An example of a good configuration tested in production for a VOD stream with segments 20 seconds long each:
42
+
An example of a good configuration tested in production for a VOD stream with segments 10 seconds long each:
40
43
41
44
```javascript
42
-
constconfig= {
43
-
segments:{
44
-
// number of segments to pass for processing to P2P algorithm
45
-
forwardSegmentCount:50, // usually should be equal or greater than p2pDownloadMaxPriority and httpDownloadMaxPriority
46
-
},
47
-
loader:{
45
+
{
46
+
constconfig= {
48
47
// how long to store the downloaded segments for P2P sharing
49
-
cachedSegmentExpiration:86400000,
48
+
cachedSegmentExpiration:86400000,
50
49
// count of the downloaded segments to store for P2P sharing
51
-
cachedSegmentsCount:1000,
52
-
53
-
// first 4 segments (priorities 0, 1, 2 and 3) are required buffer for stable playback
54
-
requiredSegmentsPriority:3,
55
-
56
-
// each 1 second each of 10 segments ahead of playhead position gets 6% probability for random HTTP download
57
-
httpDownloadMaxPriority:9,
58
-
httpDownloadProbability:0.06,
59
-
httpDownloadProbabilityInterval:1000,
60
-
61
-
// disallow randomly download segments over HTTP if there are no connected peers
62
-
httpDownloadProbabilitySkipIfNoPeers:true,
63
-
64
-
// P2P will try to download only first 51 segment ahead of playhead position
65
-
p2pDownloadMaxPriority:50,
66
-
67
-
// 1 second timeout before retrying HTTP download of a segment in case of an error
68
-
httpFailedSegmentTimeout:1000,
69
-
70
-
// number of simultaneous downloads for P2P and HTTP methods
71
-
simultaneousP2PDownloads:20,
72
-
simultaneousHttpDownloads:3,
73
-
74
-
// enable mode, that try to prevent HTTP downloads on stream start-up
75
-
httpDownloadInitialTimeout:120000, // try to prevent HTTP downloads during first 2 minutes
76
-
httpDownloadInitialTimeoutPerSegment:17000, // try to prevent HTTP download per segment during first 17 seconds
77
-
78
-
// allow to continue aborted P2P downloads via HTTP
79
-
httpUseRanges:true,
80
-
}
81
-
};
82
-
83
-
constengineHlsJs=newp2pml.hlsjs.Engine(config);
50
+
cachedSegmentsCount:1000,
51
+
// number of simultaneous downloads for P2P methods
52
+
simultaneousP2PDownloads:20,
53
+
};
54
+
}
84
55
```
85
56
86
57
## What are the requirements to share a stream over P2P?
87
58
88
59
The requirements to share a stream over P2P are:
60
+
89
61
- The stream should have the same swarm ID on all the peers. Swarm ID is equal to the stream master manifest URL without query parameters by default. If a stream URL is not the same for different peers you can set the swarm ID manually [using configuration](#how-to-manually-set-swarm-id).
90
62
- The master manifest should have the same number of variants (i.e. qualities) in the same order on all the peers. URLs of the variant playlists don't matter.
91
63
- Variants should consist of the same segments under the same sequence numbers (see #EXT-X-MEDIA-SEQUENCE for HLS) on all the peers. URLs of the segments don't matter.
@@ -98,7 +70,6 @@ P2P Media Loader implements approach of P2P assisted video delivery. It means th
98
70
99
71
For example for 10 peers in the best case the maximum possible P2P ratio is 90% if a stream was downloaded from the source only once.
100
72
101
-
102
73
## What happens if there are no peers on a stream?
103
74
104
75
P2P Media Loader downloads all the segments from HTTP(S) source in this case. It should not perform worse than a player configured without P2P at all.
@@ -107,55 +78,113 @@ P2P Media Loader downloads all the segments from HTTP(S) source in this case. It
The easiest way is to subscribe to P2P [events](https://github.com/Novage/p2p-media-loader/tree/master/p2p-media-loader-core#loaderoneventssegmentloaded-function-segment-peerid-) and log them:
159
+
The easiest way is to subscribe to P2P [events](https://novage.github.io/p2p-media-loader/docs/v1.0/types/p2p_media_loader_core.CoreEventMap.html) and log them:
**P2P Media Loader** is an open-source JavaScript library that uses features of modern web browsers (i.e. HTML5 video and WebRTC) to deliver media over P2P and do playback via integrations with many popular HTML5 video players. It doesn’t require any web browser plugins or add-ons to function (see the [demo](http://novage.com.ua/p2p-media-loader/demo.html)).
5
+
**P2P Media Loader** is an open-source JavaScript library that leverages modern web browser features, such as HTML5 video and WebRTC, to enable media delivery over peer-to-peer (P2P) networks. It integrates smoothly with many popular HTML5 video players and works entirely without browser plugins or add-ons. Experience it in action with the [demo](http://novage.com.ua/p2p-media-loader/demo.html).
7
6
8
-
It allows creating Peer-to-Peer network (also called P2P CDN or P2PTV) for traffic sharing between users (peers) that are watching the same media stream live or VOD over HLS or MPEG-DASH protocols.
7
+
This library enables the creation of a huge P2P mesh network, also known as P2P CDN or P2PTV, which allows traffic sharing among users who are simultaneously viewing the same live or VOD stream via HLS or MPEG-DASH protocols.
9
8
10
-
It significantly reduces traditional CDN traffic and cost while delivering media streams to more users.
9
+
By leveraging P2P technology, it greatly reduces reliance on traditional CDN resources, lowers costs, and enhances the ability to deliver media streams to a larger audience.
*[WebTorrent](https://github.com/webtorrent/webtorrent) - streaming torrent client for the web https://webtorrent.io
13
+
-[Aquatic](https://github.com/greatest-ape/aquatic): A high-performance BitTorrent tracker written in Rust.
14
+
-[wt-tracker](https://github.com/Novage/wt-tracker): A high-performance WebTorrent tracker.
15
+
-[WebTorrent](https://github.com/webtorrent/webtorrent): A streaming torrent client designed for web use. Learn more at [WebTorrent.io](https://webtorrent.io).
16
16
17
17
## Useful links
18
18
19
19
-[P2P development, support & consulting](https://novage.com.ua/)
@@ -39,7 +32,7 @@ It significantly reduces traditional CDN traffic and cost while delivering media
39
32
- Supports live and VOD streams over HLS or MPEG-DASH protocols
40
33
- Supports multiple HTML5 video players and engines:
41
34
- Engines: Hls.js, Shaka Player
42
-
- Video players: JWPlayer, Clappr, Flowplayer, MediaElement, VideoJS, Plyr, DPlayer, Player.js and others
35
+
- Video players: [Vidstack](https://www.vidstack.io/), [Clappr](http://clappr.io/), [MediaElement](https://www.mediaelementjs.com/), [Plyr](https://plyr.io/), [DPlayer](https://dplayer.diygod.dev/), [OpenPlayerJS](https://www.openplayerjs.com/), and others that support Hls.js or Shaka video engines. These players can be integrated via custom integration with the library API.
43
36
- Supports adaptive bitrate streaming of HLS and MPEG-DASH protocols
44
37
- No need in server-side software. By default **P2P Media Loader** uses publicly available servers:
45
38
- STUN servers - [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e)
@@ -52,6 +45,7 @@ All the components of the P2P network are free and open-source.
52
45

53
46
54
47
**P2P Media Loader** web browser [requirements](#web-browsers-support) are:<br>
48
+
55
49
-**WebRTC Data Channels** support to exchange data between peers
56
50
-**Media Source Extensions** are required by Hls.js and Shaka Player engines for media playback
57
51
@@ -64,28 +58,31 @@ It is possible to run personal WebTorrent tracker using open-source implementati
64
58
65
59
**P2P Media Loader** is configured to use public **STUN** and **WebTorrent** servers by default. It means that it is not required to run any server-side software for the P2P network to function.
66
60
67
-
## How it works
61
+
## How It Works
62
+
63
+
A web browser runs a video player that integrates with the **P2P Media Loader** library. Each instance of the library is referred to as a **peer**, and collectively, many peers form the P2P network.
68
64
69
-
A web browser runs a video player integrated with **P2P Media Loader** library. An instance of **P2P Media Loader** is called **peer**. Many peers form the P2P network.
65
+
**P2P Media Loader** initially downloads media segments over HTTP(S) from a source server or CDN to start media playback quickly. If no peers are available, it continues to download segments over HTTP(S), similar to a traditional media stream.
70
66
71
-
**P2P Media Loader** starts to download initial media segments over HTTP(S) from source server or CDN. This allows beginning media playback faster.
72
-
Also, in case of no peers, it will continue to download segments over HTTP(S) that will not differ from traditional media stream download over HTTP.
67
+
Subsequently, **P2P Media Loader** transmits media stream details and connection information, such as ICE candidates, to WebTorrent trackers. These trackers provide a list of other peers who are accessing the same media stream.
73
68
74
-
After that **P2P Media Loader** sends media stream details and its connection details (ICE candidates) to WebTorrent trackers
75
-
and obtains from them list of other peers that are downloading the same media stream.
69
+
**P2P Media Loader** then connects with these peers to download additional media segments and simultaneously shares segments that it has already downloaded.
76
70
77
-
**P2P Media Loader** connects and starts to download media segments from the obtained peers as well as sharing already downloaded segments to them.
71
+
Periodically, random peers in the P2P swarm download new segments over HTTP(S) and distribute them to others via P2P.
78
72
79
-
From time to time random peers from the P2P swarm download new segments over HTTP(S) and share them to others over P2P.
73
+
## Web browsers support
80
74
81
-
## Limitations
75
+
**All features listed below are fully supported across the following browsers:**
82
76
83
-
Only one media track is delivered over P2P. If video and audio tracks in HLS or MPEG-DASH go separately, just video is going to be shared over the P2P network.
0 commit comments