Skip to content

[camera_web] Migrate to package:web #7012

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
fda6409
Squash
Rexios80 Jun 28, 2024
83e183c
Fixing issues
Rexios80 Jun 28, 2024
fc97336
Fixing CI issues
Rexios80 Jun 28, 2024
04fcf95
Refactoring mocked functions to JSFunction
Rexios80 Jun 28, 2024
6f16798
Fixing tests
Rexios80 Jun 28, 2024
d28199a
Fixing tests
Rexios80 Jun 28, 2024
18ad29d
...
Rexios80 Jun 28, 2024
70790a0
...
Rexios80 Jun 28, 2024
4caa695
Revert "..."
Rexios80 Jun 28, 2024
252737a
...
Rexios80 Jun 28, 2024
bf29b16
...
Rexios80 Jun 29, 2024
0bc840f
Fix another test
Rexios80 Jun 29, 2024
3c95d15
Update flutter version constraints and set platform view height/width
Rexios80 Jun 29, 2024
04610ce
Update Flutter version constraint again
Rexios80 Jun 29, 2024
93dc388
Merge branch 'main' into feature/camera-web-migration-2
Rexios80 Jul 12, 2024
ed30f43
Merge branch 'main' into feature/camera-web-migration-2
Rexios80 Jul 13, 2024
bbdc895
Remove camera from `exclude_all_packages_app_wasm.yaml`
Rexios80 Jul 13, 2024
1c634ff
Merge remote-tracking branch 'origin/feature/camera-web-migration-2' …
Rexios80 Jul 13, 2024
0c28bdd
Merge branch 'main' into feature/camera-web-migration-2
Rexios80 Jul 15, 2024
fd5fe5f
Merge branch 'main' into feature/camera-web-migration-2
ditman Jul 17, 2024
b883134
Merge remote-tracking branch 'upstream/main' into feature/camera-web-…
Rexios80 Jul 18, 2024
4056e6e
Migrations for `package:web` version `1.0.0`
Rexios80 Jul 18, 2024
33d5f1a
Merge remote-tracking branch 'upstream/main' into feature/camera-web-…
Rexios80 Jul 22, 2024
e843357
Merge branch 'main' into feature/camera-web-migration-2
Rexios80 Jul 26, 2024
f930d4c
Merge remote-tracking branch 'upstream/main' into feature/camera-web-…
Rexios80 Jul 26, 2024
4340ed2
Merge branch 'main' into feature/camera-web-migration-2
ditman Aug 1, 2024
6cc3221
Make camera support web 0.5.1 too.
ditman Aug 2, 2024
9eef302
Make analyzer happy
ditman Aug 2, 2024
69eaf1a
Make yaml file empty, not null.
ditman Aug 2, 2024
ce85b20
Merge branch 'main' into feature/camera-web-migration-2
Rexios80 Aug 2, 2024
a270c4b
Replace XFile mock by fake XFile.
ditman Aug 5, 2024
1cf16c9
Remove unneeded ignore and note.
ditman Aug 5, 2024
abbdb12
Add toMediaStreamConstraints method in camera_options.dart
ditman Aug 5, 2024
a8ba0cd
Merge remote-tracking branch 'upstream/main' into feature/camera-web-…
Rexios80 Aug 5, 2024
7329278
Formatting
Rexios80 Aug 5, 2024
0c60ea4
Add trailing commas
Rexios80 Aug 5, 2024
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
4 changes: 4 additions & 0 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.11.0+2

* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 0.11.0+1

* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
Expand Down
4 changes: 4 additions & 0 deletions packages/camera/camera/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,9 @@ dev_dependencies:
integration_test:
sdk: flutter

dependency_overrides:
camera_web:
path: ../../camera_web

flutter:
uses-material-design: true
7 changes: 3 additions & 4 deletions packages/camera/camera/example/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<html>

<head>
<base href="$FLUTTER_BASE_HREF">

