Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Keep going if loading the image blurrer worker fails
Until now it was assumed that loading the image blurrer worker would not
fail. However, if the browser does not support the CSP "worker-src"
directive (like Safari) trying to load the worker would throw an
exception which would interrupt the load of Talk itself. Now the
exception is caught and logged instead, and the image blurrer reverts to
a synced generation if no worker is available (although that should not
happen, as the image blurrer is used only on Chromium and Chromium
supports the "worker-src" directive).

Note that Firefox does not throw an exception when loading a worker if
not allowed by the CSP. Moreover, as the worker object is created, it
does not seem to be possible to know if the worker is actually not
available. This is not a problem, though; the image blurrer is not used
on Firefox, and even if it was Firefox supports the "worker-src"
directive.

Signed-off-by: Daniel Calviño Sánchez <[email protected]>
  • Loading branch information
danxuliu authored and backportbot[bot] committed Jan 7, 2021
commit 4706f899af487aa320ad1d054f72a59bd81aa3bb
25 changes: 15 additions & 10 deletions src/utils/imageBlurrer.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,27 @@

import { generateFilePath } from '@nextcloud/router'

const worker = new Worker(generateFilePath('spreed', '', 'js/image-blurrer-worker.js'))
let worker = null

const pendingResults = {}
let pendingResultsNextId = 0

worker.onmessage = function(message) {
const pendingResult = pendingResults[message.data.id]
if (!pendingResult) {
console.debug('No pending result for blurring image with id ' + message.data.id)
try {
worker = new Worker(generateFilePath('spreed', '', 'js/image-blurrer-worker.js'))
worker.onmessage = function(message) {
const pendingResult = pendingResults[message.data.id]
if (!pendingResult) {
console.debug('No pending result for blurring image with id ' + message.data.id)

return
}
return
}

pendingResult(message.data.blurredImageAsDataUrl)
pendingResult(message.data.blurredImageAsDataUrl)

delete pendingResults[message.data.id]
delete pendingResults[message.data.id]
}
} catch (exception) {
console.error('Image blurrer worker could not be loaded', exception)
}

function blurSync(image, width, height, blurRadius) {
Expand All @@ -54,7 +59,7 @@ function blurSync(image, width, height, blurRadius) {
}

export default function blur(image, width, height, blurRadius) {
if (typeof OffscreenCanvas === 'undefined') {
if (!worker || typeof OffscreenCanvas === 'undefined') {
return blurSync(image, width, height, blurRadius)
}

Expand Down