Moved peer connections to an optional pull model

This commit is contained in:
Mitchell McCaffrey
2020-12-11 13:24:39 +11:00
parent b40f78042f
commit 6a4c6b30ec
8 changed files with 246 additions and 182 deletions

View File

@@ -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]);