<meta charset="UTF-8">
<meta content="IE=Edge" http-equiv="X-UA-Compatible">
<meta name="description" content="An example of the camera on the web.">
Expand All @@ -16,14 +17,12 @@
<link rel="apple-touch-icon" href="icons/Icon-192.png">

<!-- Favicon -->
<link rel="shortcut icon" type="image/png" href="favicon.png" />
<link rel="icon" type="image/png" href="favicon.png"/>

<title>Camera Web Example</title>
<link rel="manifest" href="manifest.json">
</head>

<body>
<script src="flutter_bootstrap.js" async></script>
</body>

</html>
6 changes: 3 additions & 3 deletions packages/camera/camera/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ description: A Flutter plugin for controlling the camera. Supports previewing
Dart.
repository: https://github.com/flutter/packages/tree/main/packages/camera/camera
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+camera%22
version: 0.11.0+1
version: 0.11.0+2

environment:
sdk: ^3.2.3
flutter: ">=3.16.6"
sdk: ^3.3.0
flutter: ">=3.19.0"

flutter:
plugin:
Expand Down
5 changes: 5 additions & 0 deletions packages/camera/camera_web/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.3.5

* Migrates to package:web to support WASM
* Updates minimum supported SDK version to Flutter 3.19/Dart 3.3.

## 0.3.4

* Removes `maxVideoDuration`/`maxDuration`, as the feature was never exposed at
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:html';
import 'dart:js_interop';
import 'dart:math';
import 'dart:ui';

Expand All @@ -13,6 +13,7 @@ import 'package:camera_web/src/types/types.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:web/web.dart';

import 'helpers/helpers.dart';

