Send the sign-in with native video playback
The native video player requests media itself, without the session cookie the app's file fetches send, so a video shown with show_file (or opened from Files) behind the web login was refused in the phone and Mac apps. Pass ServerSession.headersFor(uri) as the player's HTTP headers.
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../../../core/session/server_session.dart';
|
||||
|
||||
/// Creates the player for one media url; tests inject a fake controller.
|
||||
typedef ArtifactVideoControllerFactory =
|
||||
VideoPlayerController Function(Uri uri);
|
||||
|
||||
/// The native players request the media themselves, outside the app's own
|
||||
/// fetch, so they carry the same sign-in the app's file fetches send (the web
|
||||
/// login's session cookie for a trusted server). A browser's `<video>` sends
|
||||
/// its cookie itself and ignores these headers.
|
||||
VideoPlayerController defaultArtifactVideoController(Uri uri) =>
|
||||
VideoPlayerController.networkUrl(uri);
|
||||
VideoPlayerController.networkUrl(
|
||||
uri,
|
||||
httpHeaders: ServerSession.headersFor(uri),
|
||||
);
|
||||
|
||||
const String artifactVideoPlayLabel = 'Play video';
|
||||
const String artifactVideoPauseLabel = 'Pause video';
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/session/server_session.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_preview.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_url.dart';
|
||||
import 'package:pipelines_app/features/artifacts/ui/artifact_video_player.dart';
|
||||
@@ -42,6 +44,34 @@ Widget _body(ArtifactVideoControllerFactory factory) => MaterialApp(
|
||||
);
|
||||
|
||||
void main() {
|
||||
test(
|
||||
'the default player sends the sign-in only to the signed-in server',
|
||||
() async {
|
||||
SharedPreferences.setMockInitialValues({
|
||||
'pipelines.session.v2.${Uri.encodeComponent('a')}.cookie': 'session=a',
|
||||
});
|
||||
await ServerSession.load();
|
||||
await ServerSession.activateServer(
|
||||
id: 'a',
|
||||
endpoints: [Uri.parse('wss://primary.example/connect')],
|
||||
migrateLegacy: false,
|
||||
);
|
||||
addTearDown(ServerSession.clearSelection);
|
||||
|
||||
final own = defaultArtifactVideoController(
|
||||
Uri.parse('https://primary.example/files/view?path=/a.mp4'),
|
||||
);
|
||||
addTearDown(own.dispose);
|
||||
expect(own.httpHeaders, {'Cookie': 'session=a'});
|
||||
|
||||
final other = defaultArtifactVideoController(
|
||||
Uri.parse('https://external.example/a.mp4'),
|
||||
);
|
||||
addTearDown(other.dispose);
|
||||
expect(other.httpHeaders, isEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('a video preview streams its resolved url and never autoplays', (
|
||||
tester,
|
||||
) async {
|
||||
|
||||
Reference in New Issue
Block a user