├── p2p-media-loader-demo ├── .gitignore ├── .editorconfig ├── package.json └── README.md ├── p2p-media-loader-core ├── .gitignore ├── .npmignore ├── .editorconfig ├── tsconfig.tslint.json ├── tsconfig.json ├── tsconfig.test.json ├── lib │ ├── browser-init.js │ ├── index.ts │ ├── declarations.d.ts │ ├── browser-init-webpack.js │ ├── stringly-typed-event-emitter.ts │ ├── bandwidth-approximator.ts │ ├── loader-interface.ts │ ├── segments-memory-storage.ts │ └── http-media-manager.ts ├── test │ ├── types │ │ └── browser-stubs │ │ │ └── index.d.ts │ └── bandwidth-approximator.test.ts ├── webpackfile.js ├── tslint.json ├── package.json └── LICENSE ├── p2p-media-loader-hlsjs ├── .gitignore ├── .npmignore ├── .editorconfig ├── tsconfig.tslint.json ├── tsconfig.json ├── test │ ├── types │ │ ├── node-globals │ │ │ └── index.d.ts │ │ └── browser-stubs │ │ │ └── index.d.ts │ └── segment-manager.test.ts ├── tsconfig.test.json ├── lib │ ├── browser-init.js │ ├── declarations.d.ts │ ├── browser-init-webpack.js │ ├── hlsjs-loader-class.d.ts │ ├── hlsjs-loader-class.js │ ├── engine.ts │ ├── hlsjs-loader.ts │ └── index.ts ├── webpackfile.js ├── tslint.json ├── package.json ├── demo │ ├── hlsjs.html │ ├── clappr.html │ ├── jwplayer.html │ ├── plyr.html │ ├── videojs-hlsjs-plugin.html │ ├── flowplayer.html │ ├── videojs-contrib-hlsjs.html │ ├── mediaelementjs.html │ ├── dplayer.html │ └── offlineplayback.html └── LICENSE ├── p2p-media-loader-shaka ├── .gitignore ├── .npmignore ├── .editorconfig ├── tsconfig.tslint.json ├── tsconfig.json ├── lib │ ├── declarations.d.ts │ ├── browser-init.js │ ├── index.ts │ ├── browser-init-webpack.js │ ├── utils.ts │ ├── engine.ts │ ├── parser-segment.ts │ ├── manifest-parser-proxy.ts │ ├── integration.ts │ └── segment-manager.ts ├── webpackfile.js ├── tslint.json ├── package.json ├── demo │ ├── shakaplayer.html │ ├── plyr.html │ ├── clappr.html │ ├── dplayer.html │ └── offlineplayback.html ├── README.md └── LICENSE ├── .github └── FUNDING.yml ├── README.md ├── FAQ.md └── LICENSE /p2p-media-loader-demo/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /p2p-graph.js 3 | -------------------------------------------------------------------------------- /p2p-media-loader-core/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | /build 4 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | /build 4 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | /dist 3 | /build 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | custom: https://www.blockchain.com/btc/address/12YW9DJXAucLAx6Gy9tAXgXUPstHXEHnPY 2 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tsconfig.test.json 3 | tsconfig.tslint.json 4 | tslint.json 5 | lib 6 | test 7 | .editorconfig 8 | demo 9 | webpackfile.js 10 | *.tgz 11 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tsconfig.test.json 3 | tsconfig.tslint.json 4 | tslint.json 5 | lib 6 | test 7 | .editorconfig 8 | demo 9 | webpackfile.js 10 | *.tgz 11 | -------------------------------------------------------------------------------- /p2p-media-loader-core/.npmignore: -------------------------------------------------------------------------------- 1 | tsconfig.json 2 | tsconfig.test.json 3 | tsconfig.tslint.json 4 | tslint.json 5 | lib 6 | test 7 | .editorconfig 8 | build/dist 9 | webpackfile.js 10 | *.tgz 11 | -------------------------------------------------------------------------------- /p2p-media-loader-core/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /p2p-media-loader-demo/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/.editorconfig: -------------------------------------------------------------------------------- 1 | # http://editorconfig.org 2 | root = true 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | [*.md] 11 | trim_trailing_whitespace = false 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /p2p-media-loader-core/tsconfig.tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "noEmit": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "include": [ 20 | "lib/**/*", 21 | "test/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/tsconfig.tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "noEmit": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "include": [ 20 | "lib/**/*", 21 | "test/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/tsconfig.tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "noEmit": true, 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "include": [ 20 | "lib/**/*", 21 | "test/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "outDir": "./dist", 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "compileOnSave": true, 20 | "include": [ 21 | "lib/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "outDir": "./dist", 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "compileOnSave": true, 20 | "include": [ 21 | "lib/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es2017", 4 | "module": "commonjs", 5 | "strict": true, 6 | "moduleResolution": "node", 7 | "declaration": true, 8 | "outDir": "./dist", 9 | "noUnusedLocals": true, 10 | "noUnusedParameters": false, 11 | "strictNullChecks": true, 12 | "forceConsistentCasingInFileNames": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitReturns": true, 15 | "noImplicitThis": true, 16 | "noImplicitAny": true, 17 | "types": [] 18 | }, 19 | "compileOnSave": true, 20 | "include": [ 21 | "lib/**/*" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-core/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "lib": ["es6"], 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "declaration": true, 9 | "noEmit": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "strictNullChecks": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "noImplicitReturns": true, 16 | "noImplicitThis": true, 17 | "noImplicitAny": true, 18 | "types": ["mocha", "node", "browser-stubs"], 19 | "typeRoots" : ["./node_modules/@types", "./test/types"], 20 | "baseUrl": "." 21 | }, 22 | "compileOnSave": true 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/test/types/node-globals/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | declare const URL: any; 18 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "module": "commonjs", 5 | "lib": ["es6"], 6 | "strict": true, 7 | "moduleResolution": "node", 8 | "declaration": true, 9 | "noEmit": true, 10 | "noUnusedLocals": true, 11 | "noUnusedParameters": false, 12 | "strictNullChecks": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "noImplicitReturns": true, 16 | "noImplicitThis": true, 17 | "noImplicitAny": true, 18 | "types": ["mocha", "node", "node-globals", "browser-stubs"], 19 | "typeRoots" : ["./node_modules/@types", "./test/types"], 20 | "baseUrl": "." 21 | }, 22 | "compileOnSave": true 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/declarations.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | declare const shaka: any; 18 | 19 | declare const __P2PML_VERSION__: string; 20 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/browser-init.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | if (!window.p2pml) { 18 | window.p2pml = {}; 19 | } 20 | 21 | window.p2pml.core = require("./index"); 22 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/browser-init.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | if (!window.p2pml) { 18 | window.p2pml = {}; 19 | } 20 | 21 | window.p2pml.hlsjs = require("p2p-media-loader-hlsjs"); 22 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/browser-init.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | if (!window.p2pml) { 18 | window.p2pml = {}; 19 | } 20 | 21 | window.p2pml.shaka = require("p2p-media-loader-shaka"); 22 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/declarations.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | declare module "m3u8-parser" { 18 | export const Parser: any; 19 | } 20 | 21 | declare const __P2PML_VERSION__: string; 22 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Apache-2.0 3 | * Copyright 2018 Novage LLC. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export const version = "0.6.2"; 19 | export * from "./engine"; 20 | export * from "./segment-manager"; 21 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Apache-2.0 3 | * Copyright 2018 Novage LLC. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export const version = "0.6.2"; 19 | export * from "./loader-interface"; 20 | export * from "./hybrid-loader"; 21 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/browser-init-webpack.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as p2pMediaLoaderHlsJs from "./index"; 18 | 19 | if (!window.p2pml) { 20 | window.p2pml = {}; 21 | } 22 | 23 | window.p2pml.hlsjs = p2pMediaLoaderHlsJs; 24 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/browser-init-webpack.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as p2pMediaLoaderShaka from "./index"; 18 | 19 | if (!window.p2pml) { 20 | window.p2pml = {}; 21 | } 22 | 23 | window.p2pml.shaka = p2pMediaLoaderShaka; 24 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/hlsjs-loader-class.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { HlsJsLoader } from "./hlsjs-loader"; 18 | import { Engine } from "./engine"; 19 | 20 | export function createHlsJsLoaderClass(type: typeof HlsJsLoader, engine: Engine): any; 21 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/declarations.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | declare module "bittorrent-tracker/client"; 18 | declare module "get-browser-rtc"; 19 | declare module "simple-peer"; 20 | declare module "sha.js/sha1"; 21 | 22 | declare const __P2PML_VERSION__: string; 23 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/test/types/browser-stubs/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | type XMLHttpRequestResponseType = "" | "arraybuffer" | "blob" | "document" | "json" | "text"; 18 | 19 | declare class XMLHttpRequest { 20 | [key: string]: any; 21 | readonly response: any; 22 | readonly responseURL: string; 23 | } 24 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/browser-init-webpack.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as p2pMediaLoaderCore from "./index"; 18 | import * as debug from "debug"; 19 | import * as events from "events"; 20 | 21 | if (!window.p2pml) { 22 | window.p2pml = {}; 23 | } 24 | 25 | window.p2pml.core = p2pMediaLoaderCore; 26 | window.p2pml._shared = {debug, events}; 27 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/stringly-typed-event-emitter.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { EventEmitter } from "events"; 18 | 19 | export class STEEmitter extends EventEmitter { 20 | public on(event: T, listener: (...args: any[]) => void) { return super.on(event, listener); } 21 | public emit(event: T, ...args: any[]) { return super.emit(event, ...args); } 22 | } 23 | -------------------------------------------------------------------------------- /p2p-media-loader-core/test/types/browser-stubs/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | declare class RTCConfiguration { 18 | } 19 | 20 | declare class XMLHttpRequest { 21 | [key: string]: any; 22 | } 23 | 24 | declare class TextEncoder { 25 | [key: string]: any; 26 | } 27 | 28 | declare class TextDecoder { 29 | [key: string]: any; 30 | } 31 | 32 | declare const performance: any; 33 | declare const crypto: any; 34 | -------------------------------------------------------------------------------- /p2p-media-loader-core/webpackfile.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | 4 | const OUTPUT_PATH = "build"; 5 | 6 | function makeConfig({libName, entry, mode}) { 7 | return { 8 | mode, 9 | entry, 10 | resolve: { 11 | // Add `.ts` as a resolvable extension. 12 | extensions: [".ts", ".js"] 13 | }, 14 | module: { 15 | rules: [ 16 | // all files with a `.ts` extension will be handled by `ts-loader` 17 | { test: /\.ts?$/, exclude: [/node_modules/], loader: "ts-loader" }, 18 | ] 19 | }, 20 | output: { 21 | filename: libName + ".js", 22 | path: path.resolve(__dirname, OUTPUT_PATH) 23 | } 24 | } 25 | }; 26 | 27 | module.exports = [ 28 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "development", libName: "p2p-media-loader-core", }), 29 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "production", libName: "p2p-media-loader-core.min"}) 30 | ]; 31 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/utils.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | export function getSchemedUri(uri: string) { 18 | return uri.startsWith("//") ? window.location.protocol + uri : uri; 19 | } 20 | 21 | export function getMasterSwarmId(masterManifestUri: string, settings: {swarmId?: string}) { 22 | return (settings.swarmId && (settings.swarmId.length !== 0)) ? 23 | settings.swarmId : masterManifestUri.split("?")[0]; 24 | } 25 | -------------------------------------------------------------------------------- /p2p-media-loader-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "p2p-media-loader-demo", 3 | "description": "P2P Media Loader demo", 4 | "version": "0.6.2", 5 | "license": "Apache-2.0", 6 | "author": "Novage", 7 | "homepage": "https://github.com/Novage/p2p-media-loader", 8 | "main": "index.js", 9 | "keywords": [ 10 | "p2p", 11 | "peer-to-peer", 12 | "hls", 13 | "dash", 14 | "webrtc", 15 | "video", 16 | "mse", 17 | "player", 18 | "torrent", 19 | "bittorrent", 20 | "webtorrent", 21 | "hlsjs", 22 | "shaka player" 23 | ], 24 | "scripts": { 25 | "build-p2p-graph": "browserify -r p2p-graph | terser -m -c > p2p-graph.js", 26 | "build": "npm run build-p2p-graph" 27 | }, 28 | "repository": { 29 | "type": "git", 30 | "url": "https://github.com/Novage/p2p-media-loader.git" 31 | }, 32 | "dependencies": { 33 | "p2p-media-loader-core": "^0.6.2", 34 | "p2p-media-loader-hlsjs": "^0.6.2", 35 | "p2p-media-loader-shaka": "^0.6.2", 36 | "p2p-graph": "^1.2.3" 37 | }, 38 | "devDependencies": { 39 | "browserify": "^16.5.0", 40 | "browserify-versionify": "^1.0.6", 41 | "copyfiles": "^2.1.1", 42 | "terser": "^4.2.1" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /p2p-media-loader-demo/README.md: -------------------------------------------------------------------------------- 1 | # P2P Media Loader demo 2 | 3 | **P2P Media Loader** is an open-source JavaScript library that uses features of modern browsers (i.e. WebRTC) to deliver media over P2P. It doesn’t require any browser plugins or addons to function. 4 | 5 | ## Useful links 6 | 7 | - [P2P development, support & consulting](https://novage.com.ua/) 8 | - [Demo](http://novage.com.ua/p2p-media-loader/demo.html) 9 | - [FAQ](https://github.com/Novage/p2p-media-loader/blob/master/FAQ.md) 10 | - [Overview](http://novage.com.ua/p2p-media-loader/overview.html) 11 | - [Technical overview](http://novage.com.ua/p2p-media-loader/technical-overview.html) 12 | - API documentation 13 | - [Hls.js integration](../p2p-media-loader-hlsjs#p2p-media-loader---hlsjs-integration) 14 | - [Shaka Player integration](../p2p-media-loader-shaka#p2p-media-loader---shaka-player-integration) 15 | - [Core](../p2p-media-loader-core#p2p-media-loader-core) 16 | - JS CDN 17 | - [Core](https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/) 18 | - [Hls.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/build/) 19 | - [Shaka Player integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@latest/build/) 20 | 21 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/webpackfile.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | 4 | const OUTPUT_PATH = "build"; 5 | 6 | function makeConfig({libName, entry, mode}) { 7 | return { 8 | mode, 9 | entry, 10 | resolve: { 11 | // Add `.ts` as a resolvable extension. 12 | extensions: [".ts", ".js"] 13 | }, 14 | module: { 15 | rules: [ 16 | // all files with a `.ts` extension will be handled by `ts-loader` 17 | { test: /\.ts?$/, exclude: [/node_modules/], loader: "ts-loader" }, 18 | ] 19 | }, 20 | output: { 21 | filename: libName + ".js", 22 | path: path.resolve(__dirname, OUTPUT_PATH) 23 | }, 24 | externals: { 25 | "p2p-media-loader-core": "window.p2pml.core", 26 | "debug": "window.p2pml._shared.debug", 27 | "events": "window.p2pml._shared.events", 28 | } 29 | } 30 | }; 31 | 32 | module.exports = [ 33 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "development", libName: "p2p-media-loader-hlsjs", }), 34 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "production", libName: "p2p-media-loader-hlsjs.min"}) 35 | ]; 36 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/webpackfile.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const webpack = require("webpack"); 3 | 4 | const OUTPUT_PATH = "build"; 5 | 6 | function makeConfig({libName, entry, mode}) { 7 | return { 8 | mode, 9 | entry, 10 | resolve: { 11 | // Add `.ts` as a resolvable extension. 12 | extensions: [".ts", ".js"] 13 | }, 14 | module: { 15 | rules: [ 16 | // all files with a `.ts` extension will be handled by `ts-loader` 17 | { test: /\.ts?$/, exclude: [/node_modules/], loader: "ts-loader" }, 18 | ] 19 | }, 20 | output: { 21 | filename: libName + ".js", 22 | path: path.resolve(__dirname, OUTPUT_PATH) 23 | }, 24 | externals: { 25 | "p2p-media-loader-core": "window.p2pml.core", 26 | "debug": "window.p2pml._shared.debug", 27 | "events": "window.p2pml._shared.events", 28 | } 29 | } 30 | }; 31 | 32 | module.exports = [ 33 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "development", libName: "p2p-media-loader-shaka", }), 34 | makeConfig({entry: "./lib/browser-init-webpack.js", mode: "production", libName: "p2p-media-loader-shaka.min"}) 35 | ]; 36 | -------------------------------------------------------------------------------- /p2p-media-loader-core/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "indent": [ 5 | true, 6 | "spaces", 7 | 4 8 | ], 9 | "one-line": [ 10 | true, 11 | "check-else", 12 | "check-open-brace", 13 | "check-whitespace" 14 | ], 15 | "no-var-keyword": true, 16 | "quotemark": [ 17 | true, 18 | "double", 19 | "avoid-escape" 20 | ], 21 | "semicolon": [ 22 | true, 23 | "always", 24 | "ignore-bound-class-methods" 25 | ], 26 | "whitespace": [ 27 | true, 28 | "check-branch", 29 | "check-decl", 30 | "check-operator", 31 | "check-separator", 32 | "check-type" 33 | ], 34 | "typedef-whitespace": [ 35 | true, 36 | { 37 | "call-signature": "nospace", 38 | "index-signature": "nospace", 39 | "parameter": "nospace", 40 | "property-declaration": "nospace", 41 | "variable-declaration": "nospace" 42 | }, 43 | { 44 | "call-signature": "onespace", 45 | "index-signature": "onespace", 46 | "parameter": "onespace", 47 | "property-declaration": "onespace", 48 | "variable-declaration": "onespace" 49 | } 50 | ], 51 | "no-internal-module": true, 52 | "no-trailing-whitespace": true, 53 | "prefer-const": true, 54 | "jsdoc-format": true, 55 | "eofline": true 56 | }, 57 | "defaultSeverity": "warning" 58 | } 59 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "indent": [ 5 | true, 6 | "spaces", 7 | 4 8 | ], 9 | "one-line": [ 10 | true, 11 | "check-else", 12 | "check-open-brace", 13 | "check-whitespace" 14 | ], 15 | "no-var-keyword": true, 16 | "quotemark": [ 17 | true, 18 | "double", 19 | "avoid-escape" 20 | ], 21 | "semicolon": [ 22 | true, 23 | "always", 24 | "ignore-bound-class-methods" 25 | ], 26 | "whitespace": [ 27 | true, 28 | "check-branch", 29 | "check-decl", 30 | "check-operator", 31 | "check-separator", 32 | "check-type" 33 | ], 34 | "typedef-whitespace": [ 35 | true, 36 | { 37 | "call-signature": "nospace", 38 | "index-signature": "nospace", 39 | "parameter": "nospace", 40 | "property-declaration": "nospace", 41 | "variable-declaration": "nospace" 42 | }, 43 | { 44 | "call-signature": "onespace", 45 | "index-signature": "onespace", 46 | "parameter": "onespace", 47 | "property-declaration": "onespace", 48 | "variable-declaration": "onespace" 49 | } 50 | ], 51 | "no-internal-module": true, 52 | "no-trailing-whitespace": true, 53 | "prefer-const": true, 54 | "jsdoc-format": true, 55 | "eofline": true 56 | }, 57 | "defaultSeverity": "warning" 58 | } 59 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "class-name": true, 4 | "indent": [ 5 | true, 6 | "spaces", 7 | 4 8 | ], 9 | "one-line": [ 10 | true, 11 | "check-else", 12 | "check-open-brace", 13 | "check-whitespace" 14 | ], 15 | "no-var-keyword": true, 16 | "quotemark": [ 17 | true, 18 | "double", 19 | "avoid-escape" 20 | ], 21 | "semicolon": [ 22 | true, 23 | "always", 24 | "ignore-bound-class-methods" 25 | ], 26 | "whitespace": [ 27 | true, 28 | "check-branch", 29 | "check-decl", 30 | "check-operator", 31 | "check-separator", 32 | "check-type" 33 | ], 34 | "typedef-whitespace": [ 35 | true, 36 | { 37 | "call-signature": "nospace", 38 | "index-signature": "nospace", 39 | "parameter": "nospace", 40 | "property-declaration": "nospace", 41 | "variable-declaration": "nospace" 42 | }, 43 | { 44 | "call-signature": "onespace", 45 | "index-signature": "onespace", 46 | "parameter": "onespace", 47 | "property-declaration": "onespace", 48 | "variable-declaration": "onespace" 49 | } 50 | ], 51 | "no-internal-module": true, 52 | "no-trailing-whitespace": true, 53 | "prefer-const": true, 54 | "jsdoc-format": true, 55 | "eofline": true 56 | }, 57 | "defaultSeverity": "warning" 58 | } 59 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/hlsjs-loader-class.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | function createHlsJsLoaderClass(HlsJsLoader, engine) { 18 | function HlsJsLoaderClass() { 19 | this.impl = new HlsJsLoader(engine.segmentManager); 20 | this.stats = this.impl.stats; 21 | } 22 | 23 | HlsJsLoaderClass.prototype.load = function (context, config, callbacks) { 24 | this.context = context; 25 | this.impl.load(context, config, callbacks); 26 | }; 27 | 28 | HlsJsLoaderClass.prototype.abort = function () { 29 | this.impl.abort(this.context); 30 | }; 31 | 32 | HlsJsLoaderClass.prototype.destroy = function () { 33 | if (this.context) { 34 | this.impl.abort(this.context); 35 | } 36 | }; 37 | 38 | HlsJsLoaderClass.getEngine = function () { 39 | return engine; 40 | }; 41 | 42 | return HlsJsLoaderClass; 43 | } 44 | 45 | module.exports.createHlsJsLoaderClass = createHlsJsLoaderClass; 46 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "p2p-media-loader-shaka", 3 | "description": "P2P Media Loader Shaka Player integration", 4 | "version": "0.6.2", 5 | "license": "Apache-2.0", 6 | "author": "Novage", 7 | "homepage": "https://github.com/Novage/p2p-media-loader", 8 | "main": "dist/index.js", 9 | "types": "dist/index.d.ts", 10 | "keywords": [ 11 | "p2p", 12 | "peer-to-peer", 13 | "hls", 14 | "dash", 15 | "webrtc", 16 | "video", 17 | "mse", 18 | "player", 19 | "torrent", 20 | "bittorrent", 21 | "webtorrent", 22 | "shaka player" 23 | ], 24 | "scripts": { 25 | "compile": "tsc && copyfiles -f ./lib/*.js ./dist", 26 | "browserify": "mkdirp ./build && browserify -r ./dist/index.js:p2p-media-loader-shaka ./dist/browser-init.js -x p2p-media-loader-core -x debug -x events > ./build/p2p-media-loader-shaka.js", 27 | "minify": "terser ./build/p2p-media-loader-shaka.js -m -c > ./build/p2p-media-loader-shaka.min.js", 28 | "build": "npm run compile && npm run browserify && npm run minify", 29 | "webpack:build": "webpack --progress", 30 | "webpack:watch": "webpack --watch --progress", 31 | "lint": "tslint -c ./tslint.json -p ./tsconfig.tslint.json" 32 | }, 33 | "repository": { 34 | "type": "git", 35 | "url": "https://github.com/Novage/p2p-media-loader.git" 36 | }, 37 | "dependencies": { 38 | "debug": "^4.1.1", 39 | "events": "^3.0.0", 40 | "p2p-media-loader-core": "^0.6.2" 41 | }, 42 | "devDependencies": { 43 | "@types/debug": "^4.1.5", 44 | "@types/events": "^3.0.0", 45 | "browserify": "^16.5.0", 46 | "copyfiles": "^2.1.1", 47 | "mkdirp": "^0.5.1", 48 | "terser": "^4.2.1", 49 | "ts-loader": "^6.0.4", 50 | "tslint": "^5.19.0", 51 | "typescript": "^3.6.2", 52 | "webpack": "^4.39.3", 53 | "webpack-cli": "^3.3.7" 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "p2p-media-loader-hlsjs", 3 | "description": "P2P Media Loader hls.js integration", 4 | "version": "0.6.2", 5 | "license": "Apache-2.0", 6 | "author": "Novage", 7 | "homepage": "https://github.com/Novage/p2p-media-loader", 8 | "main": "dist/index.js", 9 | "types": "dist/index.d.ts", 10 | "keywords": [ 11 | "p2p", 12 | "peer-to-peer", 13 | "hls", 14 | "webrtc", 15 | "video", 16 | "mse", 17 | "player", 18 | "torrent", 19 | "bittorrent", 20 | "webtorrent", 21 | "hlsjs" 22 | ], 23 | "scripts": { 24 | "compile": "tsc && copyfiles -f ./lib/*.js ./dist", 25 | "browserify": "mkdirp ./build && browserify -r ./dist/index.js:p2p-media-loader-hlsjs ./dist/browser-init.js -x p2p-media-loader-core -x debug -x events > ./build/p2p-media-loader-hlsjs.js", 26 | "minify": "terser ./build/p2p-media-loader-hlsjs.js -m -c > ./build/p2p-media-loader-hlsjs.min.js", 27 | "webpack:build": "webpack --progress", 28 | "webpack:watch": "webpack --watch --progress", 29 | "build": "npm run compile && npm run browserify && npm run minify", 30 | "lint": "tslint -c ./tslint.json -p ./tsconfig.tslint.json", 31 | "test": "TS_NODE_PROJECT=tsconfig.test.json TS_NODE_CACHE=false mocha -r ts-node/register test/*.test.ts" 32 | }, 33 | "repository": { 34 | "type": "git", 35 | "url": "https://github.com/Novage/p2p-media-loader.git" 36 | }, 37 | "dependencies": { 38 | "events": "^3.0.0", 39 | "m3u8-parser": "^4.4.0", 40 | "p2p-media-loader-core": "^0.6.2" 41 | }, 42 | "devDependencies": { 43 | "@types/events": "^3.0.0", 44 | "@types/mocha": "^5.2.7", 45 | "@types/node": "^12.7.4", 46 | "@types/sinon": "^7.0.13", 47 | "browserify": "^16.5.0", 48 | "copyfiles": "^2.1.1", 49 | "mkdirp": "^0.5.1", 50 | "mocha": "^6.2.0", 51 | "sinon": "^7.4.2", 52 | "terser": "^4.2.1", 53 | "ts-loader": "^6.0.4", 54 | "ts-mockito": "^2.4.2", 55 | "ts-node": "^8.3.0", 56 | "tslint": "^5.19.0", 57 | "typescript": "^3.6.2", 58 | "webpack": "^4.39.3", 59 | "webpack-cli": "^3.3.7" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/hlsjs.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Hls.js player with P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /p2p-media-loader-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "p2p-media-loader-core", 3 | "description": "P2P Media Loader core functionality", 4 | "version": "0.6.2", 5 | "license": "Apache-2.0", 6 | "author": "Novage", 7 | "homepage": "https://github.com/Novage/p2p-media-loader", 8 | "main": "dist/index.js", 9 | "types": "dist/index.d.ts", 10 | "keywords": [ 11 | "p2p", 12 | "peer-to-peer", 13 | "hls", 14 | "dash", 15 | "webrtc", 16 | "video", 17 | "mse", 18 | "player", 19 | "torrent", 20 | "bittorrent", 21 | "webtorrent", 22 | "hlsjs", 23 | "shaka player" 24 | ], 25 | "scripts": { 26 | "compile": "tsc && copyfiles -f ./lib/*.js ./dist", 27 | "browserify": "mkdirp ./build && browserify -r ./dist/index.js:p2p-media-loader-core -r debug -r events ./dist/browser-init.js > ./build/p2p-media-loader-core.js", 28 | "minify": "terser ./build/p2p-media-loader-core.js -m -c > ./build/p2p-media-loader-core.min.js", 29 | "build": "npm run compile && npm run browserify && npm run minify", 30 | "webpack:build": "webpack --progress", 31 | "webpack:watch": "webpack --watch --progress", 32 | "lint": "tslint -c ./tslint.json -p ./tsconfig.tslint.json", 33 | "test": "TS_NODE_PROJECT=tsconfig.test.json TS_NODE_CACHE=false mocha -r ts-node/register test/*.test.ts" 34 | }, 35 | "repository": { 36 | "type": "git", 37 | "url": "https://github.com/Novage/p2p-media-loader.git" 38 | }, 39 | "dependencies": { 40 | "bittorrent-tracker": "^9.14.4", 41 | "debug": "^4.1.1", 42 | "events": "^3.0.0", 43 | "get-browser-rtc": "^1.0.2", 44 | "sha.js": "^2.4.11", 45 | "simple-peer": "^9.5.0" 46 | }, 47 | "devDependencies": { 48 | "@types/assert": "^1.4.3", 49 | "@types/debug": "^4.1.5", 50 | "@types/events": "^3.0.0", 51 | "@types/mocha": "^5.2.7", 52 | "@types/node": "^12.7.4", 53 | "browserify": "^16.5.0", 54 | "copyfiles": "^2.1.1", 55 | "mkdirp": "^0.5.1", 56 | "mocha": "^6.2.0", 57 | "terser": "^4.2.1", 58 | "ts-loader": "^6.0.4", 59 | "ts-mockito": "^2.4.2", 60 | "ts-node": "^8.3.0", 61 | "tslint": "^5.19.0", 62 | "typescript": "^3.6.2", 63 | "webpack": "^4.39.3", 64 | "webpack-cli": "^3.3.7" 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/clappr.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Clappr player with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | 39 | 40 | 41 |
42 | 43 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/bandwidth-approximator.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | const SMOOTH_INTERVAL = 1 * 1000; 18 | const MEASURE_INTERVAL = 60 * 1000; 19 | 20 | class NumberWithTime { 21 | constructor(readonly value: number, readonly timeStamp: number) {} 22 | } 23 | 24 | export class BandwidthApproximator { 25 | private lastBytes: NumberWithTime[] = []; 26 | private currentBytesSum = 0; 27 | private lastBandwidth: NumberWithTime[] = []; 28 | 29 | public addBytes(bytes: number, timeStamp: number): void { 30 | this.lastBytes.push(new NumberWithTime(bytes, timeStamp)); 31 | this.currentBytesSum += bytes; 32 | 33 | while (timeStamp - this.lastBytes[0].timeStamp > SMOOTH_INTERVAL) { 34 | this.currentBytesSum -= this.lastBytes.shift()!.value; 35 | } 36 | 37 | this.lastBandwidth.push(new NumberWithTime(this.currentBytesSum / SMOOTH_INTERVAL, timeStamp)); 38 | } 39 | 40 | // in bytes per millisecond 41 | public getBandwidth(timeStamp: number): number { 42 | while (this.lastBandwidth.length != 0 && timeStamp - this.lastBandwidth[0].timeStamp > MEASURE_INTERVAL) { 43 | this.lastBandwidth.shift(); 44 | } 45 | 46 | let maxBandwidth = 0; 47 | for (const bandwidth of this.lastBandwidth) { 48 | if (bandwidth.value > maxBandwidth) { 49 | maxBandwidth = bandwidth.value; 50 | } 51 | } 52 | 53 | return maxBandwidth; 54 | } 55 | 56 | public getSmoothInterval(): number { 57 | return SMOOTH_INTERVAL; 58 | } 59 | 60 | public getMeasureInterval(): number { 61 | return MEASURE_INTERVAL; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/jwplayer.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | JWPlayer with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 39 | 40 | 41 | 42 |
43 |
44 |
45 | 46 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/demo/shakaplayer.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Shaka Player with P2P demo (HLS or MPEG-DASH) 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/demo/plyr.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Plyr player with Shaka Player engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 44 |
45 | 46 |
47 | 48 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/plyr.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Plyr player with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 39 | 40 | 41 | 42 | 43 |
44 | 45 |
46 | 47 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/demo/clappr.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Clappr player with Shaka Player engine and P2P demo (MPEG-DASH only) 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 44 |
45 | 46 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/videojs-hlsjs-plugin.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Video.js player with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/flowplayer.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Flowplayer with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 44 |
45 | 46 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/videojs-contrib-hlsjs.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Video.js player with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/loader-interface.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | export interface Segment { 18 | readonly id: string; 19 | readonly url: string; 20 | readonly masterSwarmId: string; 21 | readonly masterManifestUri: string; 22 | readonly streamId: string | undefined; 23 | readonly sequence: string; 24 | readonly range: string | undefined; 25 | readonly priority: number; 26 | data?: ArrayBuffer; 27 | downloadBandwidth?: number; 28 | requestUrl?: string; 29 | responseUrl?: string; 30 | } 31 | 32 | export enum Events { 33 | /** 34 | * Emitted when segment has been downloaded. 35 | * Args: segment 36 | */ 37 | SegmentLoaded = "segment_loaded", 38 | 39 | /** 40 | * Emitted when an error occurred while loading the segment. 41 | * Args: segment, error 42 | */ 43 | SegmentError = "segment_error", 44 | 45 | /** 46 | * Emitted for each segment that does not hit into a new segments queue when the load() method is called. 47 | * Args: segment 48 | */ 49 | SegmentAbort = "segment_abort", 50 | 51 | /** 52 | * Emitted when a peer is connected. 53 | * Args: peer 54 | */ 55 | PeerConnect = "peer_connect", 56 | 57 | /** 58 | * Emitted when a peer is disconnected. 59 | * Args: peerId 60 | */ 61 | PeerClose = "peer_close", 62 | 63 | /** 64 | * Emitted when a segment piece has been downloaded. 65 | * Args: method (can be "http" or "p2p" only), bytes 66 | */ 67 | PieceBytesDownloaded = "piece_bytes_downloaded", 68 | 69 | /** 70 | * Emitted when a segment piece has been uploaded. 71 | * Args: method (can be "p2p" only), bytes 72 | */ 73 | PieceBytesUploaded = "piece_bytes_uploaded" 74 | } 75 | 76 | export interface LoaderInterface { 77 | on(eventName: string, listener: (...params: any[]) => void): this; 78 | load(segments: Segment[], streamSwarmId: string): void; 79 | getSegment(id: string): Promise; 80 | getSettings(): any; 81 | getDetails(): any; 82 | destroy(): Promise; 83 | } 84 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/mediaelementjs.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | MediaElement player with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 38 | 39 | 40 | 41 | 42 |
43 | 44 |
45 | 46 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/dplayer.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | DPlayer with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 39 | 40 | 41 | 42 | 43 |
44 | 45 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/engine.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { EventEmitter } from "events"; 18 | import { Events, LoaderInterface, HybridLoader, HybridLoaderSettings } from "p2p-media-loader-core"; 19 | import { SegmentManager, SegmentManagerSettings } from "./segment-manager"; 20 | import * as integration from "./integration"; 21 | 22 | export interface ShakaEngineSettings { 23 | loader: Partial; 24 | segments: Partial; 25 | } 26 | 27 | export class Engine extends EventEmitter { 28 | 29 | public static isSupported(): boolean { 30 | return HybridLoader.isSupported(); 31 | } 32 | 33 | private readonly loader: LoaderInterface; 34 | private readonly segmentManager: SegmentManager; 35 | 36 | public constructor(settings: Partial = {}) { 37 | super(); 38 | 39 | this.loader = new HybridLoader(settings.loader); 40 | this.segmentManager = new SegmentManager(this.loader, settings.segments); 41 | 42 | Object.keys(Events) 43 | .map(eventKey => Events[eventKey as keyof typeof Events]) 44 | .forEach(event => this.loader.on(event, (...args: any[]) => this.emit(event, ...args))); 45 | } 46 | 47 | public async destroy() { 48 | await this.segmentManager.destroy(); 49 | } 50 | 51 | public getSettings(): any { 52 | return { 53 | segments: this.segmentManager.getSettings(), 54 | loader: this.loader.getSettings() 55 | }; 56 | } 57 | 58 | public getDetails(): any { 59 | return { 60 | loader: this.loader.getDetails() 61 | }; 62 | } 63 | 64 | public initShakaPlayer(player: any) { 65 | integration.initShakaPlayer(player, this.segmentManager); 66 | } 67 | 68 | } 69 | 70 | export interface Asset { 71 | masterSwarmId: string; 72 | masterManifestUri: string; 73 | requestUri: string; 74 | requestRange?: string; 75 | responseUri: string; 76 | data: ArrayBuffer; 77 | } 78 | 79 | export interface AssetsStorage { 80 | storeAsset(asset: Asset): Promise; 81 | getAsset(requestUri: string, requestRange: string | undefined, masterSwarmId: string): Promise; 82 | destroy(): Promise; 83 | } 84 | -------------------------------------------------------------------------------- /p2p-media-loader-core/test/bandwidth-approximator.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /// 18 | /// 19 | 20 | import { BandwidthApproximator } from "../lib/bandwidth-approximator"; 21 | import * as assert from "assert"; 22 | 23 | describe("SpeedApproximator", () => { 24 | it("should calculate bandwidth correctly", () => { 25 | const bandwidthApp = new BandwidthApproximator(); 26 | const smoothInterval = bandwidthApp.getSmoothInterval(); 27 | const measureInterval = bandwidthApp.getMeasureInterval(); 28 | 29 | assert.equal(bandwidthApp.getBandwidth(1), 0); 30 | assert.equal(bandwidthApp.getBandwidth(1), 0); 31 | 32 | bandwidthApp.addBytes(1, 1); 33 | assert.equal(bandwidthApp.getBandwidth(1), 1 / smoothInterval); 34 | 35 | bandwidthApp.addBytes(1, 2); 36 | assert.equal(bandwidthApp.getBandwidth(2), 2 / smoothInterval); 37 | 38 | bandwidthApp.addBytes(1, 3); 39 | assert.equal(bandwidthApp.getBandwidth(4), 3 / smoothInterval); 40 | assert.equal(bandwidthApp.getBandwidth(4), 3 / smoothInterval); 41 | assert.equal(bandwidthApp.getBandwidth(5), 3 / smoothInterval); 42 | assert.equal(bandwidthApp.getBandwidth(5), 3 / smoothInterval); 43 | 44 | bandwidthApp.addBytes(1, smoothInterval + 3); 45 | assert.equal(bandwidthApp.getBandwidth(smoothInterval + 3), 3 / smoothInterval); 46 | 47 | assert.equal(bandwidthApp.getBandwidth(measureInterval), 3 / smoothInterval); 48 | assert.equal(bandwidthApp.getBandwidth(measureInterval + 1), 3 / smoothInterval); 49 | assert.equal(bandwidthApp.getBandwidth(measureInterval + 2), 3 / smoothInterval); 50 | assert.equal(bandwidthApp.getBandwidth(measureInterval + 3), 3 / smoothInterval); 51 | assert.equal(bandwidthApp.getBandwidth(measureInterval + 4), 2 / smoothInterval); 52 | assert.equal(bandwidthApp.getBandwidth(measureInterval + 5), 2 / smoothInterval); 53 | assert.equal(bandwidthApp.getBandwidth(measureInterval + smoothInterval + 3), 2 / smoothInterval); 54 | assert.equal(bandwidthApp.getBandwidth(measureInterval + smoothInterval + 4), 0); 55 | assert.equal(bandwidthApp.getBandwidth(measureInterval + smoothInterval + 5), 0); 56 | }); 57 | }); 58 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/demo/dplayer.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | DPlayer with Shaka Player engine and P2P demo (HLS or MPEG-DASH) 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 41 | 42 | 43 | 44 | 45 |
46 | 47 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/engine.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { EventEmitter } from "events"; 18 | import { Events, LoaderInterface, HybridLoader, HybridLoaderSettings } from "p2p-media-loader-core"; 19 | import { SegmentManager, Byterange, SegmentManagerSettings } from "./segment-manager"; 20 | import { HlsJsLoader } from "./hlsjs-loader"; 21 | import { createHlsJsLoaderClass } from "./hlsjs-loader-class"; 22 | 23 | export interface HlsJsEngineSettings { 24 | loader: Partial; 25 | segments: Partial; 26 | } 27 | 28 | export class Engine extends EventEmitter { 29 | 30 | public static isSupported(): boolean { 31 | return HybridLoader.isSupported(); 32 | } 33 | 34 | private readonly loader: LoaderInterface; 35 | private readonly segmentManager: SegmentManager; 36 | 37 | public constructor(settings: Partial = {}) { 38 | super(); 39 | 40 | this.loader = new HybridLoader(settings.loader); 41 | this.segmentManager = new SegmentManager(this.loader, settings.segments); 42 | 43 | Object.keys(Events) 44 | .map(eventKey => Events[eventKey as keyof typeof Events]) 45 | .forEach(event => this.loader.on(event, (...args: any[]) => this.emit(event, ...args))); 46 | } 47 | 48 | public createLoaderClass(): any { 49 | return createHlsJsLoaderClass(HlsJsLoader, this); 50 | } 51 | 52 | public async destroy() { 53 | await this.segmentManager.destroy(); 54 | } 55 | 56 | public getSettings(): any { 57 | return { 58 | segments: this.segmentManager.getSettings(), 59 | loader: this.loader.getSettings() 60 | }; 61 | } 62 | 63 | public getDetails(): any { 64 | return { 65 | loader: this.loader.getDetails() 66 | }; 67 | } 68 | 69 | public setPlayingSegment(url: string, byterange: Byterange, start: number, duration: number) { 70 | this.segmentManager.setPlayingSegment(url, byterange, start, duration); 71 | } 72 | 73 | public setPlayingSegmentByCurrentTime(playheadPosition: number) { 74 | this.segmentManager.setPlayingSegmentByCurrentTime(playheadPosition); 75 | } 76 | } 77 | 78 | export interface Asset { 79 | masterSwarmId: string; 80 | masterManifestUri: string; 81 | requestUri: string; 82 | requestRange?: string; 83 | responseUri: string; 84 | data: ArrayBuffer | string; 85 | } 86 | 87 | export interface AssetsStorage { 88 | storeAsset(asset: Asset): Promise; 89 | getAsset(requestUri: string, requestRange: string | undefined, masterSwarmId: string): Promise; 90 | destroy(): Promise; 91 | } 92 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/segments-memory-storage.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2019 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { Segment } from "./loader-interface"; 18 | import { SegmentsStorage } from "./hybrid-loader"; 19 | 20 | export class SegmentsMemoryStorage implements SegmentsStorage { 21 | private cache: Map = new Map(); 22 | 23 | constructor(private settings: { 24 | cachedSegmentExpiration: number, 25 | cachedSegmentsCount: number 26 | }) { } 27 | 28 | public async storeSegment(segment: Segment) { 29 | this.cache.set(segment.id, {segment, lastAccessed: performance.now()}); 30 | } 31 | 32 | public async getSegmentsMap(masterSwarmId: string) { 33 | return this.cache; 34 | } 35 | 36 | public async getSegment(id: string, masterSwarmId: string) { 37 | const cacheItem = this.cache.get(id); 38 | 39 | if (cacheItem === undefined) { 40 | return undefined; 41 | } 42 | 43 | cacheItem.lastAccessed = performance.now(); 44 | return cacheItem.segment; 45 | } 46 | 47 | public async hasSegment(id: string, masterSwarmId: string) { 48 | return this.cache.has(id); 49 | } 50 | 51 | public async clean(masterSwarmId: string, lockedSementsfilter?: (id: string) => boolean) { 52 | const segmentsToDelete: string[] = []; 53 | const remainingSegments: {segment: Segment, lastAccessed: number}[] = []; 54 | 55 | // Delete old segments 56 | const now = performance.now(); 57 | 58 | for (const cachedSegment of this.cache.values()) { 59 | if (now - cachedSegment.lastAccessed > this.settings.cachedSegmentExpiration) { 60 | segmentsToDelete.push(cachedSegment.segment.id); 61 | } else { 62 | remainingSegments.push(cachedSegment); 63 | } 64 | } 65 | 66 | // Delete segments over cached count 67 | let countOverhead = remainingSegments.length - this.settings.cachedSegmentsCount; 68 | if (countOverhead > 0) { 69 | remainingSegments.sort((a, b) => a.lastAccessed - b.lastAccessed); 70 | 71 | for (const cachedSegment of remainingSegments) { 72 | if ((lockedSementsfilter === undefined) || !lockedSementsfilter(cachedSegment.segment.id)) { 73 | segmentsToDelete.push(cachedSegment.segment.id); 74 | countOverhead--; 75 | if (countOverhead == 0) { 76 | break; 77 | } 78 | } 79 | } 80 | } 81 | 82 | segmentsToDelete.forEach(id => this.cache.delete(id)); 83 | return segmentsToDelete.length > 0; 84 | } 85 | 86 | public async destroy() { 87 | this.cache.clear(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/hlsjs-loader.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { SegmentManager } from "./segment-manager"; 18 | 19 | const DEFAULT_DOWNLOAD_LATENCY = 1; 20 | const DEFAULT_DOWNLOAD_BANDWIDTH = 12500; // bytes per millisecond 21 | 22 | export class HlsJsLoader { 23 | private segmentManager: SegmentManager; 24 | private readonly stats: any = {}; // required for older versions of hls.js 25 | 26 | public constructor(segmentManager: SegmentManager) { 27 | this.segmentManager = segmentManager; 28 | } 29 | 30 | public async load(context: any, _config: any, callbacks: any) { 31 | if (context.type) { 32 | try { 33 | const result = await this.segmentManager.loadPlaylist(context.url); 34 | this.successPlaylist(result, context, callbacks); 35 | } catch (e) { 36 | this.error(e, context, callbacks); 37 | } 38 | } else if (context.frag) { 39 | try { 40 | const result = await this.segmentManager.loadSegment(context.url, 41 | (context.rangeStart == undefined) || (context.rangeEnd == undefined) 42 | ? undefined 43 | : { offset: context.rangeStart, length: context.rangeEnd - context.rangeStart }); 44 | if (result.content !== undefined) { 45 | setTimeout(() => this.successSegment(result.content!, result.downloadBandwidth, context, callbacks), 0); 46 | } 47 | } catch (e) { 48 | setTimeout(() => this.error(e, context, callbacks), 0); 49 | } 50 | } else { 51 | console.warn("Unknown load request", context); 52 | } 53 | } 54 | 55 | public abort(context: any): void { 56 | this.segmentManager.abortSegment(context.url, 57 | (context.rangeStart == undefined) || (context.rangeEnd == undefined) 58 | ? undefined 59 | : { offset: context.rangeStart, length: context.rangeEnd - context.rangeStart }); 60 | } 61 | 62 | private successPlaylist(xhr: {response: string, responseURL: string}, context: any, callbacks: any): void { 63 | const now = performance.now(); 64 | 65 | this.stats.trequest = now - 300; 66 | this.stats.tfirst = now - 200; 67 | this.stats.tload = now; 68 | this.stats.loaded = xhr.response.length; 69 | 70 | callbacks.onSuccess({ 71 | url: xhr.responseURL, 72 | data: xhr.response 73 | }, this.stats, context); 74 | } 75 | 76 | private successSegment(content: ArrayBuffer, downloadBandwidth: number | undefined, context: any, callbacks: any): void { 77 | const now = performance.now(); 78 | const downloadTime = content.byteLength / (((downloadBandwidth === undefined) || (downloadBandwidth <= 0)) ? DEFAULT_DOWNLOAD_BANDWIDTH : downloadBandwidth); 79 | 80 | this.stats.trequest = now - DEFAULT_DOWNLOAD_LATENCY - downloadTime; 81 | this.stats.tfirst = now - downloadTime; 82 | this.stats.tload = now; 83 | this.stats.loaded = content.byteLength; 84 | 85 | callbacks.onSuccess({ 86 | url: context.url, 87 | data: content 88 | }, this.stats, context); 89 | } 90 | 91 | private error(error: any, context: any, callbacks: any): void { 92 | callbacks.onError(error, context); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/parser-segment.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { getSchemedUri } from "./utils"; 18 | 19 | export class ParserSegment { 20 | 21 | public static create(stream: any, position: number): ParserSegment | undefined { 22 | const ref = stream.getSegmentReferenceOriginal(position); 23 | if (!ref) { 24 | return undefined; 25 | } 26 | 27 | const uris = ref.createUris(); 28 | if (!uris || uris.length === 0) { 29 | return undefined; 30 | } 31 | 32 | const start = ref.getStartTime(); 33 | const end = ref.getEndTime(); 34 | 35 | const startByte = ref.getStartByte(); 36 | const endByte = ref.getEndByte(); 37 | const range = startByte || endByte 38 | ? `bytes=${startByte || ""}-${endByte || ""}` 39 | : undefined; 40 | 41 | const streamTypeCode = stream.type.substring(0, 1).toUpperCase(); 42 | const streamPosition = stream.getPosition(); 43 | const streamIsHls = streamPosition >= 0; 44 | 45 | const streamIdentity = streamIsHls 46 | ? `${streamTypeCode}${streamPosition}` 47 | : `${streamTypeCode}${stream.id}`; 48 | 49 | const identity = streamIsHls 50 | ? `${position}` 51 | : `${Number(start).toFixed(3)}`; 52 | 53 | return new ParserSegment( 54 | stream.id, 55 | stream.type, 56 | streamPosition, 57 | streamIdentity, 58 | identity, 59 | position, 60 | start, 61 | end, 62 | getSchemedUri(uris[ 0 ]), 63 | range, 64 | () => ParserSegment.create(stream, position - 1), 65 | () => ParserSegment.create(stream, position + 1) 66 | ); 67 | } 68 | 69 | private constructor( 70 | readonly streamId: number, 71 | readonly streamType: string, 72 | readonly streamPosition: number, 73 | readonly streamIdentity: string, 74 | readonly identity: string, 75 | readonly position: number, 76 | readonly start: number, 77 | readonly end: number, 78 | readonly uri: string, 79 | readonly range: string | undefined, 80 | readonly prev: () => ParserSegment | undefined, 81 | readonly next: () => ParserSegment | undefined 82 | ) {} 83 | 84 | } // end of ParserSegment 85 | 86 | export class ParserSegmentCache { 87 | 88 | private readonly segments: ParserSegment[] = []; 89 | private readonly maxSegments: number; 90 | 91 | public constructor(maxSegments: number) { 92 | this.maxSegments = maxSegments; 93 | } 94 | 95 | public find(uri: string, range?: string) { 96 | return this.segments.find(i => i.uri === uri && i.range === range); 97 | } 98 | 99 | public add(stream: any, position: number) { 100 | const segment = ParserSegment.create(stream, position); 101 | if (segment && !this.find(segment.uri, segment.range)) { 102 | this.segments.push(segment); 103 | if (this.segments.length > this.maxSegments) { 104 | this.segments.splice(0, this.maxSegments * 0.2); 105 | } 106 | } 107 | } 108 | 109 | public clear() { 110 | this.segments.splice(0); 111 | } 112 | 113 | } // end of ParserSegmentCache 114 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/manifest-parser-proxy.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import { ParserSegment, ParserSegmentCache } from "./parser-segment"; 18 | 19 | export class ShakaManifestParserProxy { 20 | 21 | private readonly cache: ParserSegmentCache = new ParserSegmentCache(200); 22 | private readonly originalManifestParser: any; 23 | private manifest: any; 24 | 25 | public constructor(originalManifestParser: any) { 26 | this.originalManifestParser = originalManifestParser; 27 | } 28 | 29 | public isHls() { return this.originalManifestParser instanceof shaka.hls.HlsParser; } 30 | public isDash() { return this.originalManifestParser instanceof shaka.dash.DashParser; } 31 | 32 | public start(uri: string, playerInterface: any) { 33 | // Tell P2P Media Loader's networking engine code about currently loading manifest 34 | if (playerInterface.networkingEngine.p2pml === undefined) { 35 | playerInterface.networkingEngine.p2pml = {}; 36 | } 37 | playerInterface.networkingEngine.p2pml.masterManifestUri = uri; 38 | 39 | return this.originalManifestParser.start(uri, playerInterface).then((manifest: any) => { 40 | this.manifest = manifest; 41 | 42 | for (const period of manifest.periods) { 43 | const processedStreams = []; 44 | 45 | for (const variant of period.variants) { 46 | if ((variant.video != null) && (processedStreams.indexOf(variant.video) == -1)) { 47 | this.hookGetSegmentReference(variant.video); 48 | processedStreams.push(variant.video); 49 | } 50 | 51 | if ((variant.audio != null) && (processedStreams.indexOf(variant.audio) == -1)) { 52 | this.hookGetSegmentReference(variant.audio); 53 | processedStreams.push(variant.audio); 54 | } 55 | } 56 | } 57 | 58 | manifest.p2pml = {parser: this}; 59 | return manifest; 60 | }); 61 | } 62 | 63 | public configure(config: any) { 64 | return this.originalManifestParser.configure(config); 65 | } 66 | 67 | public stop() { 68 | return this.originalManifestParser.stop(); 69 | } 70 | 71 | public update() { 72 | return this.originalManifestParser.update(); 73 | } 74 | 75 | public onExpirationUpdated() { 76 | return this.originalManifestParser.onExpirationUpdated(); 77 | } 78 | 79 | public find(uri: string, range?: string): ParserSegment | undefined { 80 | return this.cache.find(uri, range); 81 | } 82 | 83 | public reset() { 84 | this.cache.clear(); 85 | } 86 | 87 | private hookGetSegmentReference(stream: any): void { 88 | stream.getSegmentReferenceOriginal = stream.getSegmentReference; 89 | 90 | stream.getSegmentReference = (segmentNumber: any) => { 91 | this.cache.add(stream, segmentNumber); 92 | return stream.getSegmentReferenceOriginal(segmentNumber); 93 | }; 94 | 95 | stream.getPosition = () => { 96 | if (this.isHls()) { 97 | if (stream.type === "video") { 98 | return this.manifest.periods[0].variants.reduce((a: any, i: any) => { 99 | if (i.video && i.video.id && !a.includes(i.video.id)) { 100 | a.push(i.video.id); 101 | } 102 | return a; 103 | }, []).indexOf(stream.id); 104 | } 105 | } 106 | return -1; 107 | }; 108 | } 109 | 110 | } // end of ShakaManifestParserProxy 111 | 112 | export class ShakaDashManifestParserProxy extends ShakaManifestParserProxy { 113 | public constructor() { 114 | super(new shaka.dash.DashParser()); 115 | } 116 | } 117 | 118 | export class ShakaHlsManifestParserProxy extends ShakaManifestParserProxy { 119 | public constructor() { 120 | super(new shaka.hls.HlsParser()); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/test/segment-manager.test.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /// 18 | /// 19 | 20 | import { mock, instance, when, anyFunction } from "ts-mockito"; 21 | import * as assert from "assert"; 22 | 23 | import { SegmentManager } from "../lib/segment-manager"; 24 | import { Events, Segment, LoaderInterface } from "p2p-media-loader-core"; 25 | 26 | class LoaderInterfaceEmptyImpl implements LoaderInterface { 27 | public on(eventName: string | symbol, listener: Function): this { return this; } 28 | public load(segments: Segment[], swarmId: string): void { } 29 | public async getSegment(id: string): Promise { return undefined; } 30 | public getSettings(): any { } 31 | public getDetails(): any { } 32 | public async destroy(): Promise { } 33 | } 34 | 35 | const testPlaylist = { 36 | url: "http://site.com/stream/playlist.m3u8", 37 | baseUrl: "http://site.com/stream/", 38 | content: `#EXTM3U 39 | #EXT-X-VERSION:3 40 | #EXT-X-TARGETDURATION:5 41 | #EXTINF:5 42 | segment-1041.ts 43 | #EXTINF:5.055 44 | segment-1042.ts 45 | #EXTINF:6.125 46 | segment-1043.ts 47 | #EXTINF:5.555 48 | segment-1044.ts 49 | #EXTINF:5.555 50 | segment-1045.ts 51 | #EXTINF:5.115 52 | segment-1046.ts 53 | #EXTINF:5.425 54 | segment-1047.ts 55 | #EXTINF:5.745 56 | segment-1048.ts 57 | ` 58 | }; 59 | 60 | describe("SegmentManager", () => { 61 | 62 | it("should call succeed after segment loading succeeded", async () => { 63 | const loader = mock(LoaderInterfaceEmptyImpl); 64 | 65 | let segmentLoadedListener = (segment: Segment) => { throw new Error("SegmentLoaded listener not set"); }; 66 | when(loader.on(Events.SegmentLoaded, anyFunction())).thenCall((_eventName, listener) => { 67 | segmentLoadedListener = listener; 68 | }); 69 | 70 | const segment = new Segment( 71 | "id", 72 | testPlaylist.baseUrl + "segment-1045.ts", 73 | testPlaylist.url, 74 | testPlaylist.url, 75 | undefined, 76 | "1045", 77 | undefined, 0, new ArrayBuffer(1)); 78 | 79 | const manager = new SegmentManager(instance(loader)); 80 | manager.processPlaylist(testPlaylist.url, testPlaylist.content, testPlaylist.url); 81 | const promise = manager.loadSegment(segment.url, undefined); 82 | segmentLoadedListener(segment); 83 | 84 | const result = await promise; 85 | 86 | assert.deepEqual(result.content, segment.data); 87 | }); 88 | 89 | it("should fail after segment loading failed", async () => { 90 | const loader = mock(LoaderInterfaceEmptyImpl); 91 | 92 | let segmentErrorListener = (segment: Segment, error: any) => { throw new Error("SegmentError listener not set"); }; 93 | when(loader.on(Events.SegmentError, anyFunction())).thenCall((_eventName, listener) => { 94 | segmentErrorListener = listener; 95 | }); 96 | 97 | const error = "Test error message content"; 98 | 99 | const segment = new Segment( 100 | "id", 101 | testPlaylist.baseUrl + "segment-1045.ts", 102 | testPlaylist.url, 103 | testPlaylist.url, 104 | undefined, 105 | "1045", 106 | undefined, 0, undefined); 107 | 108 | const manager = new SegmentManager(instance(loader)); 109 | manager.processPlaylist(testPlaylist.url, testPlaylist.content, testPlaylist.url); 110 | const promise = manager.loadSegment(segment.url, undefined); 111 | segmentErrorListener(segment, error); 112 | 113 | try { 114 | await promise; 115 | assert.fail("should not succeed"); 116 | } catch (e) { 117 | assert.equal(e, error); 118 | } 119 | }); 120 | 121 | it("should return undefined content after abortSegment call", async () => { 122 | const loader = mock(LoaderInterfaceEmptyImpl); 123 | 124 | let segmentLoadedListener = (segment: Segment) => { throw new Error("SegmentLoaded listener not set"); }; 125 | when(loader.on(Events.SegmentLoaded, anyFunction())).thenCall((_eventName, listener) => { 126 | segmentLoadedListener = listener; 127 | }); 128 | 129 | const segment = new Segment( 130 | "id", 131 | testPlaylist.baseUrl + "segment-1045.ts", 132 | testPlaylist.url, 133 | testPlaylist.url, 134 | undefined, 135 | "1045", 136 | undefined, 0, new ArrayBuffer(0)); 137 | 138 | const manager = new SegmentManager(instance(loader)); 139 | manager.processPlaylist(testPlaylist.url, testPlaylist.content, testPlaylist.url); 140 | const promise = manager.loadSegment(segment.url, undefined); 141 | manager.abortSegment(segment.url, undefined); 142 | segmentLoadedListener(segment); 143 | 144 | const result = await promise; 145 | assert.equal(result.content, undefined); 146 | }); 147 | 148 | }); 149 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/README.md: -------------------------------------------------------------------------------- 1 | # P2P Media Loader - Shaka Player integration 2 | 3 | [![npm version](https://badge.fury.io/js/p2p-media-loader-shaka.svg)](https://npmjs.com/package/p2p-media-loader-shaka) 4 | 5 | P2P sharing of segmented media streams (i.e. HLS, MPEG-DASH) using WebRTC for [Shaka Player](https://github.com/google/shaka-player) 6 | 7 | Useful links: 8 | - [P2P development, support & consulting](https://novage.com.ua/) 9 | - [Demo](http://novage.com.ua/p2p-media-loader/demo.html) 10 | - [FAQ](https://github.com/Novage/p2p-media-loader/blob/master/FAQ.md) 11 | - [Overview](http://novage.com.ua/p2p-media-loader/overview.html) 12 | - [Technical overview](http://novage.com.ua/p2p-media-loader/technical-overview.html) 13 | - JS CDN 14 | - [Core](https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/) 15 | - [Shaka Player integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@latest/build/) 16 | - [Hls.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/build/) 17 | 18 | ## Basic usage 19 | 20 | General steps are: 21 | 22 | 1. Include P2P Medial Loader scripts. 23 | 2. Create P2P Medial Loader engine instance. 24 | 3. Create a player instance. 25 | 4. Call init function for the player. 26 | 27 | ```html 28 | 29 | 30 | 31 | Shaka Player with P2P Media Loader 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 57 | 58 | 59 | ``` 60 | 61 | # API 62 | 63 | The library uses `window.p2pml.shaka` as a root namespace in Web browser for: 64 | - `Engine` - Shaka Player support engine 65 | - `version` - API version 66 | 67 | --- 68 | 69 | ## `Engine` 70 | 71 | Shaka Player support engine. 72 | 73 | ### `Engine.isSupported()` 74 | 75 | Returns result from `p2pml.core.HybridLoader.isSupported()`. 76 | 77 | ### `engine = new Engine([settings])` 78 | 79 | Creates a new `Engine` instance. 80 | 81 | `settings` structure: 82 | - `segments` 83 | + `forwardSegmentCount` - Number of segments for building up predicted forward segments sequence; used to predownload and share via P2P. Default is 20. 84 | + `maxHistorySegments` - Maximum amount of requested segments manager should remember; used to build up sequence with correct priorities for P2P sharing. Default is 50. 85 | + `swarmId` - Override default swarm ID that is used to identify unique media stream with trackers (manifest URL without query parameters is used as the swarm ID if the parameter is not specified). 86 | + `assetsStorage` - A storage for the downloaded assets: manifests, subtitles, init segments, DRM assets etc. By default the assets are not stored. Can be used to implement offline plabyack. See [AssetsStorage](#assetsstorage-interface) interface for details. 87 | - `loader` 88 | + settings for `HybridLoader` (see [P2P Media Loader Core API](../p2p-media-loader-core/README.md#loader--new-hybridloadersettings) for details). 89 | 90 | ### AssetsStorage interface 91 | ```typescript 92 | interface Asset { 93 | masterSwarmId: string; 94 | masterManifestUri: string; 95 | requestUri: string; 96 | requestRange?: string; 97 | responseUri: string; 98 | data: ArrayBuffer; 99 | } 100 | 101 | interface AssetsStorage { 102 | storeAsset(asset: Asset): Promise; 103 | getAsset(requestUri: string, requestRange: string | undefined, masterSwarmId: string): Promise; 104 | destroy(): Promise; 105 | } 106 | ``` 107 | 108 | ### `engine.on(event, handler)` 109 | 110 | Registers an event handler. 111 | 112 | - `event` - Event you want to handle; available events you can find [here](../p2p-media-loader-core/README.md#events). 113 | - `handler` - Function to handle the event 114 | 115 | ### `engine.getSettings()` 116 | 117 | Returns engine instance settings. 118 | 119 | ### `engine.getDetails()` 120 | 121 | Returns engine instance details. 122 | 123 | ### `engine.destroy()` 124 | 125 | Destroys engine; destroy loader and segment manager. 126 | 127 | ### `engine.initShakaPlayer(player)` 128 | 129 | Shaka Player integration. 130 | 131 | `player` should be valid Shaka Player instance. 132 | 133 | Example 134 | ```javascript 135 | shaka.polyfill.installAll(); 136 | 137 | var engine = new p2pml.shaka.Engine(); 138 | 139 | var video = document.getElementById("video"); 140 | var player = new shaka.Player(video); 141 | 142 | engine.initShakaPlayer(player); 143 | 144 | player.load("https://example.com/path/to/your/dash.mpd"); 145 | ``` 146 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/lib/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * @license Apache-2.0 3 | * Copyright 2018 Novage LLC. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | export const version = "0.6.2"; 19 | export * from "./engine"; 20 | export * from "./segment-manager"; 21 | 22 | import { Engine } from "./engine"; 23 | 24 | declare const videojs: any; 25 | 26 | export function initHlsJsPlayer(player: any): void { 27 | if (player && player.config && player.config.loader && typeof player.config.loader.getEngine === "function") { 28 | initHlsJsEvents(player, player.config.loader.getEngine()); 29 | } 30 | } 31 | 32 | export function initClapprPlayer(player: any): void { 33 | player.on("play", () => { 34 | const playback = player.core.getCurrentPlayback(); 35 | if (playback._hls && !playback._hls._p2pm_linitialized) { 36 | playback._hls._p2pm_linitialized = true; 37 | initHlsJsPlayer(player.core.getCurrentPlayback()._hls); 38 | } 39 | }); 40 | } 41 | 42 | export function initFlowplayerHlsJsPlayer(player: any): void { 43 | player.on("ready", () => initHlsJsPlayer(player.engine.hlsjs ? player.engine.hlsjs : player.engine.hls)); 44 | } 45 | 46 | export function initVideoJsContribHlsJsPlayer(player: any): void { 47 | player.ready(() => { 48 | const options = player.tech_.options_; 49 | if (options && options.hlsjsConfig && options.hlsjsConfig.loader && typeof options.hlsjsConfig.loader.getEngine === "function") { 50 | initHlsJsEvents(player.tech_, options.hlsjsConfig.loader.getEngine()); 51 | } 52 | }); 53 | } 54 | 55 | export function initVideoJsHlsJsPlugin(): void { 56 | if (videojs == undefined || videojs.Html5Hlsjs == undefined) { 57 | return; 58 | } 59 | 60 | videojs.Html5Hlsjs.addHook("beforeinitialize", (videojsPlayer: any, hlsjs: any) => { 61 | if (hlsjs.config && hlsjs.config.loader && typeof hlsjs.config.loader.getEngine === "function") { 62 | initHlsJsEvents(hlsjs, hlsjs.config.loader.getEngine()); 63 | } 64 | }); 65 | } 66 | 67 | export function initMediaElementJsPlayer(mediaElement: any): void { 68 | mediaElement.addEventListener("hlsFragChanged", (event: any) => { 69 | const hls = mediaElement.hlsPlayer; 70 | if (hls && hls.config && hls.config.loader && typeof hls.config.loader.getEngine === "function") { 71 | const engine: Engine = hls.config.loader.getEngine(); 72 | 73 | if (event.data && (event.data.length > 1)) { 74 | const frag = event.data[1].frag; 75 | const byterange = (frag.byteRange.length !== 2) 76 | ? undefined 77 | : { offset: frag.byteRange[0], length: frag.byteRange[1] - frag.byteRange[0] }; 78 | engine.setPlayingSegment(frag.url, byterange, frag.start, frag.duration); 79 | } 80 | } 81 | }); 82 | mediaElement.addEventListener("hlsDestroying", async () => { 83 | const hls = mediaElement.hlsPlayer; 84 | if (hls && hls.config && hls.config.loader && typeof hls.config.loader.getEngine === "function") { 85 | const engine: Engine = hls.config.loader.getEngine(); 86 | await engine.destroy(); 87 | } 88 | }); 89 | mediaElement.addEventListener("hlsError", (event: any) => { 90 | const hls = mediaElement.hlsPlayer; 91 | if (hls && hls.config && hls.config.loader && typeof hls.config.loader.getEngine === "function") { 92 | if ((event.data !== undefined) && (event.data.details === "bufferStalledError")) { 93 | const engine: Engine = hls.config.loader.getEngine(); 94 | engine.setPlayingSegmentByCurrentTime(hls.media.currentTime); 95 | } 96 | } 97 | }); 98 | } 99 | 100 | export function initJwPlayer(player: any, hlsjsConfig: any): void { 101 | const iid = setInterval(() => { 102 | if (player.hls && player.hls.config) { 103 | clearInterval(iid); 104 | Object.assign(player.hls.config, hlsjsConfig); 105 | initHlsJsPlayer(player.hls); 106 | } 107 | }, 200); 108 | } 109 | 110 | function initHlsJsEvents(player: any, engine: Engine): void { 111 | player.on("hlsFragChanged", (_event: any, data: any) => { 112 | const frag = data.frag; 113 | const byterange = (frag.byteRange.length !== 2) 114 | ? undefined 115 | : { offset: frag.byteRange[0], length: frag.byteRange[1] - frag.byteRange[0] }; 116 | engine.setPlayingSegment(frag.url, byterange, frag.start, frag.duration); 117 | }); 118 | player.on("hlsDestroying", async () => { 119 | await engine.destroy(); 120 | }); 121 | player.on("hlsError", (_event: string, errorData: { details: string }) => { 122 | if (errorData.details === "bufferStalledError") { 123 | const htmlMediaElement = player.media === undefined 124 | ? player.el_ // videojs-contrib-hlsjs 125 | : player.media; // all others 126 | if (htmlMediaElement === undefined) { 127 | return; 128 | } 129 | engine.setPlayingSegmentByCurrentTime(htmlMediaElement.currentTime); 130 | } 131 | }); 132 | } 133 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # P2P Media Loader 2 | 3 | **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)). 4 | 5 | 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. 6 | 7 | It significantly reduces traditional CDN traffic and cost while delivering media streams to more users. 8 | 9 | ## Related projects 10 | 11 | * [wt-tracker](https://github.com/Novage/wt-tracker) - high-performance WebTorrent tracker 12 | * [WebTorrent](https://github.com/webtorrent/webtorrent) - streaming torrent client for the web https://webtorrent.io 13 | 14 | ## Useful links 15 | 16 | - [P2P development, support & consulting](https://novage.com.ua/) 17 | - [Demo](http://novage.com.ua/p2p-media-loader/demo.html) 18 | - [FAQ](FAQ.md) 19 | - [Overview](http://novage.com.ua/p2p-media-loader/overview.html) 20 | - [Technical overview](http://novage.com.ua/p2p-media-loader/technical-overview.html) 21 | - API documentation 22 | - [Hls.js integration](p2p-media-loader-hlsjs#p2p-media-loader---hlsjs-integration) 23 | - [Shaka Player integration](p2p-media-loader-shaka#p2p-media-loader---shaka-player-integration) 24 | - [Core](p2p-media-loader-core#p2p-media-loader-core) 25 | - JS CDN 26 | - [Core](https://cdn.jsdelivr.net/npm/p2p-media-loader-core@latest/build/) 27 | - [Hls.js integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-hlsjs@latest/build/) 28 | - [Shaka Player integration](https://cdn.jsdelivr.net/npm/p2p-media-loader-shaka@latest/build/) 29 | - npm packages 30 | - [Core](https://npmjs.com/package/p2p-media-loader-core) 31 | - [Hls.js integration](https://npmjs.com/package/p2p-media-loader-hlsjs) 32 | - [Shaka Player integration](https://npmjs.com/package/p2p-media-loader-shaka) 33 | 34 | ## Key features 35 | 36 | - Supports live and VOD streams over HLS or MPEG-DASH protocols 37 | - Supports multiple HTML5 video players and engines: 38 | - Engines: Hls.js, Shaka Player 39 | - Video players: JWPlayer, Clappr, Flowplayer, MediaElement, VideoJS 40 | - Supports adaptive bitrate streaming of HLS and MPEG-DASH protocols 41 | - No need in server-side software. By default **P2P Media Loader** uses publicly available servers: 42 | - STUN servers - [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e) 43 | - WebTorrent trackers - [https://openwebtorrent.com/](https://openwebtorrent.com/) 44 | 45 | ## Key components of the P2P network 46 | 47 | All the components of the P2P network are free and open-source. 48 | 49 | ![P2P Media Loader network](https://raw.githubusercontent.com/Novage/p2p-media-loader/gh-pages/images/p2p-media-loader-network.png) 50 | 51 | **P2P Media Loader** web browser [requirements](#web-browsers-support) are:
52 | - **WebRTC Data Channels** support to exchange data between peers 53 | - **Media Source Extensions** are required by Hls.js and Shaka Player engines for media playback 54 | 55 | [**STUN**](https://en.wikipedia.org/wiki/STUN) server is used by [WebRTC](https://developer.mozilla.org/en-US/docs/Web/API/WebRTC_API) to gather [ICE](https://en.wikipedia.org/wiki/Interactive_Connectivity_Establishment) candidates. 56 | There are many running public servers available on [Public STUN server list](https://gist.github.com/mondain/b0ec1cf5f60ae726202e). 57 | 58 | [**WebTorrent**](https://webtorrent.io/) tracker is used for WebRTC signaling and to create swarms of peers that download the same media stream. 59 | Few running public trackers are available: [https://openwebtorrent.com/](https://openwebtorrent.com/). 60 | It is possible to run personal WebTorrent tracker using open-source implementations: [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker), [uWebTorrentTracker](https://github.com/DiegoRBaquero/uWebTorrentTracker). 61 | 62 | **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. 63 | 64 | ## How it works 65 | 66 | 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. 67 | 68 | **P2P Media Loader** starts to download initial media segments over HTTP(S) from source server or CDN. This allows beginning media playback faster. 69 | 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. 70 | 71 | After that **P2P Media Loader** sends media stream details and its connection details (ICE candidates) to WebTorrent trackers 72 | and obtains from them list of other peers that are downloading the same media stream. 73 | 74 | **P2P Media Loader** connects and starts to download media segments from the obtained peers as well as sharing already downloaded segments to them. 75 | 76 | From time to time random peers from the P2P swarm download new segments over HTTP(S) and share them to others over P2P. 77 | 78 | ## Limitations 79 | 80 | 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. 81 | 82 | ## Web browsers support 83 | 84 | | | Chrome | Firefox | macOS Safari | iOS Safari | IE | Edge | 85 | |-------------------------|--------|---------|--------------|------------|-------|-------| 86 | | WebRTC Data Channels | + | + | + | + | - | - | 87 | | Media Source Extensions | + | + | + | - | + | + | 88 | | **P2P Media Loader** | **+** | **+** | **+** | **-** | **-** | **-** | 89 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/integration.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as Debug from "debug"; 18 | import { SegmentManager } from "./segment-manager"; 19 | import { ShakaDashManifestParserProxy, ShakaHlsManifestParserProxy } from "./manifest-parser-proxy"; 20 | import { getSchemedUri, getMasterSwarmId } from "./utils"; 21 | import { ParserSegment } from "./parser-segment"; 22 | 23 | const debug = Debug("p2pml:shaka:index"); 24 | 25 | export function initShakaPlayer(player: any, segmentManager: SegmentManager) { 26 | registerParserProxies(); 27 | initializeNetworkingEngine(); 28 | 29 | let intervalId: number = 0; 30 | let lastPlayheadTimeReported: number = 0; 31 | 32 | player.addEventListener("loading", async () => { 33 | if (intervalId > 0) { 34 | clearInterval(intervalId); 35 | intervalId = 0; 36 | } 37 | 38 | lastPlayheadTimeReported = 0; 39 | 40 | const manifest = player.getManifest(); 41 | if (manifest && manifest.p2pml) { 42 | manifest.p2pml.parser.reset(); 43 | } 44 | 45 | await segmentManager.destroy(); 46 | 47 | intervalId = setInterval(() => { 48 | const time = getPlayheadTime(player); 49 | if (time !== lastPlayheadTimeReported || player.isBuffering()) { 50 | segmentManager.setPlayheadTime(time); 51 | lastPlayheadTimeReported = time; 52 | } 53 | }, 500); 54 | }); 55 | 56 | debug("register request filter"); 57 | player.getNetworkingEngine().registerRequestFilter((requestType: number, request: any) => { 58 | request.p2pml = {player, segmentManager}; 59 | }); 60 | } 61 | 62 | function registerParserProxies() { 63 | debug("register parser proxies"); 64 | shaka.media.ManifestParser.registerParserByExtension("mpd", ShakaDashManifestParserProxy); 65 | shaka.media.ManifestParser.registerParserByMime("application/dash+xml", ShakaDashManifestParserProxy); 66 | shaka.media.ManifestParser.registerParserByExtension("m3u8", ShakaHlsManifestParserProxy); 67 | shaka.media.ManifestParser.registerParserByMime("application/x-mpegurl", ShakaHlsManifestParserProxy); 68 | shaka.media.ManifestParser.registerParserByMime("application/vnd.apple.mpegurl", ShakaHlsManifestParserProxy); 69 | } 70 | 71 | function initializeNetworkingEngine() { 72 | debug("init networking engine"); 73 | shaka.net.NetworkingEngine.registerScheme("http", processNetworkRequest); 74 | shaka.net.NetworkingEngine.registerScheme("https", processNetworkRequest); 75 | } 76 | 77 | function processNetworkRequest(uri: string, request: any, requestType: number, progressUpdated?: Function) { 78 | if (!request.p2pml) { 79 | return shaka.net.HttpXHRPlugin(uri, request, requestType, progressUpdated); 80 | } 81 | 82 | const { player, segmentManager }: { player: any, segmentManager: SegmentManager } = request.p2pml; 83 | let assetsStorage = segmentManager.getSettings().assetsStorage; 84 | let masterManifestUri: string | undefined; 85 | let masterSwarmId: string | undefined; 86 | 87 | if (assetsStorage !== undefined 88 | && player.getNetworkingEngine().p2pml !== undefined 89 | && player.getNetworkingEngine().p2pml.masterManifestUri !== undefined) { 90 | masterManifestUri = player.getNetworkingEngine().p2pml.masterManifestUri as string; 91 | masterSwarmId = getMasterSwarmId(masterManifestUri, segmentManager.getSettings()); 92 | } else { 93 | assetsStorage = undefined; 94 | } 95 | 96 | let segment: ParserSegment | undefined; 97 | const manifest = player.getManifest(); 98 | 99 | if (requestType === shaka.net.NetworkingEngine.RequestType.SEGMENT 100 | && manifest !== null 101 | && manifest.p2pml !== undefined 102 | && manifest.p2pml.parser !== undefined) { 103 | segment = manifest.p2pml.parser.find(uri, request.headers.Range); 104 | } 105 | 106 | if (segment !== undefined && segment.streamType === "video") { // load segment using P2P loader 107 | debug("request", "load", segment.identity); 108 | 109 | const promise = segmentManager.load(segment, getSchemedUri(player.getAssetUri ? player.getAssetUri() : player.getManifestUri()), getPlayheadTime(player)); 110 | 111 | const abort = async () => { 112 | debug("request", "abort", segment!.identity); 113 | // TODO: implement abort in SegmentManager 114 | }; 115 | 116 | return new shaka.util.AbortableOperation(promise, abort); 117 | } else if (assetsStorage) { // load or store the asset using assets storage 118 | const responsePromise = (async () => { 119 | const asset = await assetsStorage.getAsset(uri, request.headers.Range, masterSwarmId!); 120 | if (asset !== undefined) { 121 | return { 122 | data: asset.data, 123 | uri: asset.responseUri, 124 | fromCache: true 125 | }; 126 | } else { 127 | const response = await shaka.net.HttpXHRPlugin(uri, request, requestType, progressUpdated).promise; 128 | assetsStorage.storeAsset({ 129 | masterManifestUri: masterManifestUri!, 130 | masterSwarmId: masterSwarmId!, 131 | requestUri: uri, 132 | requestRange: request.headers.Range, 133 | responseUri: response.uri, 134 | data: response.data 135 | }); 136 | return response; 137 | } 138 | })(); 139 | return new shaka.util.AbortableOperation(responsePromise, async () => {}); 140 | } else { // load asset using default plugin 141 | return shaka.net.HttpXHRPlugin(uri, request, requestType, progressUpdated); 142 | } 143 | } 144 | 145 | function getPlayheadTime(player: any): number { 146 | let time = 0; 147 | 148 | const date = player.getPlayheadTimeAsDate(); 149 | if (date) { 150 | time = date.valueOf(); 151 | if (player.isLive()) { 152 | time -= player.getPresentationStartTimeAsDate().valueOf(); 153 | } 154 | time /= 1000; 155 | } 156 | 157 | return time; 158 | } 159 | -------------------------------------------------------------------------------- /FAQ.md: -------------------------------------------------------------------------------- 1 | # P2P Media Loader - FAQ 2 | 3 | Table of contents: 4 | - [What is tracker?](#what-is-tracker) 5 | - [Don't use public trackers in production](#dont-use-public-trackers-in-production) 6 | - [How to achieve better P2P ratio for live streams?](#how-to-achieve-better-p2p-ratio-for-live-streams) 7 | - [How to achieve better P2P ratio for VOD streams?](#how-to-achieve-better-p2p-ratio-for-vod-streams) 8 | - [What are the requirements to share a stream over P2P?](#what-are-the-requirements-to-share-a-stream-over-p2p) 9 | - [Is it possible to have 100% P2P ratio?](#is-it-possible-to-have-100-p2p-ratio) 10 | - [What happens if there are no peers on a stream?](#what-happens-if-there-are-no-peers-on-a-stream) 11 | - [How to configure personal tracker and stun servers?](#how-to-configure-personal-tracker-and-stun-servers) 12 | - [How to manually set swarm ID?](#how-to-manually-set-swarm-id) 13 | - [How to see that P2P is actually working?](#how-to-see-that-p2p-is-actually-working) 14 | 15 | ## What is tracker? 16 | 17 | `P2P Media Loader` uses WebTorrent compatible trackers to do [WebRTC](https://en.wikipedia.org/wiki/WebRTC) signaling - exchanging [SDP](https://en.wikipedia.org/wiki/Session_Description_Protocol) data between peers to connect them into a swarm. 18 | 19 | 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). 20 | 21 | Any compatible WebTorrent tracker works for `P2P Media Loader`: 22 | - [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. 23 | - [bittorrent-tracker](https://github.com/webtorrent/bittorrent-tracker) - tracker from WebTorrent project that uses Node.js I/O 24 | 25 | ## Don't use public trackers in production 26 | 27 | [Public trackers](https://openwebtorrent.com/) allow quickly begin development and testing of P2P technologies on the web. 28 | But they support a limited number of peers and can reject connections or even go down on a heavy loads. 29 | 30 | That is why they can't be used in production environments. Consider running your personal tracker or buy resources from a tracker provider to go stable. 31 | 32 | ## How to achieve better P2P ratio for live streams? 33 | 34 | The default configuration works best for live streams with 15-20 segments in the playlist. The segments duration sohould be about 5 seconds. 35 | 36 | ## How to achieve better P2P ratio for VOD streams? 37 | 38 | An example of a good configuration tested in production for a VOD stream with segments 20 seconds long each: 39 | 40 | ```javascript 41 | segments:{ 42 | // number of segments to pass for processing to P2P algorithm 43 | forwardSegmentCount:50, // usually should be equal or greater than p2pDownloadMaxPriority and httpDownloadMaxPriority 44 | }, 45 | loader:{ 46 | // how long to store the downloaded segments for P2P sharing 47 | cachedSegmentExpiration:86400000, 48 | // count of the downloaded segments to store for P2P sharing 49 | cachedSegmentsCount:1000, 50 | 51 | // first 4 segments (priorities 0, 1, 2 and 3) are required buffer for stable playback 52 | requiredSegmentsPriority:3, 53 | 54 | // each 1 second each of 10 segments ahead of playhead position gets 6% probability for random HTTP download 55 | httpDownloadMaxPriority:9, 56 | httpDownloadProbability:0.06, 57 | httpDownloadProbabilityInterval: 1000, 58 | 59 | // disallow randomly download segments over HTTP if there are no connected peers 60 | httpDownloadProbabilitySkipIfNoPeers: true, 61 | 62 | // P2P will try to download only first 51 segment ahead of playhead position 63 | p2pDownloadMaxPriority: 50, 64 | 65 | // 1 second timeout before retrying HTTP download of a segment in case of an error 66 | httpFailedSegmentTimeout:1000, 67 | 68 | // number of simultaneous downloads for P2P and HTTP methods 69 | simultaneousP2PDownloads:20, 70 | simultaneousHttpDownloads:3, 71 | 72 | // enable mode, that try to prevent HTTP downloads on stream start-up 73 | httpDownloadInitialTimeout: 120000, // try to prevent HTTP downloads during first 2 minutes 74 | httpDownloadInitialTimeoutPerSegment: 17000, // try to prevent HTTP download per segment during first 17 seconds 75 | 76 | // allow to continue aborted P2P downloads via HTTP 77 | httpUseRanges: true, 78 | } 79 | ``` 80 | 81 | ## What are the requirements to share a stream over P2P? 82 | 83 | The requirements to share a stream over P2P are: 84 | - 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). 85 | - 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. 86 | - 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. 87 | 88 | ## Is it possible to have 100% P2P ratio? 89 | 90 | It is possible for a single peer but not possible for a swarm of peers in total. 91 | 92 | P2P Media Loader implements approach of P2P assisted video delivery. It means that the stream should be downloaded via HTTP(S) at least once to be shared between peers in a swarm. 93 | 94 | 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. 95 | 96 | 97 | ## What happens if there are no peers on a stream? 98 | 99 | 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. 100 | 101 | ## How to configure personal tracker and STUN servers? 102 | 103 | ```javascript 104 | const config = { 105 | loader: { 106 | trackerAnnounce: [ 107 | "wss://personal.tracker1.com", 108 | "wss://personal.tracker2.com" 109 | ], 110 | rtcConfig: { 111 | iceServers: [ 112 | { urls: "stun:stun.l.google.com:19302" }, 113 | { urls: "stun:global.stun.twilio.com:3478?transport=udp" } 114 | ] 115 | } 116 | } 117 | }; 118 | 119 | const engineHlsJs = new p2pml.hlsjs.Engine(config); 120 | // or 121 | const engineShaka = new p2pml.shaka.Engine(config); 122 | ``` 123 | ## How to manually set swarm ID? 124 | 125 | ```javascript 126 | const config = { 127 | segments: { 128 | swarmId: "https://somecdn.com/mystream_12345.m3u8" // any unique string 129 | } 130 | }; 131 | 132 | const engineHlsJs = new p2pml.hlsjs.Engine(config); 133 | // or 134 | const engineShaka = new p2pml.shaka.Engine(config); 135 | ``` 136 | ## How to see that P2P is actually working? 137 | 138 | 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: 139 | 140 | ```javascript 141 | const engine = new p2pml.hlsjs.Engine(); 142 | 143 | engine.on("peer_connect", peer => console.log("peer_connect", peer.id, peer.remoteAddress)); 144 | engine.on("peer_close", peerId => console.log("peer_close", peerId)); 145 | engine.on("segment_loaded", (segment, peerId) => console.log("segment_loaded from", peerId ? `peer ${peerId}` : "HTTP", segment.url)); 146 | ``` 147 | 148 | Open few P2P enabled players with the same stream so they can connect. 149 | -------------------------------------------------------------------------------- /p2p-media-loader-core/lib/http-media-manager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as Debug from "debug"; 18 | import { STEEmitter } from "./stringly-typed-event-emitter"; 19 | import { Segment } from "./loader-interface"; 20 | import { SegmentValidatorCallback, XhrSetupCallback, SegmentUrlBuilder } from "./hybrid-loader"; 21 | 22 | export class HttpMediaManager extends STEEmitter< 23 | "segment-loaded" | "segment-error" | "bytes-downloaded" 24 | > { 25 | 26 | private xhrRequests: Map = new Map(); 27 | private failedSegments: Map = new Map(); 28 | private debug = Debug("p2pml:http-media-manager"); 29 | 30 | public constructor(readonly settings: { 31 | httpFailedSegmentTimeout: number, 32 | httpUseRanges: boolean, 33 | segmentValidator?: SegmentValidatorCallback, 34 | xhrSetup?: XhrSetupCallback 35 | segmentUrlBuilder?: SegmentUrlBuilder 36 | }) { 37 | super(); 38 | } 39 | 40 | public download(segment: Segment, downloadedPieces?: ArrayBuffer[]): void { 41 | if (this.isDownloading(segment)) { 42 | return; 43 | } 44 | 45 | this.cleanTimedOutFailedSegments(); 46 | 47 | const segmentUrl = this.settings.segmentUrlBuilder 48 | ? this.settings.segmentUrlBuilder(segment) 49 | : segment.url; 50 | 51 | this.debug("http segment download", segmentUrl); 52 | 53 | segment.requestUrl = segmentUrl; 54 | 55 | const xhr = new XMLHttpRequest(); 56 | xhr.open("GET", segmentUrl, true); 57 | xhr.responseType = "arraybuffer"; 58 | 59 | if (segment.range) { 60 | xhr.setRequestHeader("Range", segment.range); 61 | downloadedPieces = undefined; // TODO: process downloadedPieces for segments with range headers too 62 | } else if ((downloadedPieces !== undefined) && this.settings.httpUseRanges) { 63 | let bytesDownloaded = 0; 64 | for (const piece of downloadedPieces) { 65 | bytesDownloaded += piece.byteLength; 66 | } 67 | 68 | xhr.setRequestHeader("Range", `bytes=${bytesDownloaded}-`); 69 | 70 | this.debug("continue download from", bytesDownloaded); 71 | } else { 72 | downloadedPieces = undefined; 73 | } 74 | 75 | this.setupXhrEvents(xhr, segment, downloadedPieces); 76 | 77 | if (this.settings.xhrSetup) { 78 | this.settings.xhrSetup(xhr, segmentUrl); 79 | } 80 | 81 | this.xhrRequests.set(segment.id, {xhr, segment}); 82 | xhr.send(); 83 | } 84 | 85 | public abort(segment: Segment): void { 86 | const request = this.xhrRequests.get(segment.id); 87 | 88 | if (request) { 89 | request.xhr.abort(); 90 | this.xhrRequests.delete(segment.id); 91 | this.debug("http segment abort", segment.id); 92 | } 93 | } 94 | 95 | public isDownloading(segment: Segment): boolean { 96 | return this.xhrRequests.has(segment.id); 97 | } 98 | 99 | public isFailed(segment: Segment): boolean { 100 | const time = this.failedSegments.get(segment.id); 101 | return time !== undefined && time > this.now(); 102 | } 103 | 104 | public getActiveDownloads(): ReadonlyMap { 105 | return this.xhrRequests; 106 | } 107 | 108 | public getActiveDownloadsCount(): number { 109 | return this.xhrRequests.size; 110 | } 111 | 112 | public destroy(): void { 113 | this.xhrRequests.forEach(request => request.xhr.abort()); 114 | this.xhrRequests.clear(); 115 | } 116 | 117 | private setupXhrEvents(xhr: XMLHttpRequest, segment: Segment, downloadedPieces?: ArrayBuffer[]) { 118 | let prevBytesLoaded = 0; 119 | 120 | xhr.addEventListener("progress", (event: any) => { 121 | const bytesLoaded = event.loaded - prevBytesLoaded; 122 | this.emit("bytes-downloaded", bytesLoaded); 123 | prevBytesLoaded = event.loaded; 124 | }); 125 | 126 | xhr.addEventListener("load", async (event: any) => { 127 | if ((event.target.status < 200) || (event.target.status >= 300)) { 128 | this.segmentFailure(segment, event, xhr); 129 | return; 130 | } 131 | 132 | let data = event.target.response; 133 | 134 | if ((downloadedPieces !== undefined) && (event.target.status === 206)) { 135 | let bytesDownloaded = 0; 136 | for (const piece of downloadedPieces) { 137 | bytesDownloaded += piece.byteLength; 138 | } 139 | 140 | const segmentData = new Uint8Array(bytesDownloaded + data.byteLength); 141 | let offset = 0; 142 | 143 | for (const piece of downloadedPieces) { 144 | segmentData.set(new Uint8Array(piece), offset); 145 | offset += piece.byteLength; 146 | } 147 | 148 | segmentData.set(new Uint8Array(data), offset); 149 | data = segmentData.buffer; 150 | } 151 | 152 | await this.segmentDownloadFinished(segment, data, xhr); 153 | }); 154 | 155 | xhr.addEventListener("error", (event: any) => { 156 | this.segmentFailure(segment, event, xhr); 157 | }); 158 | 159 | xhr.addEventListener("timeout", (event: any) => { 160 | this.segmentFailure(segment, event, xhr); 161 | }); 162 | } 163 | 164 | private async segmentDownloadFinished(segment: Segment, data: ArrayBuffer, xhr: XMLHttpRequest) { 165 | segment.responseUrl = xhr.responseURL === null ? undefined : xhr.responseURL; 166 | 167 | if (this.settings.segmentValidator) { 168 | try { 169 | await this.settings.segmentValidator({ ...segment, data: data }, "http"); 170 | } catch (error) { 171 | this.debug("segment validator failed", error); 172 | this.segmentFailure(segment, error, xhr); 173 | return; 174 | } 175 | } 176 | 177 | this.xhrRequests.delete(segment.id); 178 | this.emit("segment-loaded", segment, data); 179 | } 180 | 181 | private segmentFailure(segment: Segment, error: any, xhr: XMLHttpRequest) { 182 | segment.responseUrl = xhr.responseURL === null ? undefined : xhr.responseURL; 183 | 184 | this.xhrRequests.delete(segment.id); 185 | this.failedSegments.set(segment.id, this.now() + this.settings.httpFailedSegmentTimeout); 186 | this.emit("segment-error", segment, error); 187 | } 188 | 189 | private cleanTimedOutFailedSegments() { 190 | const now = this.now(); 191 | const candidates: string[] = []; 192 | 193 | this.failedSegments.forEach((time, id) => { 194 | if (time < now) { 195 | candidates.push(id); 196 | } 197 | }); 198 | 199 | candidates.forEach(id => this.failedSegments.delete(id)); 200 | } 201 | 202 | private now = () => performance.now(); 203 | 204 | } 205 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/demo/offlineplayback.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Offline playback with Shaka Player engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 188 | 189 | 190 | 191 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/demo/offlineplayback.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | Offline playback with hls.js engine and P2P demo 23 | 24 | 25 | 26 | 27 | 28 | 29 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 203 | 204 | 205 | 206 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/lib/segment-manager.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2018 Novage LLC. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | import * as Debug from "debug"; 18 | import { Events, Segment as LoaderSegment, LoaderInterface } from "p2p-media-loader-core"; 19 | import { ParserSegment } from "./parser-segment"; 20 | import { getMasterSwarmId } from "./utils"; 21 | import { AssetsStorage } from "./engine"; 22 | 23 | const defaultSettings: SegmentManagerSettings = { 24 | forwardSegmentCount: 20, 25 | maxHistorySegments: 50, 26 | swarmId: undefined, 27 | assetsStorage: undefined, 28 | }; 29 | 30 | export class SegmentManager { 31 | 32 | private readonly debug = Debug("p2pml:shaka:sm"); 33 | private readonly loader: LoaderInterface; 34 | private readonly requests: Map = new Map(); 35 | private manifestUri: string = ""; 36 | private playheadTime: number = 0; 37 | private readonly segmentHistory: ParserSegment[] = []; 38 | private readonly settings: SegmentManagerSettings; 39 | 40 | public constructor(loader: LoaderInterface, settings: Partial = {}) { 41 | this.settings = { ...defaultSettings, ...settings }; 42 | 43 | this.loader = loader; 44 | this.loader.on(Events.SegmentLoaded, this.onSegmentLoaded); 45 | this.loader.on(Events.SegmentError, this.onSegmentError); 46 | this.loader.on(Events.SegmentAbort, this.onSegmentAbort); 47 | } 48 | 49 | public async destroy() { 50 | if (this.requests.size !== 0) { 51 | console.error("Destroying segment manager with active request(s)!"); 52 | 53 | for (const request of this.requests.values()) { 54 | this.reportError(request, "Request aborted due to destroy call"); 55 | } 56 | 57 | this.requests.clear(); 58 | } 59 | 60 | this.playheadTime = 0; 61 | this.segmentHistory.splice(0); 62 | 63 | if (this.settings.assetsStorage !== undefined) { 64 | await this.settings.assetsStorage.destroy(); 65 | } 66 | 67 | await this.loader.destroy(); 68 | } 69 | 70 | public getSettings() { 71 | return this.settings; 72 | } 73 | 74 | public async load(parserSegment: ParserSegment, manifestUri: string, playheadTime: number): Promise<{ data: ArrayBuffer, timeMs: number | undefined }> { 75 | this.manifestUri = manifestUri; 76 | this.playheadTime = playheadTime; 77 | 78 | this.pushSegmentHistory(parserSegment); 79 | 80 | const lastRequestedSegment = this.refreshLoad(); 81 | 82 | const alreadyLoadedSegment = await this.loader.getSegment(lastRequestedSegment.id); 83 | 84 | return new Promise<{ data: ArrayBuffer, timeMs: number | undefined }>((resolve, reject) => { 85 | const request = new Request(lastRequestedSegment.id, resolve, reject); 86 | if (alreadyLoadedSegment) { 87 | this.reportSuccess(request, alreadyLoadedSegment); 88 | } else { 89 | this.debug("request add", request.id); 90 | this.requests.set(request.id, request); 91 | } 92 | }); 93 | } 94 | 95 | public setPlayheadTime(time: number) { 96 | this.playheadTime = time; 97 | 98 | if (this.segmentHistory.length > 0) { 99 | this.refreshLoad(); 100 | } 101 | } 102 | 103 | private refreshLoad(): LoaderSegment { 104 | const lastRequestedSegment = this.segmentHistory[ this.segmentHistory.length - 1 ]; 105 | const safePlayheadTime = this.playheadTime > 0.1 ? this.playheadTime : lastRequestedSegment.start; 106 | const sequence: ParserSegment[] = this.segmentHistory.reduce((a: ParserSegment[], i) => { 107 | if (i.start >= safePlayheadTime) { 108 | a.push(i); 109 | } 110 | return a; 111 | }, []); 112 | 113 | if (sequence.length === 0) { 114 | sequence.push(lastRequestedSegment); 115 | } 116 | 117 | const lastRequestedSegmentIndex = sequence.length - 1; 118 | 119 | do { 120 | const next = sequence[ sequence.length - 1 ].next(); 121 | if (next) { 122 | sequence.push(next); 123 | } else { 124 | break; 125 | } 126 | } while (sequence.length < this.settings.forwardSegmentCount); 127 | 128 | const masterSwarmId = getMasterSwarmId(this.manifestUri, this.settings); 129 | 130 | const loaderSegments: LoaderSegment[] = sequence.map((s, i) => ({ 131 | id: `${masterSwarmId}+${s.streamIdentity}+${s.identity}`, 132 | url: s.uri, 133 | masterSwarmId: masterSwarmId, 134 | masterManifestUri: this.manifestUri, 135 | streamId: s.streamIdentity, 136 | sequence: s.identity, 137 | range: s.range, 138 | priority: i, 139 | })); 140 | 141 | this.loader.load(loaderSegments, `${masterSwarmId}+${lastRequestedSegment.streamIdentity}`); 142 | return loaderSegments[ lastRequestedSegmentIndex ]; 143 | } 144 | 145 | private pushSegmentHistory(segment: ParserSegment) { 146 | if (this.segmentHistory.length >= this.settings.maxHistorySegments) { 147 | this.debug("segment history auto shrink"); 148 | this.segmentHistory.splice(0, this.settings.maxHistorySegments * 0.2); 149 | } 150 | 151 | if (this.segmentHistory.length > 0 && this.segmentHistory[ this.segmentHistory.length - 1 ].start > segment.start) { 152 | this.debug("segment history reset due to playhead seek back"); 153 | this.segmentHistory.splice(0); 154 | } 155 | 156 | this.segmentHistory.push(segment); 157 | } 158 | 159 | private reportSuccess(request: Request, loaderSegment: LoaderSegment) { 160 | let timeMs: number | undefined; 161 | 162 | if (loaderSegment.downloadBandwidth !== undefined && loaderSegment.downloadBandwidth > 0 && loaderSegment.data && loaderSegment.data.byteLength > 0) { 163 | timeMs = Math.trunc(loaderSegment.data.byteLength / loaderSegment.downloadBandwidth); 164 | } 165 | 166 | this.debug("report success", request.id); 167 | request.resolve({ data: loaderSegment.data!, timeMs }); 168 | } 169 | 170 | private reportError(request: Request, error: any) { 171 | if (request.reject) { 172 | this.debug("report error", request.id); 173 | request.reject(error); 174 | } 175 | } 176 | 177 | private onSegmentLoaded = (segment: LoaderSegment) => { 178 | if (this.requests.has(segment.id)) { 179 | this.reportSuccess(this.requests.get(segment.id)!, segment); 180 | this.debug("request delete", segment.id); 181 | this.requests.delete(segment.id); 182 | } 183 | } 184 | 185 | private onSegmentError = (segment: LoaderSegment, error: any) => { 186 | if (this.requests.has(segment.id)) { 187 | this.reportError(this.requests.get(segment.id)!, error); 188 | this.debug("request delete from error", segment.id); 189 | this.requests.delete(segment.id); 190 | } 191 | } 192 | 193 | private onSegmentAbort = (segment: LoaderSegment) => { 194 | if (this.requests.has(segment.id)) { 195 | this.reportError(this.requests.get(segment.id)!, "Internal abort"); 196 | this.debug("request delete from abort", segment.id); 197 | this.requests.delete(segment.id); 198 | } 199 | } 200 | 201 | } // end of SegmentManager 202 | 203 | class Request { 204 | public constructor( 205 | readonly id: string, 206 | readonly resolve: (value: { data: ArrayBuffer, timeMs: number | undefined }) => void, 207 | readonly reject: (reason?: any) => void 208 | ) {} 209 | } 210 | 211 | export interface SegmentManagerSettings { 212 | /** 213 | * Number of segments for building up predicted forward segments sequence; used to predownload and share via P2P 214 | */ 215 | forwardSegmentCount: number; 216 | 217 | /** 218 | * Maximum amount of requested segments manager should remember; used to build up sequence with correct priorities for P2P sharing 219 | */ 220 | maxHistorySegments: number; 221 | 222 | /** 223 | * Override default swarm ID that is used to identify unique media stream with trackers (manifest URL without 224 | * query parameters is used as the swarm ID if the parameter is not specified) 225 | */ 226 | swarmId?: string; 227 | 228 | /** 229 | * A storage for the downloaded assets: manifests, subtitles, init segments, DRM assets etc. By default the assets are not stored. 230 | */ 231 | assetsStorage?: AssetsStorage; 232 | } 233 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /p2p-media-loader-core/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /p2p-media-loader-hlsjs/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /p2p-media-loader-shaka/LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | --------------------------------------------------------------------------------