novage / p2p-media-loader Goto Github PK
View Code? Open in Web Editor NEWAn open-source engine for P2P streaming of live and on demand video directly in a web browser HTML page
License: Apache License 2.0
An open-source engine for P2P streaming of live and on demand video directly in a web browser HTML page
License: Apache License 2.0
One improvement that can be made is to force the player to start downloading and playing the first segment instead of the last one or the one before.
That can lead to latency problems but that's not a big issue i guess , if the playlist have 6 segments, 10 seconds each, if you force the player to start from the first segment, that gives the P2P-media-loader
enough time (50 seconds) to download the rest segments through P2P, instead of downloading the last one or the one before (gives the library 10 to 20 seconds to download the next segment through P2P).
there is no way to do that in Clappr
as i know, the only work around i found is to seek back he first segment like this:
events: {
onPlay: function() {
if (player._hasSeek) {
return
}
player.seek(0);
player._hasSeek = true;
},
}
i don't know about other players, i hope there are a way to force the player to download and play the first segment. and add that option to this library so we can configure what segment that can be download first. so if latency is important to someone then he can choose the last segment, and if it's not an issue he can choose the first one and give enough time to P2P-media-loader
to download the max segments through P2P.
thanks a lot for this amazing library
Why is it not possible to deliver hls to ios devices?
They do support WebRTC Data Channels and I don't really understand what's the problem.
I also think that peer5 is able deliver hls to ios devices vie peer to peer but I wasn't able to figure out how.
Is it pollible to do so and just not supported by this p2p-media-loader or is it impossible to deliver hls to ios devices over WebRtc?
Hi :)
I read the code, but I did not find out if p2p-media-loader was checking P2P segment validity (for example like in bittorrent with a hash function).
If it does not check them, can a peer send a fake segment?
Hi All,
I want download range but it not woking with me
request.setRequestHeader("Range", segment.range);
segment.range is undefined
my file .m3u8 and server support download range
#EXTM3U
#EXT-X-VERSION:4
#EXT-X-TARGETDURATION:11
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXTINF:8.217089,
#EXT-X-BYTERANGE:212440@0
5bd9fd91ce7e1b08435acb87-000.ts
#EXTINF:10.427778,
#EXT-X-BYTERANGE:2814360@212440
5bd9fd91ce7e1b08435acb87-000.ts
#EXTINF:2.794644,
#EXT-X-BYTERANGE:128592@3026800
5bd9fd91ce7e1b08435acb87-000.ts
..........
Configuration parameter similar to https://github.com/video-dev/hls.js/blob/master/docs/API.md#xhrsetup
Testing here I ended up getting stuck here on line 42 of the media-peer.js:
class MediaPeer extends stringly_typed_event_emitter_1.default {
constructor (peer, settings) {
super();
this.peer = peer;
this.settings = settings;
this.remoteAddress = "";
this.downloadingSegmentId = null;
this.downloadingSegment = null;
this.segmentsMap = new Map ();
this.debug = Debug ("p2pml: media-peer");
this.timer = null;
//! at this point this.peer (peer too) here is a string like "179.187.29.127:9736", not an object
this.peer.on ("connect", () => this.onPeerConnect ());
=>
Uncaught TypeError: this.peer.on is not a function
at new MediaPeer (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/other_modules/p2p-media-loader-core/dist/media-peer.js:54)
at P2PMediaManager.onTrackerPeer (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/other_modules/p2p-media-loader-core/dist/p2p-media-manager.js:217)
at Client.emit (events.js: 188)
at /home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/bittorrent-tracker/lib/client/http-tracker.js:208
at Array.forEach (<anonymous>)
at HTTPTracker._onAnnounceResponse (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/bittorrent-tracker/lib/client/http-tracker.js:207)
at /home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/bittorrent-tracker/lib/client/http-tracker.js:60
at onResponse (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/bittorrent-tracker/lib/client/http-tracker.js:177)
at concat (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/bittorrent-tracker/node_modules/simple-get/index.js:89)
at IncomingMessage. <anonymous> (/home/efox/Downloads/nwjs-sdk-v0.35.4-linux-x64/package.nw/node_modules/simple-concat/index.js:7)
What could be the cause for the peer variable to be a string and not an object?
Hi there Nice project. Im tring to use it with a different tracker , but managed to make it work just with bittorrent-tracker, there is a way to Use it with UDP or to change it to Another tracker on WSS..
short history im tring to use a tracker to oprtimize
This project is great, I like it very much! Thanks very much!
I use Flowplayer to play videos, but Flowplayer hlsjs plugin is deprecated and discontinued.
Flowplayer 7 help says: Your should use the hlsjs-lite plugin available in Flowplayer Core now.
Please see:
https://flowplayer.com/help/developers/flowplayer-7/setup#hlsjs-lite
I tested p2p-media-loader-hlsjs with flowplayer hlsjs-lite plugin, but play the video was easy to get stuck, can you improve this ?
Thanks very much!
Hey mrlika & team,
is there an detailed instruction, how to install p2p-media-loader on an windows root/dedicated server? We want to test it in our own environment.
Keep up the good work ;)
Hi,
Can multiple tracker server help to increase the percent of media over p2p ?
i tried with new jwplayer (8.5.6) but can't display SUB . i see CC button .
When I run VOD HLS, the player loads the manifest segments in a different order. If the next segment is not loaded, the player stops.
This is what the Network tab in chrome displays:
..._3.ts
..._4.ts
..._20.ts
..._5.ts
..._10.ts
..._6.ts
..._7.ts
..._19.ts
At this point, the player stopped, because the 8th segment did not have time to load. Further, the player does not load any segments, the video stops playing.
This error occurs even on your demo, if you put a link to VOD HLS:
http://novage.com.ua/p2p-media-loader/demo.html?url=https%3A%2F%2Fwowza.peer5.com%2Fvod%2Fsmil%3Abbb_abr.smil%2Fplaylist.m3u8&type=jwplayer
My browser is Chrome 72.0.3626.121
So, viewing the demo example on the novage site runs as expected, however when i take the clappr example from here:
No p2p action happens. it gets this far, and then nothing more. No attempts on a websocket connection or any relevant debug logs:
p2pml:hybrid-loader loader settings +0ms Object p2p-media-loader-core.min.js:25 p2pml:p2p-media-manager peer ID +0ms 629918747b9e2edd7c1b36e713174b339446c714
Its a bit of an odd one, i previously had this working in a much more complicated setup and then today it stopped functioning, even in this simplified example.
The same is happening in both FF and Chrome latest on mac and windows, for me at least.
Is anyone able to reproduce this bug?
Hi, Could you tell me :
How to get myself's peer info( id and remoteAddress) or just peer.id?
Thanks!
Thank you for this wonderful package. But I'm having a problem. The system works perfect between two computers on the same network. I get all the video uploaded to the other computer but doesn't work for people outside the network. P2P graph always only shows me. How to fix this issue?
Can you please add something that shows how much download and upload every peer made to the other demos ( like this demo ) without graphs, a simple div that got updated every 5 seconds for example would be helpful.
because even if you enable debugging there are lot of informations, where sometimes you want just to see the performance ( p2p download vs http download ).
thanks for the great library
Hi, I tried to create a jwplayer instance in HLS with P2P, but it does not seem to work. In my tests the HLS is always loaded by the "provider.hlsjs.js" (default hls script of jwplayer), in the demo example i see that the segments are loaded by the initiator "p2p-media-loader-hlsjs.min.js". I can not see the difference between the test I did and the demo, could anyone explain what I did wrong?
Demo: https://jsfiddle.net/gkob21fv/1/
Browser: Chrome 70 win10
I just wonder why default config look like this:
httpDownloadProbability: 0.06,
httpDownloadProbabilityInterval: 500,
As i understand, when processSegmentsQueue
trigger, its used httpDownloadProbability
to random downloading through http. So with 0.06 ratio, after 20 times ~ 10 secs, all segment queued will download through http? Is it too short?
If i set httpDownloadProbability: 0
, does p2p rate would be down?
Thanks.
Hello,
how to configure the p2pml config that some peers (for example mobile) only download (p2p / http) ?
its possible ?
Thanks.
Is there any way to force the download over p2p of every segment including the first 2 that by default are downloader over http?
thanks
Retry counter, retry timeout, handle errors in Shaka and hls.js integrations etc.
Hello,
First of all, thanks for this awesome open source.
My m3u8 file url and all segments links are different for each user.
I believe peer system is identify which peer connect to which by segment or m3u8 links. But its not able to do it correctly because all users got a different m3u8 and segment links.
Is there any way to make a manuel match?
Something like this;
fileLinkReplace: function (url) {
url = remove_unique_parts(url);
return url;
}
segmentIdReplace: function (level, sn, url) {
url = remove_unique_parts(url);
return url;
}
from
https://example.com/hls/baxppq2zn5ts5n2gmlloot52i6lyz5rcvhjiszq4vsemf5jdqxwulk7bcxha/seg-27-v1-a1.ts
to
hi, if m3u8 src is
server.com/redirector.php?video.m3u8
and it redirect to
storage.com/hash/video.m3u8
script download m3u8 successfuly, after that try download ts files from server.com, but should from storage.com/hash/
Hello,
I don't know how to fix it. http://51.15.252.219/duplicate.png
My script: http://51.15.252.219/plugin.min.js
Please help.
is there an example how to use p2pml with dash.js?
Hello,
Would it be possible to let users choose the quality without breaking the p2p structure?
I'm using this one with notmal HLS streaming. But Its not compatible with your p2p script.
Hi there, it is any way to have the amount of segments downloaded by p2p and the amount by HTTP
Or whatever stats of traffic to check
Thanks in advance
I use Chrome extension uBlock Origin
, by default the option for Privacy > Prevent WebRTC from leaking local IP addresses
is enabled, when this option enabled in console I see websocket is connected and no error but cannot find another peer, It is required to use WebRTC IP?
Hello,
Is it possible to make a fallback to normal palyer when p2p is not possible?
On IE or Edge, It just gives error and video is not playable.
Hello, I don't know how to explain this issue very well.
I using this loader on VOD with 720/1080 videos, where segments usually ~10MB for 720 and ~20MB for 1080.
Without the loader, segments can be downloaded very fast via CDN
I am wondering if my current configuration is not suitable for VOD?
Also, I noticed the P2P request sequence seem to not ordered.
For example, say current segment is 100, next segment will be 101, but we got 102 instead, so we need to wait for 101 to load.
Maybe this cause the playback stucks frequently?
My current configuration:
{
loader: {
cachedSegmentsCount: 75,
cachedSegmentExpiration: 1000 * 60 * 15,
simultaneousP2PDownloads: 4,
httpDownloadProbability: 0.05,
httpDownloadProbabilityInterval: 1000,
bufferedSegmentsCount,
trackerAnnounce: ['wss://tracker.openwebtorrent.com', 'wss://tracker.fastcast.nz'],
},
segments: {
forwardSegmentCount: bufferedSegmentsCount,
maxHistorySegments: 0,
},
}
I currently have my broadcast on multiple servers, and do a simple client-side random to decide what source to use in that client's player.
Would it be possible to have the same peer network for all CDNs? Does this happen automatically based on the hash of the files? If not, is there some way to have control over this?
Thanks in advance.
Although the "bittorrent-tracker (client.js)" documentation states that the "port" argument is optional, in fact it is mandatory.
webtorrent/bittorrent-tracker#315
This is causing the following error here:
Uncaught (in promise) Error: Option `port` is required
at new Client (F: \ NWJS_SDK \ package.nw \ node_modules \ bittorrent-tracker \ client.js: 45)
at P2PMediaManager.createClient (F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ p2p-media-manager.js: 201)
at P2PMediaManager. <anonymous> (F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ p2p-media-manager.js: 187)
at Generator.next (<anonymous>)
at F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ p2p-media-manager.js: 22
at new Promise (<anonymous>)
at __awaiter (F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ p2p-media-manager.js: 18)
at P2PMediaManager.setSwarmId (F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ p2p-media-manager.js: 169)
at HybridLoader.load (F: \ NWJS_SDK \ package.nw \ node_modules \ p2p-media-loader-core \ dist \ hybrid-loader.js: 104)
at Object.self.fetch (assets / js / utils / prx.js: 306)
Hi
when .ts segment is loading it get 404 error sometimes.
What is the reason ?
How to fix it or config something ?
Hello,
I see that sometimes peers can't upload in high speeds.
In this case if reciever encounter this type of peer It starts to wait until the downloading segment from slow connection peer complete. But when player reaches that segment, Its just freezes and waiting the segment download finish.
So my question is;
I've try to set p2pSegmentDownloadTimeout to 5000 but It didn't solve the issue.
Lots of improvement has happened since last time, could you make a new release maybe?
Hello, thank you so much for creating and maintaining this amazing plugin!
I am currently integrating with the Shaka Player, I don't really understand how these settings works as they looks so identical:
Any clarification would be really helpful.
Unlike browserify build that substitutes "VERSION" string with package version using browserify-versionify plugin.
Hello,
How can we increase peer ratio? Any specific way like more tracker server or changing some config etc.
For me currently only %20 of my streams goes over peer traffic. Other %80 still loading from servers. When I was using peer5 this ratio was around %40-%50.
Thanks to you I have my own peer network now 🥇 💯 👍
But I wanted to know if its possible to improve performance or not.
Thanks :)
Hello,
Thanks for your library!
But I have segment links that look like this:
#EXTINF:20.000,
./big_buck_bunny.mp4:hls:seg-1-v1-a1.ts
#EXTINF:20.000,
./big_buck_bunny.mp4:hls:seg-2-v1-a1.ts
#EXTINF:20.000,
./big_buck_bunny.mp4:hls:seg-3-v1-a1.ts
And it seems that the library can't handle these "./" at the start of each link, and as a result, p2p does not work.
(engine.loader.segments
is empty while Playlist.segments
is not)
I'm using bittorrent-tracker with the following code
var Server = require('bittorrent-tracker').Server
var server = new Server({
udp: false, // enable udp server? [default=true]
http: false, // enable http server? [default=true]
ws: true, // enable websocket server? [default=true]
stats: true, // enable web-based statistics? [default=true]
filter: null
})
server.ws
server.on('error', function(err) {
// fatal server error!
console.log(err.message)
})
server.on('warning', function(err) {
// client sent bad data. probably not a problem, just a buggy client.
console.log(err.message)
})
server.on('listening', function() {
console.log('listening on ws port:' + server.ws.address().port)
})
// start tracker server listening! Use 0 to listen on a random free port.
var port = 8080,
hostname = "localhost";
server.listen(port, hostname)
// listen for individual tracker messages from peers:
server.on('start', function(addr) {
console.log('got start message from ' + addr)
})
server.on('complete', function(addr) {})
server.on('update', function(addr) {})
server.on('stop', function(addr) {})
then open url
http://novage.com.ua/p2p-media-loader/demo.html?url=https%3A%2F%2Fwowza.peer5.com%2Flive%2Fsmil%3Abbb_abr.smil%2Fchunklist_w1374448516_b591000.m3u8&type=clappr&trackers=ws://localhost:8080
in CMD I can see
got start message from 324d592d8855ff28e04c66a20fde7de68972d170
but I cannot see P2P traffic in stats, can you please create example working code for the server.
Thanks
is there an easy way to debug and find out the source of the file if it came from p2p or http
I have made a tiny wrapper utilising P2P media loader HLS package to be consumed in an Android App. There's 2 things i was wondering if someone can help me cross verify.
Likewise in exoplayer i'm tad-bit confused which event would call this. RIght now i'm using onLoadCompleted. Not sure if setPlayingSegment
is to be called when frame is requested or responded.
One of the solutions i'm tried today was to read chunk list and request for packets ahead of time and keep track of it so when player requests it i can directly resolve it. Though i get this error, Cancel segment request: simultaneous segment requests are not supported
.
Just wanted to run it through @mrlika if you have more ideas. Also kudos on library. Lemme know if there's anything i can help with. By now i'm very close to finish reading almost your entire source code to make it work over android.
P.s.: I know i'mma not have a perfect solution (hacky solution ofcourse 😏) just wanted todo a POC that p2p between web+android is possible using webrtc. I think peer5 does same underhood.
Yesterday i was try your script, after i was send to each webtorrent server (wss://tracker.openwebtorrent.com, wss://tracker.btorrent.xyz and wss://tracker.fastcast.nz) 5k viewers, they go down. How many messages script send to each server, that they cant do this work and go down...
Who store how many segments have peer - Server or peer ask another peers does they have segments?
Do you have goLang programmer?
Hello,
It's difficult to use the library with private trackers, because the infohash is built with a prefix, a swarmId and a suffix. And the way the library builds it could change at any time (for example by using sha256 https://github.com/Novage/p2p-media-loader/blob/master/p2p-media-loader-core/lib/p2p-media-manager.ts#L97).
Is it possible to expose the infohash builder in options with some arguments (protocole version, playlist url etc)?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.