Moved peer connections to an optional pull model
This commit is contained in:
@@ -11,7 +11,28 @@ function useDataSource(data, defaultSources, unknownSource) {
|
||||
}
|
||||
let url = unknownSource;
|
||||
if (data.type === "file") {
|
||||
url = URL.createObjectURL(new Blob([data.file]));
|
||||
if (data.resolutions) {
|
||||
// Check is a resolution is specified
|
||||
if (data.quality && data.resolutions[data.quality]) {
|
||||
url = URL.createObjectURL(
|
||||
new Blob([data.resolutions[data.quality].file])
|
||||
);
|
||||
}
|
||||
// If no file available fallback to the highest resolution
|
||||
else if (!data.file) {
|
||||
const resolutionArray = Object.keys(data.resolutions);
|
||||
url = URL.createObjectURL(
|
||||
new Blob([
|
||||
data.resolutions[resolutionArray[resolutionArray.length - 1]]
|
||||
.file,
|
||||
])
|
||||
);
|
||||
} else {
|
||||
url = URL.createObjectURL(new Blob([data.file]));
|
||||
}
|
||||
} else {
|
||||
url = URL.createObjectURL(new Blob([data.file]));
|
||||
}
|
||||
} else if (data.type === "default") {
|
||||
url = defaultSources[data.key];
|
||||
}
|
||||
@@ -19,7 +40,10 @@ function useDataSource(data, defaultSources, unknownSource) {
|
||||
|
||||
return () => {
|
||||
if (data.type === "file" && url) {
|
||||
URL.revokeObjectURL(url);
|
||||
// Remove file url after 5 seconds as we still may be using it while the next image loads
|
||||
setTimeout(() => {
|
||||
URL.revokeObjectURL(url);
|
||||
}, 5000);
|
||||
}
|
||||
};
|
||||
}, [data, defaultSources, unknownSource]);
|
||||
|
||||
Reference in New Issue
Block a user