Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit 835c58b

Browse files
fix: added back a missed bracket
1 parent 1c2fc22 commit 835c58b

File tree

1 file changed

+84
-80
lines changed

1 file changed

+84
-80
lines changed

src/index.js

+84-80
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,109 @@
11
'use strict'
22
function HlsjsIPFSLoaderFactory (ipfs) {
33
return class HlsjsIPFSLoader {
4-
constructor (config) {
5-
this._abortFlag = [ false ];
4+
constructor(config) {
5+
this._abortFlag = [false];
66
this.ipfs = ipfs;
77
this.hash = config.ipfsHash;
8-
this.debug = config.debug === false ? function () {} : config.debug === true ? console.log : config.debug;
8+
this.debug = config.debug === false ? function () {
9+
} : config.debug === true ? console.log : config.debug;
910
this.m3u8provider = config.m3u8provider ?? null;
1011
this.tsListProvider = config.tsListProvider ?? null;
1112
}
1213

13-
destroy() {
14-
}
15-
16-
abort() {
17-
this._abortFlag[0] = true;
18-
}
14+
destroy() {
15+
}
1916

20-
load(context, config, callbacks) {
21-
this.context = context
22-
this.config = config
23-
this.callbacks = callbacks
24-
this.stats = { trequest: performance.now(), retry: 0 }
25-
this.retryDelay = config.retryDelay
26-
this.loadInternal()
27-
}
28-
/**
29-
* Call this by getting the HLSIPFSLoader instance from hls.js hls.coreComponents[0].loaders.manifest.setM3U8Provider()
30-
* @param {function} provider
31-
*/
32-
setM3U8Provider(provider) {
33-
this.m3u8provider = provider;
34-
}
35-
/**
36-
*
37-
* @param {function} provider
38-
*/
39-
setTsListProvider(provider) {
40-
this.tsListProvider = provider;
41-
}
17+
abort() {
18+
this._abortFlag[0] = true;
19+
}
4220

43-
loadInternal() {
44-
const { stats, context, callbacks } = this
21+
load(context, config, callbacks) {
22+
this.context = context
23+
this.config = config
24+
this.callbacks = callbacks
25+
this.stats = {trequest: performance.now(), retry: 0}
26+
this.retryDelay = config.retryDelay
27+
this.loadInternal()
28+
}
4529

46-
stats.tfirst = Math.max(performance.now(), stats.trequest)
47-
stats.loaded = 0
30+
/**
31+
* Call this by getting the HLSIPFSLoader instance from hls.js hls.coreComponents[0].loaders.manifest.setM3U8Provider()
32+
* @param {function} provider
33+
*/
34+
setM3U8Provider(provider) {
35+
this.m3u8provider = provider;
36+
}
4837

49-
//When using absolute path (https://example.com/index.html) vs https://example.com/
50-
const urlParts = window.location.href.split("/")
51-
if(urlParts[urlParts.length - 1] !== "") {
52-
urlParts[urlParts.length - 1] = ""
38+
/**
39+
*
40+
* @param {function} provider
41+
*/
42+
setTsListProvider(provider) {
43+
this.tsListProvider = provider;
5344
}
54-
const filename = context.url.replace(urlParts.join("/"), "")
5545

56-
const options = {}
57-
if (Number.isFinite(context.rangeStart)) {
46+
loadInternal() {
47+
const {stats, context, callbacks} = this
48+
49+
stats.tfirst = Math.max(performance.now(), stats.trequest)
50+
stats.loaded = 0
51+
52+
//When using absolute path (https://example.com/index.html) vs https://example.com/
53+
const urlParts = window.location.href.split("/")
54+
if (urlParts[urlParts.length - 1] !== "") {
55+
urlParts[urlParts.length - 1] = ""
56+
}
57+
const filename = context.url.replace(urlParts.join("/"), "")
58+
59+
const options = {}
60+
if (Number.isFinite(context.rangeStart)) {
5861
options.offset = context.rangeStart;
5962
if (Number.isFinite(context.rangeEnd)) {
60-
options.length = context.rangeEnd - context.rangeStart;
63+
options.length = context.rangeEnd - context.rangeStart;
6164
}
62-
}
65+
}
6366

64-
if(filename.split(".")[1] === "m3u8" && this.m3u8provider !== null) {
65-
const res = this.m3u8provider();
66-
let data;
67-
if(Buffer.isBuffer(res)) {
68-
data = buf2str(res)
69-
} else {
70-
data = res;
67+
if (filename.split(".")[1] === "m3u8" && this.m3u8provider !== null) {
68+
const res = this.m3u8provider();
69+
let data;
70+
if (Buffer.isBuffer(res)) {
71+
data = buf2str(res)
72+
} else {
73+
data = res;
74+
}
75+
const response = {url: context.url, data: data}
76+
callbacks.onSuccess(response, stats, context)
77+
return;
7178
}
72-
const response = { url: context.url, data: data }
73-
callbacks.onSuccess(response, stats, context)
74-
return;
75-
}
76-
if(filename.split(".")[1] === "m3u8" && this.tsListProvider !== null) {
77-
var tslist = this.tsListProvider();
78-
var hash = tslist[filename];
79-
if(hash) {
80-
this.cat(hash).then(res => {
81-
let data;
82-
if(Buffer.isBuffer(res)) {
83-
data = buf2str(res)
84-
} else {
85-
data = res;
86-
}
87-
stats.loaded = stats.total = data.length
88-
stats.tload = Math.max(stats.tfirst, performance.now())
89-
const response = { url: context.url, data: data }
90-
callbacks.onSuccess(response, stats, context)
91-
});
79+
if (filename.split(".")[1] === "m3u8" && this.tsListProvider !== null) {
80+
var tslist = this.tsListProvider();
81+
var hash = tslist[filename];
82+
if (hash) {
83+
this.cat(hash).then(res => {
84+
let data;
85+
if (Buffer.isBuffer(res)) {
86+
data = buf2str(res)
87+
} else {
88+
data = res;
89+
}
90+
stats.loaded = stats.total = data.length
91+
stats.tload = Math.max(stats.tfirst, performance.now())
92+
const response = {url: context.url, data: data}
93+
callbacks.onSuccess(response, stats, context)
94+
});
95+
}
96+
return;
9297
}
93-
return;
98+
this._abortFlag[0] = false;
99+
getFile(this.ipfs, this.hash, filename, options, this.debug, this._abortFlag).then(res => {
100+
const data = (context.responseType === 'arraybuffer') ? res : buf2str(res)
101+
stats.loaded = stats.total = data.length
102+
stats.tload = Math.max(stats.tfirst, performance.now())
103+
const response = {url: context.url, data: data}
104+
callbacks.onSuccess(response, stats, context)
105+
}, console.error)
94106
}
95-
this._abortFlag[0] = false;
96-
getFile(this.ipfs, this.hash, filename, options, this.debug, this._abortFlag).then(res => {
97-
const data = (context.responseType === 'arraybuffer') ? res : buf2str(res)
98-
stats.loaded = stats.total = data.length
99-
stats.tload = Math.max(stats.tfirst, performance.now())
100-
const response = { url: context.url, data: data }
101-
callbacks.onSuccess(response, stats, context)
102-
}, console.error)
103107
}
104108
}
105109
async function getFile(ipfs, rootHash, filename, options, debug, abortFlag) {

0 commit comments

Comments
 (0)