Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Add UI for file presentation service #288

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class FilePresentationServiceModule(
onError = result::error,
onSuccess = {
getCurrentFileId()
.let { VoxeetSDK.filePresentation().update(it, call.argumentOrThrow("page")) }
.let { VoxeetSDK.filePresentation().update(it, call.argumentOrThrow("page")).await() }
.let { result.success(null) }
}
)
Expand Down
104 changes: 92 additions & 12 deletions test_app/lib/screens/participant_screen/conference_controls.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:dolbyio_comms_sdk_flutter_example/conference_ext.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/bottom_tool_bar.dart';
import 'package:file_picker/file_picker.dart';
import 'package:flutter/material.dart';
import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart';
import 'package:provider/provider.dart';
Expand All @@ -14,7 +15,6 @@ typedef ParticipantConferenceStatus = void Function(
class ConferenceControls extends StatefulWidget {
final ParticipantConferenceStatus updateCloseSessionFlag;


const ConferenceControls({Key? key, required this.updateCloseSessionFlag})
: super(key: key);

Expand All @@ -24,7 +24,10 @@ class ConferenceControls extends StatefulWidget {

class _ConferenceControlsState extends State<ConferenceControls> {
final _dolbyioCommsSdkFlutterPlugin = DolbyioCommsSdk.instance;
bool isMicOff = false, isVideoOff = false, isScreenShareOff = true;
bool isMicOff = false;
bool isVideoOff = false;
bool isScreenShareOff = true;
FileConverted? _fileConverted;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -52,16 +55,49 @@ class _ConferenceControlsState extends State<ConferenceControls> {
? const Icon(Icons.videocam_off)
: const Icon(Icons.videocam),
),
ConferenceActionIconButton(
iconWidget: isScreenShareOff
? const Icon(Icons.screen_share)
: const Icon(Icons.stop_screen_share_sharp),
backgroundIconColor: Colors.deepPurple,
onPressedIcon: () {
if (isScreenShareOff) {
startScreenShare();
} else {
stopScreenShare();
PopupMenuButton(
position: PopupMenuPosition.under,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 24),
child: Container(
width: 50,
height: 50,
decoration: const BoxDecoration(
color: Colors.deepPurple,
shape: BoxShape.circle,
),
child: const Icon(Icons.ios_share_rounded, color: Colors.white),
),
),
itemBuilder: (BuildContext context) {
return [
PopupMenuItem<int>(
value: 0,
child: isScreenShareOff
? const Text('Share screen')
: const Text('Stop sharing'),
),
const PopupMenuItem<int>(
value: 1,
child: Text('Share file'),
),
];
},
onSelected: (value) async {
switch (value) {
case 0:
if (isScreenShareOff) {
startScreenShare();
} else {
stopScreenShare();
}
break;
case 1:
await convertFile();
if (_fileConverted != null) {
startFilePresentation();
}
break;
}
},
),
Expand Down Expand Up @@ -195,6 +231,50 @@ class _ConferenceControlsState extends State<ConferenceControls> {
}
}

Future<void> convertFile() async {
try {
FilePickerResult? result = await FilePicker.platform.pickFiles(
type: FileType.custom,
allowedExtensions: ['doc', 'docx', 'ppt', 'pptx', 'pdf'],
);
String? path = result?.files.single.path;

if (path == null) {
if (!mounted) return;
showResultDialog(context, 'File not selected', '');
return;
}

var fileConverted = await _dolbyioCommsSdkFlutterPlugin.filePresentation
.convert(File(path));
_fileConverted = fileConverted;
if (!mounted) return;
showResultDialog(context, 'Success', 'File converted.');
} catch (error) {
if (!mounted) return;
showResultDialog(context, 'Error: ', error.toString());
}
}

Future<void> startFilePresentation() async {
try {
if (_fileConverted == null) {
if (!mounted) return;
showResultDialog(context, 'You must convert file first!', '');
return;
}

await _dolbyioCommsSdkFlutterPlugin.filePresentation
.start(_fileConverted!);
if (!mounted) return;
showResultDialog(
context, 'Success', 'File presentation has been started.');
} catch (error) {
if (!mounted) return;
showResultDialog(context, 'Error: ', error.toString());
}
}

Future<bool> isSomeoneScreenSharing() async {
final conference = await _dolbyioCommsSdkFlutterPlugin.conference.current();
final participants = await _dolbyioCommsSdkFlutterPlugin.conference
Expand Down
55 changes: 54 additions & 1 deletion test_app/lib/screens/participant_screen/participant_screen.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'package:dolbyio_comms_sdk_flutter_example/state_management/models/conference_model.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/file_presentation_ui.dart';
import 'package:dolbyio_comms_sdk_flutter_example/widgets/spatial_extensions/participant_spatial_values.dart';
import 'package:provider/provider.dart';
import '../../conference_ext.dart';
import '../../widgets/file_container.dart';
import '../../widgets/spatial_extensions/spatial_values_model.dart';
import '../../widgets/status_snackbar.dart';
import '../test_buttons/test_buttons.dart';
Expand Down Expand Up @@ -77,10 +79,16 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
StreamSubscription<Event<RecordingServiceEventNames, RecordingStatusUpdate>>?
_onRecordingChangeSubscription;

StreamSubscription<
Event<FilePresentationServiceEventNames, FilePresentation>>?
_onFilePresentationChangeSubscription;

Participant? _localParticipant;
bool shouldCloseSessionOnLeave = false;
List<ParticipantSpatialValues> participants = [];
bool _isScreenSharing = false;
bool isFilePresenting = false;
bool isLocalPresentingFile = false;

@override
void initState() {
Expand Down Expand Up @@ -120,6 +128,42 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
"Recording status: ${event.body.recordingStatus} for conference: ${event.body.conferenceId}",
const Duration(seconds: 2));
});

_onFilePresentationChangeSubscription = _dolbyioCommsSdkFlutterPlugin
.filePresentation
.onFilePresentationChange()
.listen((event) async {
if (event.type ==
FilePresentationServiceEventNames.filePresentationStarted) {
Provider.of<ConferenceModel>(context, listen: false).imageSource =
await _dolbyioCommsSdkFlutterPlugin.filePresentation
.getImage(event.body.position);
var localParticipant = await _dolbyioCommsSdkFlutterPlugin.conference
.getLocalParticipant();
setState(() {
isFilePresenting = true;
if (event.body.owner.id == localParticipant.id) {
isLocalPresentingFile = true;
Provider.of<ConferenceModel>(context, listen: false)
.amountOfPagesInDocument = event.body.imageCount - 1;
}
});
} else if (event.type ==
FilePresentationServiceEventNames.filePresentationUpdated) {
var imageSource = await _dolbyioCommsSdkFlutterPlugin.filePresentation
.getImage(event.body.position);
setState(() {
Provider.of<ConferenceModel>(context, listen: false).imageSource =
imageSource;
});
} else if (event.type ==
FilePresentationServiceEventNames.filePresentationStopped) {
setState(() {
isFilePresenting = false;
isLocalPresentingFile = false;
});
}
});
}

@override
Expand All @@ -130,12 +174,14 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
_streamsChangeSubscription?.cancel();
_onPermissionsChangeSubsription?.cancel();
_onRecordingChangeSubscription?.cancel();
_onFilePresentationChangeSubscription?.cancel();
super.deactivate();
}

@override
Widget build(BuildContext context) {
Provider.of<SpatialValuesModel>(context).setSpatialConferenceState(widget.isSpatialAudio);
Provider.of<SpatialValuesModel>(context)
.setSpatialConferenceState(widget.isSpatialAudio);
Provider.of<SpatialValuesModel>(context).copyList(participants);

Widget videoView = const FlutterLogo();
Expand All @@ -159,6 +205,13 @@ class _ParticipantScreenContentState extends State<ParticipantScreenContent> {
child: Column(
children: [
const ConferenceTitle(),
isFilePresenting
? isLocalPresentingFile
? const FilePresentationUI()
: const SingleChildScrollView(
child: FileContainer(),
)
: const SizedBox.shrink(),
Expanded(
child: Stack(
children: [
Expand Down
Loading