Appeareantly Firefox (and maybe Chrome) won't let service workers take over requests from <video> and <audio> tags, so we just fetch the URL ourselves.
const [srcState, loadSrc] = useAsyncCallback(
useCallback(
- () => getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo),
+ () => getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo, true),
[mx, url, useAuthentication, mimeType, encInfo]
)
);
const [srcState, loadSrc] = useAsyncCallback(
useCallback(
- () => getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo),
+ () => getFileSrcUrl(mxcUrlToHttp(mx, url, useAuthentication) ?? '', mimeType, encInfo, true),
[mx, url, useAuthentication, mimeType, encInfo]
)
);
export const getFileSrcUrl = async (
httpUrl: string,
mimeType: string,
- encInfo?: EncryptedAttachmentInfo
+ encInfo?: EncryptedAttachmentInfo,
+ forceFetch?: boolean
): Promise<string> => {
if (encInfo) {
if (typeof httpUrl !== 'string') throw new Error('Malformed event');
const decryptedBlob = await decryptFile(encData, mimeType, encInfo);
return URL.createObjectURL(decryptedBlob);
}
+ if (forceFetch) {
+ const res = await fetch(httpUrl, { method: 'GET' });
+ const blob = await res.blob();
+ return URL.createObjectURL(blob);
+ }
+
return httpUrl;
};