Skip to content

Commit 7199c8f

Browse files
committed
Another fix for Safari: use JPEG if WEBP not supported
1 parent d31d591 commit 7199c8f

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

client/src/lib/player_view/VideoPlayer.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,12 @@ export function getScreenshot() : string
442442
if (!ctx) throw new Error("Cannot get canvas context");
443443
// ctx.drawImage(videoElem, 0, 0); // Removed, as bgr frame capture is now done when draw mode is entered
444444
ctx.drawImage(draw_canvas, 0, 0);
445-
return comb.toDataURL("image/webp", 0.8);
445+
// Try WebP first, fall back to JPEG if not supported (Safari doesn't support WebP encoding)
446+
const webp = comb.toDataURL("image/webp", 0.8);
447+
if (webp.startsWith("data:image/webp")) {
448+
return webp;
449+
}
450+
return comb.toDataURL("image/jpeg", 0.85);
446451
}
447452
448453
export async function collabPlay(seek_time: number, looping: boolean) {

server/src/api_server/ws_handers.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,13 @@ pub async fn msg_add_comment(data: &proto::client::client_to_server_cmd::AddComm
268268
// Convert data URI to bytes
269269
let img_uri = DataUrl::process(&d).map_err(|e| anyhow!("Invalid drawing data URI"))?;
270270

271-
if img_uri.mime_type().type_ != "image" || img_uri.mime_type().subtype != "webp" {
272-
bail!("Invalid mimetype in drawing: {:?}", img_uri.mime_type())
273-
}
271+
let mime = img_uri.mime_type();
272+
let ext = match (mime.type_.as_str(), mime.subtype.as_str()) {
273+
("image", "webp") => "webp",
274+
("image", "jpeg") => "jpg",
275+
("image", "png") => "png",
276+
_ => bail!("Invalid mimetype in drawing: {:?}", mime),
277+
};
274278
let img_data = img_uri.decode_to_vec().map_err(|e| anyhow!("Failed to decode drawing data URI: {:?}", e))?;
275279

276280
// Make up a filename
@@ -281,7 +285,7 @@ pub async fn msg_add_comment(data: &proto::client::client_to_server_cmd::AddComm
281285
hex::encode(result)
282286
}
283287
let short_csum = sha256hex(img_data.0.as_ref())[..16].to_string();
284-
let fname = format!("{}.webp", short_csum);
288+
let fname = format!("{}.{}", short_csum, ext);
285289

286290
// Write to file
287291
let drawing_path = server.media_files_dir.join(&media_file_id).join("drawings").join(&fname);

0 commit comments

Comments
 (0)