fix ios issues
parent
0fceca8f3e
commit
57f938aa09
@ -0,0 +1,91 @@
|
||||
# Uncomment this line to define a global platform for your project
|
||||
# platform :ios, '11.0'
|
||||
|
||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||
|
||||
project 'Runner', {
|
||||
'Debug' => :debug,
|
||||
'Profile' => :release,
|
||||
'Release' => :release,
|
||||
}
|
||||
|
||||
# pod 'FBSDKCoreKit'
|
||||
# pod 'FBSDKLoginKit'
|
||||
|
||||
def parse_KV_file(file, separator='=')
|
||||
file_abs_path = File.expand_path(file)
|
||||
if !File.exists? file_abs_path
|
||||
return [];
|
||||
end
|
||||
generated_key_values = {}
|
||||
skip_line_start_symbols = ["#", "/"]
|
||||
File.foreach(file_abs_path) do |line|
|
||||
next if skip_line_start_symbols.any? { |symbol| line =~ /^\s*#{symbol}/ }
|
||||
plugin = line.split(pattern=separator)
|
||||
if plugin.length == 2
|
||||
podname = plugin[0].strip()
|
||||
path = plugin[1].strip()
|
||||
podpath = File.expand_path("#{path}", file_abs_path)
|
||||
generated_key_values[podname] = podpath
|
||||
else
|
||||
puts "Invalid plugin specification: #{line}"
|
||||
end
|
||||
end
|
||||
generated_key_values
|
||||
end
|
||||
|
||||
target 'Runner' do
|
||||
use_frameworks!
|
||||
use_modular_headers!
|
||||
|
||||
# Flutter Pod
|
||||
|
||||
copied_flutter_dir = File.join(__dir__, 'Flutter')
|
||||
copied_framework_path = File.join(copied_flutter_dir, 'Flutter.framework')
|
||||
copied_podspec_path = File.join(copied_flutter_dir, 'Flutter.podspec')
|
||||
unless File.exist?(copied_framework_path) && File.exist?(copied_podspec_path)
|
||||
# Copy Flutter.framework and Flutter.podspec to Flutter/ to have something to link against if the xcode backend script has not run yet.
|
||||
# That script will copy the correct debug/profile/release version of the framework based on the currently selected Xcode configuration.
|
||||
# CocoaPods will not embed the framework on pod install (before any build phases can generate) if the dylib does not exist.
|
||||
|
||||
generated_xcode_build_settings_path = File.join(copied_flutter_dir, 'Generated.xcconfig')
|
||||
unless File.exist?(generated_xcode_build_settings_path)
|
||||
raise "Generated.xcconfig must exist. If you're running pod install manually, make sure flutter pub get is executed first"
|
||||
end
|
||||
generated_xcode_build_settings = parse_KV_file(generated_xcode_build_settings_path)
|
||||
cached_framework_dir = generated_xcode_build_settings['FLUTTER_FRAMEWORK_DIR'];
|
||||
|
||||
unless File.exist?(copied_framework_path)
|
||||
FileUtils.cp_r(File.join(cached_framework_dir, 'Flutter.framework'), copied_flutter_dir)
|
||||
end
|
||||
unless File.exist?(copied_podspec_path)
|
||||
FileUtils.cp(File.join(cached_framework_dir, 'Flutter.podspec'), copied_flutter_dir)
|
||||
end
|
||||
end
|
||||
|
||||
# Keep pod path relative so it can be checked into Podfile.lock.
|
||||
pod 'Flutter', :path => 'Flutter'
|
||||
|
||||
# Plugin Pods
|
||||
|
||||
# Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
|
||||
# referring to absolute paths on developers' machines.
|
||||
system('rm -rf .symlinks')
|
||||
system('mkdir -p .symlinks/plugins')
|
||||
plugin_pods = parse_KV_file('../.flutter-plugins')
|
||||
plugin_pods.each do |name, path|
|
||||
symlink = File.join('.symlinks', 'plugins', name)
|
||||
File.symlink(path, symlink)
|
||||
pod name, :path => File.join(symlink, 'ios')
|
||||
end
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
installer.pods_project.targets.each do |target|
|
||||
target.build_configurations.each do |config|
|
||||
config.build_settings['ENABLE_BITCODE'] = 'NO'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,388 +1,388 @@
|
||||
// import 'dart:async';
|
||||
//
|
||||
// import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/conference_button_bar.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/conference_room.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/participant_widget.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
||||
// import 'package:diplomaticquarterapp/pages/conference/widgets/platform_alert_dialog.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:flutter/services.dart';
|
||||
// import 'package:wakelock/wakelock.dart';
|
||||
//
|
||||
// class ConferencePage extends StatefulWidget {
|
||||
// final RoomModel roomModel;
|
||||
//
|
||||
// const ConferencePage({Key key, this.roomModel}) : super(key: key);
|
||||
//
|
||||
// @override
|
||||
// _ConferencePageState createState() => _ConferencePageState();
|
||||
// }
|
||||
//
|
||||
// class _ConferencePageState extends State<ConferencePage> {
|
||||
// final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
||||
// final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
||||
// ConferenceRoom _conferenceRoom;
|
||||
// StreamSubscription _onConferenceRoomException;
|
||||
//
|
||||
// @override
|
||||
// void initState() {
|
||||
// super.initState();
|
||||
// _lockInPortrait();
|
||||
// // _connectToRoom();
|
||||
// _wakeLock(true);
|
||||
// }
|
||||
//
|
||||
// // void _connectToRoom() async {
|
||||
// // try {
|
||||
// // final conferenceRoom = ConferenceRoom(
|
||||
// // name: widget.roomModel.name,
|
||||
// // token: widget.roomModel.token,
|
||||
// // identity: widget.roomModel.identity,
|
||||
// // );
|
||||
// // await conferenceRoom.connect();
|
||||
// // setState(() {
|
||||
// // _conferenceRoom = conferenceRoom;
|
||||
// // _onConferenceRoomException = _conferenceRoom.onException.listen((err) async {
|
||||
// // await PlatformAlertDialog(
|
||||
// // title: err is PlatformException ? err.message : 'An error occured',
|
||||
// // content: err is PlatformException ? err.details : err.toString(),
|
||||
// // defaultActionText: 'OK',
|
||||
// // ).show(context);
|
||||
// // });
|
||||
// // _conferenceRoom.addListener(_conferenceRoomUpdated);
|
||||
// // });
|
||||
// // } catch (err) {
|
||||
// // print(err);
|
||||
// // await PlatformAlertDialog(
|
||||
// // title: err is PlatformException ? err.message : 'An error occured',
|
||||
// // content: err is PlatformException ? err.details : err.toString(),
|
||||
// // defaultActionText: 'OK',
|
||||
// // ).show(context);
|
||||
// //
|
||||
// // Navigator.of(context).pop();
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// Future<void> _lockInPortrait() async {
|
||||
// await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// void dispose() {
|
||||
// _freePortraitLock();
|
||||
// _wakeLock(false);
|
||||
// _disposeStreamsAndSubscriptions();
|
||||
// if (_conferenceRoom != null) _conferenceRoom.removeListener(_conferenceRoomUpdated);
|
||||
// super.dispose();
|
||||
// }
|
||||
//
|
||||
// Future<void> _freePortraitLock() async {
|
||||
// await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
// DeviceOrientation.landscapeRight,
|
||||
// DeviceOrientation.landscapeLeft,
|
||||
// DeviceOrientation.portraitUp,
|
||||
// DeviceOrientation.portraitDown,
|
||||
// ]);
|
||||
// }
|
||||
//
|
||||
// Future<void> _disposeStreamsAndSubscriptions() async {
|
||||
// if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
||||
// if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
||||
// if (_onConferenceRoomException != null) await _onConferenceRoomException.cancel();
|
||||
// }
|
||||
//
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return WillPopScope(
|
||||
// onWillPop: () async => false,
|
||||
// child: Scaffold(
|
||||
// backgroundColor: Colors.black,
|
||||
// body: _conferenceRoom == null ? showProgress() : buildLayout(),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// LayoutBuilder buildLayout() {
|
||||
// return LayoutBuilder(
|
||||
// builder: (BuildContext context, BoxConstraints constraints) {
|
||||
// return Stack(
|
||||
// children: <Widget>[
|
||||
// _buildParticipants(context, constraints.biggest, _conferenceRoom),
|
||||
// ConferenceButtonBar(
|
||||
// audioEnabled: _conferenceRoom.onAudioEnabled,
|
||||
// videoEnabled: _conferenceRoom.onVideoEnabled,
|
||||
// onAudioEnabled: _conferenceRoom.toggleAudioEnabled,
|
||||
// onVideoEnabled: _conferenceRoom.toggleVideoEnabled,
|
||||
// onHangup: _onHangup,
|
||||
// onSwitchCamera: _conferenceRoom.switchCamera,
|
||||
// onPersonAdd: _onPersonAdd,
|
||||
// onPersonRemove: _onPersonRemove,
|
||||
// onHeight: _onHeightBar,
|
||||
// onShow: _onShowBar,
|
||||
// onHide: _onHideBar,
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// },
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// Widget showProgress() {
|
||||
// return Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.center,
|
||||
// crossAxisAlignment: CrossAxisAlignment.center,
|
||||
// children: <Widget>[
|
||||
// Center(child: CircularProgressIndicator()),
|
||||
// SizedBox(
|
||||
// height: 10,
|
||||
// ),
|
||||
// Text(
|
||||
// 'Connecting to the call...',
|
||||
// style: TextStyle(color: Colors.white),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// Future<void> _onHangup() async {
|
||||
// print('onHangup');
|
||||
// await _conferenceRoom.disconnect();
|
||||
// Navigator.of(context).pop();
|
||||
// }
|
||||
//
|
||||
// void _onPersonAdd() {
|
||||
// print('onPersonAdd');
|
||||
// try {
|
||||
// _conferenceRoom.addDummy(
|
||||
// child: Stack(
|
||||
// children: <Widget>[
|
||||
// const Placeholder(),
|
||||
// Center(
|
||||
// child: Text(
|
||||
// (_conferenceRoom.participants.length + 1).toString(),
|
||||
// style: const TextStyle(
|
||||
// shadows: <Shadow>[
|
||||
// Shadow(
|
||||
// blurRadius: 3.0,
|
||||
// color: Color.fromARGB(255, 0, 0, 0),
|
||||
// ),
|
||||
// Shadow(
|
||||
// blurRadius: 8.0,
|
||||
// color: Color.fromARGB(255, 255, 255, 255),
|
||||
// ),
|
||||
// ],
|
||||
// fontSize: 80,
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// );
|
||||
// } on PlatformException catch (err) {
|
||||
// PlatformAlertDialog(
|
||||
// title: err.message,
|
||||
// content: err.details,
|
||||
// defaultActionText: 'OK',
|
||||
// ).show(context);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _onPersonRemove() {
|
||||
// print('onPersonRemove');
|
||||
// _conferenceRoom.removeDummy();
|
||||
// }
|
||||
//
|
||||
// Widget _buildParticipants(BuildContext context, Size size, ConferenceRoom conferenceRoom) {
|
||||
// final children = <Widget>[];
|
||||
// final length = conferenceRoom.participants.length;
|
||||
//
|
||||
// if (length <= 2) {
|
||||
// _buildOverlayLayout(context, size, children);
|
||||
// return Stack(children: children);
|
||||
// }
|
||||
//
|
||||
// void buildInCols(bool removeLocalBeforeChunking, bool moveLastOfEachRowToNextRow, int columns) {
|
||||
// _buildLayoutInGrid(
|
||||
// context,
|
||||
// size,
|
||||
// children,
|
||||
// removeLocalBeforeChunking: removeLocalBeforeChunking,
|
||||
// moveLastOfEachRowToNextRow: moveLastOfEachRowToNextRow,
|
||||
// columns: columns,
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// // if (length <= 3) {
|
||||
// // buildInCols(true, false, 1);
|
||||
// // } else if (length == 5) {
|
||||
// // buildInCols(false, true, 2);
|
||||
// // } else if (length <= 6 || length == 8) {
|
||||
// // buildInCols(false, false, 2);
|
||||
// // } else if (length == 7 || length == 9) {
|
||||
// // buildInCols(true, false, 2);
|
||||
// // } else if (length == 10) {
|
||||
// // buildInCols(false, true, 3);
|
||||
// // } else if (length == 13 || length == 16) {
|
||||
// // buildInCols(true, false, 3);
|
||||
// // } else if (length <= 18) {
|
||||
// // buildInCols(false, false, 3);
|
||||
// // }
|
||||
//
|
||||
// return Column(
|
||||
// children: children,
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// void _buildOverlayLayout(BuildContext context, Size size, List<Widget> children) {
|
||||
// final participants = _conferenceRoom.participants;
|
||||
// if (participants.length == 1) {
|
||||
// children.add(_buildNoiseBox());
|
||||
// } else {
|
||||
// final remoteParticipant = participants.firstWhere((ParticipantWidget participant) => participant.isRemote, orElse: () => null);
|
||||
// if (remoteParticipant != null) {
|
||||
// children.add(remoteParticipant);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// final localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
// if (localParticipant != null) {
|
||||
// children.add(DraggablePublisher(
|
||||
// key: Key('publisher'),
|
||||
// child: localParticipant,
|
||||
// availableScreenSize: size,
|
||||
// onButtonBarVisible: _onButtonBarVisibleStreamController.stream,
|
||||
// onButtonBarHeight: _onButtonBarHeightStreamController.stream,
|
||||
// ));
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _buildLayoutInGrid(
|
||||
// BuildContext context,
|
||||
// Size size,
|
||||
// List<Widget> children, {
|
||||
// bool removeLocalBeforeChunking = false,
|
||||
// bool moveLastOfEachRowToNextRow = false,
|
||||
// int columns = 2,
|
||||
// }) {
|
||||
// final participants = _conferenceRoom.participants;
|
||||
// ParticipantWidget localParticipant;
|
||||
// if (removeLocalBeforeChunking) {
|
||||
// localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
// if (localParticipant != null) {
|
||||
// participants.remove(localParticipant);
|
||||
// }
|
||||
// }
|
||||
// final chunkedParticipants = chunk(array: participants, size: columns);
|
||||
// if (localParticipant != null) {
|
||||
// chunkedParticipants.last.add(localParticipant);
|
||||
// participants.add(localParticipant);
|
||||
// }
|
||||
//
|
||||
// if (moveLastOfEachRowToNextRow) {
|
||||
// for (var i = 0; i < chunkedParticipants.length - 1; i++) {
|
||||
// var participant = chunkedParticipants[i].removeLast();
|
||||
// chunkedParticipants[i + 1].insert(0, participant);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for (final participantChunk in chunkedParticipants) {
|
||||
// final rowChildren = <Widget>[];
|
||||
// for (final participant in participantChunk) {
|
||||
// rowChildren.add(
|
||||
// Container(
|
||||
// width: size.width / participantChunk.length,
|
||||
// height: size.height / chunkedParticipants.length,
|
||||
// child: participant,
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// children.add(
|
||||
// Container(
|
||||
// height: size.height / chunkedParticipants.length,
|
||||
// child: Row(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// children: rowChildren,
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// NoiseBox _buildNoiseBox() {
|
||||
// return NoiseBox(
|
||||
// density: NoiseBoxDensity.xLow,
|
||||
// backgroundColor: Colors.grey.shade900,
|
||||
// child: Center(
|
||||
// child: Container(
|
||||
// color: Colors.black54,
|
||||
// width: double.infinity,
|
||||
// height: 40,
|
||||
// child: Center(
|
||||
// child: Text(
|
||||
// 'Waiting for another participant to connect to the call...',
|
||||
// key: Key('text-wait'),
|
||||
// textAlign: TextAlign.center,
|
||||
// style: TextStyle(color: Colors.white),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
//
|
||||
// List<List<T>> chunk<T>({@required List<T> array, @required int size}) {
|
||||
// final result = <List<T>>[];
|
||||
// if (array.isEmpty || size <= 0) {
|
||||
// return result;
|
||||
// }
|
||||
// var first = 0;
|
||||
// var last = size;
|
||||
// final totalLoop = array.length % size == 0 ? array.length ~/ size : array.length ~/ size + 1;
|
||||
// for (var i = 0; i < totalLoop; i++) {
|
||||
// if (last > array.length) {
|
||||
// result.add(array.sublist(first, array.length));
|
||||
// } else {
|
||||
// result.add(array.sublist(first, last));
|
||||
// }
|
||||
// first = last;
|
||||
// last = last + size;
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//
|
||||
// void _onHeightBar(double height) {
|
||||
// _onButtonBarHeightStreamController.add(height);
|
||||
// }
|
||||
//
|
||||
// void _onShowBar() {
|
||||
// setState(() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
// });
|
||||
// _onButtonBarVisibleStreamController.add(true);
|
||||
// }
|
||||
//
|
||||
// void _onHideBar() {
|
||||
// setState(() {
|
||||
// SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||
// });
|
||||
// _onButtonBarVisibleStreamController.add(false);
|
||||
// }
|
||||
//
|
||||
// Future<void> _wakeLock(bool enable) async {
|
||||
// try {
|
||||
// return await (enable ? Wakelock.enable() : Wakelock.disable());
|
||||
// } catch (err) {
|
||||
// print('Unable to change the Wakelock and set it to $enable');
|
||||
// print(err);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// void _conferenceRoomUpdated() {
|
||||
// setState(() {});
|
||||
// }
|
||||
// }
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:diplomaticquarterapp/models/LiveCare/room_model.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/conference_button_bar.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/conference_room.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/draggable_publisher.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/participant_widget.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/widgets/noise_box.dart';
|
||||
import 'package:diplomaticquarterapp/pages/conference/widgets/platform_alert_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:wakelock/wakelock.dart';
|
||||
|
||||
class ConferencePage extends StatefulWidget {
|
||||
final RoomModel roomModel;
|
||||
|
||||
const ConferencePage({Key key, this.roomModel}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ConferencePageState createState() => _ConferencePageState();
|
||||
}
|
||||
|
||||
class _ConferencePageState extends State<ConferencePage> {
|
||||
final StreamController<bool> _onButtonBarVisibleStreamController = StreamController<bool>.broadcast();
|
||||
final StreamController<double> _onButtonBarHeightStreamController = StreamController<double>.broadcast();
|
||||
ConferenceRoom _conferenceRoom;
|
||||
StreamSubscription _onConferenceRoomException;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_lockInPortrait();
|
||||
_connectToRoom();
|
||||
_wakeLock(true);
|
||||
}
|
||||
|
||||
void _connectToRoom() async {
|
||||
try {
|
||||
final conferenceRoom = ConferenceRoom(
|
||||
name: widget.roomModel.name,
|
||||
token: widget.roomModel.token,
|
||||
identity: widget.roomModel.identity,
|
||||
);
|
||||
await conferenceRoom.connect();
|
||||
setState(() {
|
||||
_conferenceRoom = conferenceRoom;
|
||||
_onConferenceRoomException = _conferenceRoom.onException.listen((err) async {
|
||||
await PlatformAlertDialog(
|
||||
title: err is PlatformException ? err.message : 'An error occured',
|
||||
content: err is PlatformException ? err.details : err.toString(),
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
});
|
||||
_conferenceRoom.addListener(_conferenceRoomUpdated);
|
||||
});
|
||||
} catch (err) {
|
||||
print(err);
|
||||
await PlatformAlertDialog(
|
||||
title: err is PlatformException ? err.message : 'An error occured',
|
||||
content: err is PlatformException ? err.details : err.toString(),
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _lockInPortrait() async {
|
||||
await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_freePortraitLock();
|
||||
_wakeLock(false);
|
||||
_disposeStreamsAndSubscriptions();
|
||||
if (_conferenceRoom != null) _conferenceRoom.removeListener(_conferenceRoomUpdated);
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Future<void> _freePortraitLock() async {
|
||||
await SystemChrome.setPreferredOrientations(<DeviceOrientation>[
|
||||
DeviceOrientation.landscapeRight,
|
||||
DeviceOrientation.landscapeLeft,
|
||||
DeviceOrientation.portraitUp,
|
||||
DeviceOrientation.portraitDown,
|
||||
]);
|
||||
}
|
||||
|
||||
Future<void> _disposeStreamsAndSubscriptions() async {
|
||||
if (_onButtonBarVisibleStreamController != null) await _onButtonBarVisibleStreamController.close();
|
||||
if (_onButtonBarHeightStreamController != null) await _onButtonBarHeightStreamController.close();
|
||||
if (_onConferenceRoomException != null) await _onConferenceRoomException.cancel();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () async => false,
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black,
|
||||
body: _conferenceRoom == null ? showProgress() : buildLayout(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
LayoutBuilder buildLayout() {
|
||||
return LayoutBuilder(
|
||||
builder: (BuildContext context, BoxConstraints constraints) {
|
||||
return Stack(
|
||||
children: <Widget>[
|
||||
_buildParticipants(context, constraints.biggest, _conferenceRoom),
|
||||
ConferenceButtonBar(
|
||||
audioEnabled: _conferenceRoom.onAudioEnabled,
|
||||
videoEnabled: _conferenceRoom.onVideoEnabled,
|
||||
onAudioEnabled: _conferenceRoom.toggleAudioEnabled,
|
||||
onVideoEnabled: _conferenceRoom.toggleVideoEnabled,
|
||||
onHangup: _onHangup,
|
||||
onSwitchCamera: _conferenceRoom.switchCamera,
|
||||
onPersonAdd: _onPersonAdd,
|
||||
onPersonRemove: _onPersonRemove,
|
||||
onHeight: _onHeightBar,
|
||||
onShow: _onShowBar,
|
||||
onHide: _onHideBar,
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget showProgress() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
Center(child: CircularProgressIndicator()),
|
||||
SizedBox(
|
||||
height: 10,
|
||||
),
|
||||
Text(
|
||||
'Connecting to the call...',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onHangup() async {
|
||||
print('onHangup');
|
||||
await _conferenceRoom.disconnect();
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
||||
void _onPersonAdd() {
|
||||
print('onPersonAdd');
|
||||
try {
|
||||
_conferenceRoom.addDummy(
|
||||
child: Stack(
|
||||
children: <Widget>[
|
||||
const Placeholder(),
|
||||
Center(
|
||||
child: Text(
|
||||
(_conferenceRoom.participants.length + 1).toString(),
|
||||
style: const TextStyle(
|
||||
shadows: <Shadow>[
|
||||
Shadow(
|
||||
blurRadius: 3.0,
|
||||
color: Color.fromARGB(255, 0, 0, 0),
|
||||
),
|
||||
Shadow(
|
||||
blurRadius: 8.0,
|
||||
color: Color.fromARGB(255, 255, 255, 255),
|
||||
),
|
||||
],
|
||||
fontSize: 80,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} on PlatformException catch (err) {
|
||||
PlatformAlertDialog(
|
||||
title: err.message,
|
||||
content: err.details,
|
||||
defaultActionText: 'OK',
|
||||
).show(context);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPersonRemove() {
|
||||
print('onPersonRemove');
|
||||
_conferenceRoom.removeDummy();
|
||||
}
|
||||
|
||||
Widget _buildParticipants(BuildContext context, Size size, ConferenceRoom conferenceRoom) {
|
||||
final children = <Widget>[];
|
||||
final length = conferenceRoom.participants.length;
|
||||
|
||||
if (length <= 2) {
|
||||
_buildOverlayLayout(context, size, children);
|
||||
return Stack(children: children);
|
||||
}
|
||||
|
||||
void buildInCols(bool removeLocalBeforeChunking, bool moveLastOfEachRowToNextRow, int columns) {
|
||||
_buildLayoutInGrid(
|
||||
context,
|
||||
size,
|
||||
children,
|
||||
removeLocalBeforeChunking: removeLocalBeforeChunking,
|
||||
moveLastOfEachRowToNextRow: moveLastOfEachRowToNextRow,
|
||||
columns: columns,
|
||||
);
|
||||
}
|
||||
|
||||
// if (length <= 3) {
|
||||
// buildInCols(true, false, 1);
|
||||
// } else if (length == 5) {
|
||||
// buildInCols(false, true, 2);
|
||||
// } else if (length <= 6 || length == 8) {
|
||||
// buildInCols(false, false, 2);
|
||||
// } else if (length == 7 || length == 9) {
|
||||
// buildInCols(true, false, 2);
|
||||
// } else if (length == 10) {
|
||||
// buildInCols(false, true, 3);
|
||||
// } else if (length == 13 || length == 16) {
|
||||
// buildInCols(true, false, 3);
|
||||
// } else if (length <= 18) {
|
||||
// buildInCols(false, false, 3);
|
||||
// }
|
||||
|
||||
return Column(
|
||||
children: children,
|
||||
);
|
||||
}
|
||||
|
||||
void _buildOverlayLayout(BuildContext context, Size size, List<Widget> children) {
|
||||
final participants = _conferenceRoom.participants;
|
||||
if (participants.length == 1) {
|
||||
children.add(_buildNoiseBox());
|
||||
} else {
|
||||
final remoteParticipant = participants.firstWhere((ParticipantWidget participant) => participant.isRemote, orElse: () => null);
|
||||
if (remoteParticipant != null) {
|
||||
children.add(remoteParticipant);
|
||||
}
|
||||
}
|
||||
|
||||
final localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
if (localParticipant != null) {
|
||||
children.add(DraggablePublisher(
|
||||
key: Key('publisher'),
|
||||
child: localParticipant,
|
||||
availableScreenSize: size,
|
||||
onButtonBarVisible: _onButtonBarVisibleStreamController.stream,
|
||||
onButtonBarHeight: _onButtonBarHeightStreamController.stream,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void _buildLayoutInGrid(
|
||||
BuildContext context,
|
||||
Size size,
|
||||
List<Widget> children, {
|
||||
bool removeLocalBeforeChunking = false,
|
||||
bool moveLastOfEachRowToNextRow = false,
|
||||
int columns = 2,
|
||||
}) {
|
||||
final participants = _conferenceRoom.participants;
|
||||
ParticipantWidget localParticipant;
|
||||
if (removeLocalBeforeChunking) {
|
||||
localParticipant = participants.firstWhere((ParticipantWidget participant) => !participant.isRemote, orElse: () => null);
|
||||
if (localParticipant != null) {
|
||||
participants.remove(localParticipant);
|
||||
}
|
||||
}
|
||||
final chunkedParticipants = chunk(array: participants, size: columns);
|
||||
if (localParticipant != null) {
|
||||
chunkedParticipants.last.add(localParticipant);
|
||||
participants.add(localParticipant);
|
||||
}
|
||||
|
||||
if (moveLastOfEachRowToNextRow) {
|
||||
for (var i = 0; i < chunkedParticipants.length - 1; i++) {
|
||||
var participant = chunkedParticipants[i].removeLast();
|
||||
chunkedParticipants[i + 1].insert(0, participant);
|
||||
}
|
||||
}
|
||||
|
||||
for (final participantChunk in chunkedParticipants) {
|
||||
final rowChildren = <Widget>[];
|
||||
for (final participant in participantChunk) {
|
||||
rowChildren.add(
|
||||
Container(
|
||||
width: size.width / participantChunk.length,
|
||||
height: size.height / chunkedParticipants.length,
|
||||
child: participant,
|
||||
),
|
||||
);
|
||||
}
|
||||
children.add(
|
||||
Container(
|
||||
height: size.height / chunkedParticipants.length,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: rowChildren,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
NoiseBox _buildNoiseBox() {
|
||||
return NoiseBox(
|
||||
density: NoiseBoxDensity.xLow,
|
||||
backgroundColor: Colors.grey.shade900,
|
||||
child: Center(
|
||||
child: Container(
|
||||
color: Colors.black54,
|
||||
width: double.infinity,
|
||||
height: 40,
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Waiting for another participant to connect to the call...',
|
||||
key: Key('text-wait'),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<List<T>> chunk<T>({@required List<T> array, @required int size}) {
|
||||
final result = <List<T>>[];
|
||||
if (array.isEmpty || size <= 0) {
|
||||
return result;
|
||||
}
|
||||
var first = 0;
|
||||
var last = size;
|
||||
final totalLoop = array.length % size == 0 ? array.length ~/ size : array.length ~/ size + 1;
|
||||
for (var i = 0; i < totalLoop; i++) {
|
||||
if (last > array.length) {
|
||||
result.add(array.sublist(first, array.length));
|
||||
} else {
|
||||
result.add(array.sublist(first, last));
|
||||
}
|
||||
first = last;
|
||||
last = last + size;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void _onHeightBar(double height) {
|
||||
_onButtonBarHeightStreamController.add(height);
|
||||
}
|
||||
|
||||
void _onShowBar() {
|
||||
setState(() {
|
||||
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom, SystemUiOverlay.top]);
|
||||
});
|
||||
_onButtonBarVisibleStreamController.add(true);
|
||||
}
|
||||
|
||||
void _onHideBar() {
|
||||
setState(() {
|
||||
SystemChrome.setEnabledSystemUIOverlays([SystemUiOverlay.bottom]);
|
||||
});
|
||||
_onButtonBarVisibleStreamController.add(false);
|
||||
}
|
||||
|
||||
Future<void> _wakeLock(bool enable) async {
|
||||
try {
|
||||
return await (enable ? Wakelock.enable() : Wakelock.disable());
|
||||
} catch (err) {
|
||||
print('Unable to change the Wakelock and set it to $enable');
|
||||
print(err);
|
||||
}
|
||||
}
|
||||
|
||||
void _conferenceRoomUpdated() {
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue