mirror of
https://github.com/rustdesk/rustdesk.git
synced 2026-09-09 05:51:00 +03:00
WebClient: 3.44 webcodecs offline (#15722)
* feat(web): zero-readback WebCodecs video path Decoded VideoFrames from js/src/webcodecs.js are handed to Flutter via window.onVideoFrame and imported GPU-side with createImageFromTextureSource; any failure unregisters the hook so the JS side falls back to RGBA readback. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(web): load bundled terminal font when Google CDNs are unreachable In air-gapped deployments GoogleFonts.robotoMono() cannot download the terminal font; when index.html signals offline mode, load the copy bundled with the web app under the family name google_fonts registers. Part of the fix for rustdesk/rustdesk-server-pro#996. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * ci: bump windows arm64 to Flutter 3.44.8, add web build patch script apply_flutter_3.44_web_patches.sh prepares a 3.44.x web build on top of the shared source patches: qr_code_scanner's web impl needs dart:ui_web for the removed platformViewRegistry, and flutter/web/fonts is refreshed to the font paths the 3.44 engine requests. The disabled build-rustdesk-web job runs it automatically once FLUTTER_VERSION moves to 3.44.x, and version-guarded 'Patch flutter' steps no longer fail when the guard does not match. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * fix(web): prevent stale WebCodecs frames across sessions Signed-off-by: fufesou <linlong1266@gmail.com> * fix(web): harden WebCodecs reconnect and Flutter 3.44 patches Signed-off-by: fufesou <linlong1266@gmail.com> * fix(ci): harden Flutter 3.44 patch input validation Validate required files before checking patch state, parameterize the theme-range validator, and prevent missing inputs from satisfying NO_MATCHES checks. Signed-off-by: fufesou <linlong1266@gmail.com> * Remove unused code Signed-off-by: fufesou <linlong1266@gmail.com> * fix(web): retry font loading and dispose stale decoded images Signed-off-by: fufesou <linlong1266@gmail.com> * remove unused code Signed-off-by: fufesou <linlong1266@gmail.com> * fix(web): Bad state: RenderBox was not laid out Signed-off-by: fufesou <linlong1266@gmail.com> --------- Signed-off-by: fufesou <linlong1266@gmail.com> Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: fufesou <linlong1266@gmail.com>
This commit is contained in:
@@ -2,14 +2,18 @@
|
||||
|
||||
import 'dart:convert';
|
||||
import 'dart:js_interop';
|
||||
import 'dart:js_interop_unsafe';
|
||||
import 'dart:typed_data';
|
||||
import 'dart:js';
|
||||
import 'dart:html';
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:ui_web' as ui_web;
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_hbb/common/widgets/login.dart';
|
||||
import 'package:flutter_hbb/models/state_model.dart';
|
||||
import 'package:flutter_hbb/models/web_video_frame_queue.dart';
|
||||
|
||||
import 'package:flutter_hbb/web/bridge.dart';
|
||||
import 'package:flutter_hbb/common.dart';
|
||||
@@ -18,6 +22,22 @@ import 'package:uuid/uuid.dart';
|
||||
final List<StreamSubscription<MouseEvent>> mouseListeners = [];
|
||||
final List<StreamSubscription<KeyboardEvent>> keyListeners = [];
|
||||
|
||||
// WebCodecs VideoFrames handed over from js/src/webcodecs.js arrive as plain
|
||||
// interop objects (the package language version predates extension types).
|
||||
// This side owns each frame and must close it quickly: hardware decoders
|
||||
// stall once their small output frame pool is exhausted.
|
||||
int _videoFrameWidth(JSObject frame) =>
|
||||
frame.getProperty<JSNumber>('displayWidth'.toJS).toDartInt;
|
||||
int _videoFrameHeight(JSObject frame) =>
|
||||
frame.getProperty<JSNumber>('displayHeight'.toJS).toDartInt;
|
||||
void _closeVideoFrame(JSObject frame) {
|
||||
try {
|
||||
frame.callMethod<JSAny?>('close'.toJS);
|
||||
} catch (error) {
|
||||
debugPrint('VideoFrame.close failed: $error');
|
||||
}
|
||||
}
|
||||
|
||||
typedef HandleEvent = Future<void> Function(Map<String, dynamic> evt);
|
||||
|
||||
class PlatformFFI {
|
||||
@@ -33,6 +53,13 @@ class PlatformFFI {
|
||||
}
|
||||
|
||||
PlatformFFI._() {
|
||||
_videoFrameQueue = WebVideoFrameQueue(
|
||||
importFrame: _importVideoFrame,
|
||||
closeFrame: _closeVideoFrame,
|
||||
disposeImage: (image) => image.dispose(),
|
||||
onImportError: _handleVideoFrameImportError,
|
||||
onCallbackError: _handleVideoImageCallbackError,
|
||||
);
|
||||
window.document.addEventListener(
|
||||
'visibilitychange',
|
||||
(event) => {
|
||||
@@ -162,6 +189,46 @@ class PlatformFFI {
|
||||
};
|
||||
}
|
||||
|
||||
late final WebVideoFrameQueue<JSObject, ui.Image> _videoFrameQueue;
|
||||
|
||||
// Zero-readback video path: the JS decoder hands decoded VideoFrames here
|
||||
// (checking typeof window.onVideoFrame before every frame), and the engine
|
||||
// imports them GPU-to-GPU via createImageBitmap. Unregistering the JS global
|
||||
// reverts the JS side to the RGBA readback path.
|
||||
void setVideoFrameCallback(
|
||||
Future<void> Function(int, ui.Image, bool Function()) fun) {
|
||||
_videoFrameQueue.beginSession(fun);
|
||||
if (!_videoFrameQueue.isEnabled) return;
|
||||
globalContext.setProperty(
|
||||
'onVideoFrame'.toJS,
|
||||
((JSNumber display, JSObject frame) {
|
||||
_videoFrameQueue.submit(display.toDartInt, frame);
|
||||
}).toJS,
|
||||
);
|
||||
}
|
||||
|
||||
void clearVideoFrameCallback() {
|
||||
_videoFrameQueue.endSession();
|
||||
globalContext.setProperty('onVideoFrame'.toJS, null);
|
||||
}
|
||||
|
||||
Future<ui.Image> _importVideoFrame(JSObject frame) async {
|
||||
return await ui_web.createImageFromTextureSource(frame,
|
||||
width: _videoFrameWidth(frame), height: _videoFrameHeight(frame));
|
||||
}
|
||||
|
||||
void _handleVideoFrameImportError(Object error, StackTrace stackTrace) {
|
||||
debugPrintStack(
|
||||
label: 'createImageFromTextureSource failed, using RGBA path: $error',
|
||||
stackTrace: stackTrace);
|
||||
globalContext.setProperty('onVideoFrame'.toJS, null);
|
||||
}
|
||||
|
||||
void _handleVideoImageCallbackError(Object error, StackTrace stackTrace) {
|
||||
debugPrintStack(
|
||||
label: 'video image callback error: $error', stackTrace: stackTrace);
|
||||
}
|
||||
|
||||
void startDesktopWebListener() {
|
||||
mouseListeners.add(
|
||||
window.document.onContextMenu.listen((evt) => evt.preventDefault()));
|
||||
|
||||
Reference in New Issue
Block a user