Expand All @@ -22,7 +23,7 @@ void main() {
const Size videoSize = Size(320, 240);

/// Draw some seconds of random video frames on canvas in realtime.
Future<void> simulateCamera(CanvasElement canvasElement) async {
Future<void> simulateCamera(HTMLCanvasElement canvasElement) async {
const int fps = 15;
const int seconds = 3;
const int frameDuration = 1000 ~/ fps;
Expand All @@ -34,8 +35,10 @@ void main() {
final int h = videoSize.height ~/ 20;
for (int y = 0; y < videoSize.height; y += h) {
for (int x = 0; x < videoSize.width; x += w) {
canvasElement.context2D.setFillColorRgb(
random.nextInt(255), random.nextInt(255), random.nextInt(255));
final int r = random.nextInt(255);
final int g = random.nextInt(255);
final int b = random.nextInt(255);
canvasElement.context2D.fillStyle = 'rgba($r, $g, $b, 1)'.toJS;
canvasElement.context2D.fillRect(x, y, w, h);
}
}
Expand All @@ -53,19 +56,25 @@ void main() {
bool isVideoTypeSupported(String type) => type == supportedVideoType;

Future<int> recordVideo(int videoBitrate) async {
final Window window = MockWindow();
final Navigator navigator = MockNavigator();
final MediaDevices mediaDevices = MockMediaDevices();
final MockWindow mockWindow = MockWindow();
final MockNavigator mockNavigator = MockNavigator();
final MockMediaDevices mockMediaDevices = MockMediaDevices();

when(() => window.navigator).thenReturn(navigator);
when(() => navigator.mediaDevices).thenReturn(mediaDevices);
final Window window = createJSInteropWrapper(mockWindow) as Window;
final Navigator navigator =
createJSInteropWrapper(mockNavigator) as Navigator;
final MediaDevices mediaDevices =
createJSInteropWrapper(mockMediaDevices) as MediaDevices;

final CanvasElement canvasElement = CanvasElement(
width: videoSize.width.toInt(),
height: videoSize.height.toInt(),
)..context2D.clearRect(0, 0, videoSize.width, videoSize.height);
mockWindow.navigator = navigator;
mockNavigator.mediaDevices = mediaDevices;

final VideoElement videoElement = VideoElement();
final HTMLCanvasElement canvasElement = HTMLCanvasElement()
..width = videoSize.width.toInt()
..height = videoSize.height.toInt()
..context2D.clearRect(0, 0, videoSize.width, videoSize.height);

final HTMLVideoElement videoElement = HTMLVideoElement();

final MockCameraService cameraService = MockCameraService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:html';

// ignore: implementation_imports
import 'dart:js_interop';

import 'package:camera_web/src/types/types.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:web/web.dart';

import 'helpers/helpers.dart';

Expand Down Expand Up @@ -132,7 +133,8 @@ void main() {
testWidgets('with aborted error code', (WidgetTester tester) async {
expect(
CameraErrorCode.fromMediaError(
FakeMediaError(MediaError.MEDIA_ERR_ABORTED),
createJSInteropWrapper(
FakeMediaError(MediaError.MEDIA_ERR_ABORTED)) as MediaError,
).toString(),
equals('mediaErrorAborted'),
);
Expand All @@ -141,7 +143,8 @@ void main() {
testWidgets('with network error code', (WidgetTester tester) async {
expect(
CameraErrorCode.fromMediaError(
FakeMediaError(MediaError.MEDIA_ERR_NETWORK),
createJSInteropWrapper(
FakeMediaError(MediaError.MEDIA_ERR_NETWORK)) as MediaError,
).toString(),
equals('mediaErrorNetwork'),
);
Expand All @@ -150,7 +153,8 @@ void main() {
testWidgets('with decode error code', (WidgetTester tester) async {
expect(
CameraErrorCode.fromMediaError(
FakeMediaError(MediaError.MEDIA_ERR_DECODE),
createJSInteropWrapper(
FakeMediaError(MediaError.MEDIA_ERR_DECODE)) as MediaError,
).toString(),
equals('mediaErrorDecode'),
);
Expand All @@ -160,7 +164,9 @@ void main() {
(WidgetTester tester) async {
expect(
CameraErrorCode.fromMediaError(
FakeMediaError(MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED),
createJSInteropWrapper(
FakeMediaError(MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED))
as MediaError,
).toString(),
equals('mediaErrorSourceNotSupported'),
);
Expand All @@ -169,7 +175,7 @@ void main() {
testWidgets('with unknown error code', (WidgetTester tester) async {
expect(
CameraErrorCode.fromMediaError(
FakeMediaError(5),
createJSInteropWrapper(FakeMediaError(5)) as MediaError,
).toString(),
equals('mediaErrorUnknown'),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// found in the LICENSE file.

// ignore: implementation_imports
import 'dart:js_interop';

import 'package:camera_web/src/types/types.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
Expand All @@ -20,10 +22,10 @@ void main() {
);

expect(
cameraOptions.toJson(),
cameraOptions.toMediaStreamConstraints().dartify(),
equals(<String, Object>{
'audio': cameraOptions.audio.toJson(),
'video': cameraOptions.video.toJson(),
'audio': cameraOptions.audio.toMediaStreamConstraints().dartify()!,
'video': cameraOptions.video.toMediaStreamConstraints().dartify()!,
}),
);
});
Expand Down Expand Up @@ -61,8 +63,8 @@ void main() {
group('AudioConstraints', () {
testWidgets('serializes correctly', (WidgetTester tester) async {
expect(
const AudioConstraints(enabled: true).toJson(),
equals(true),
const AudioConstraints(enabled: true).toMediaStreamConstraints(),
true.toJS,
);
});

Expand All @@ -84,7 +86,7 @@ void main() {
);

expect(
videoConstraints.toJson(),
videoConstraints.toMediaStreamConstraints().dartify(),
equals(<String, Object>{
'facingMode': videoConstraints.facingMode!.toJson(),
'width': videoConstraints.width!.toJson(),
Expand Down
Loading