远程遥控界面视频实现
This commit is contained in:
@@ -23,14 +23,12 @@ class RemoteControlPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _RemoteControlPageState extends State<RemoteControlPage> {
|
class _RemoteControlPageState extends State<RemoteControlPage> {
|
||||||
|
String _videoStreamUrl = "";
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
// 1. 锁定横屏
|
// 1. 锁定横屏
|
||||||
SystemChrome.setPreferredOrientations([
|
SystemChrome.setPreferredOrientations([DeviceOrientation.landscapeLeft, DeviceOrientation.landscapeRight]);
|
||||||
DeviceOrientation.landscapeLeft,
|
|
||||||
DeviceOrientation.landscapeRight,
|
|
||||||
]);
|
|
||||||
// 2. 隐藏状态栏和虚拟按键
|
// 2. 隐藏状态栏和虚拟按键
|
||||||
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);
|
||||||
|
|
||||||
@@ -53,10 +51,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
final deviceState = context.watch<DevicesCubit>().state;
|
final deviceState = context.watch<DevicesCubit>().state;
|
||||||
final currentDevice = deviceState.selectedDevice;
|
final currentDevice = deviceState.selectedDevice;
|
||||||
|
|
||||||
context.read<RemoteControlCubit>().requestControlPermissionS(
|
context.read<RemoteControlCubit>().requestControlPermissionS(currentDevice!.deviceName, "app");
|
||||||
currentDevice!.deviceName,
|
|
||||||
"app",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (currentDevice == null) {
|
if (currentDevice == null) {
|
||||||
return _buildOfflineScaffold();
|
return _buildOfflineScaffold();
|
||||||
@@ -70,15 +65,19 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
child: BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||||
// 只有当显示隐藏状态改变时才重构,内部的拖拽由组件自身 State 处理,不影响这里
|
// 只有当显示隐藏状态改变时才重构,内部的拖拽由组件自身 State 处理,不影响这里
|
||||||
buildWhen: (p, c) =>
|
buildWhen: (p, c) => p.showLeftPip != c.showLeftPip || p.showRightPip != c.showRightPip,
|
||||||
p.showLeftPip != c.showLeftPip ||
|
|
||||||
p.showRightPip != c.showRightPip,
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
|
final deviceId = context.watch<DevicesCubit>().state.selectedDevice?.deviceName;
|
||||||
|
if (deviceId != null && userState.user != null && userState.user!.token != null) {
|
||||||
|
_videoStreamUrl = "webrtc://${TCPConsts.TCP_IP}/live/livestream/$deviceId?token=${userState.user!.token}";
|
||||||
|
} else {
|
||||||
|
_videoStreamUrl = '';
|
||||||
|
}
|
||||||
return WebRTCLocalPlayer(
|
return WebRTCLocalPlayer(
|
||||||
// 这里的 URL 拼接根据你的后端规则
|
// 这里的 URL 拼接根据你的后端规则
|
||||||
// streamUrl: "webrtc://${TCPConsts.TCP_IP}/live/livestream/${currentDevice.deviceName}?token=${userState.user!.token}",
|
// streamUrl: "webrtc://${TCPConsts.TCP_IP}/live/livestream/${currentDevice.deviceName}?token=${userState.user!.token}",
|
||||||
streamUrl:
|
streamUrl: _videoStreamUrl,
|
||||||
"webrtc://${TCPConsts.TCP_IP}/live/livestream/111?token=${userState.user!.token}",
|
|
||||||
showLeftPip: state.showLeftPip, // 从 Cubit 状态中读取
|
showLeftPip: state.showLeftPip, // 从 Cubit 状态中读取
|
||||||
showRightPip: state.showRightPip, // 从 Cubit 状态中读取
|
showRightPip: state.showRightPip, // 从 Cubit 状态中读取
|
||||||
);
|
);
|
||||||
@@ -89,9 +88,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||||
buildWhen: (p, c) => p.isEmergency != c.isEmergency,
|
buildWhen: (p, c) => p.isEmergency != c.isEmergency,
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return state.isEmergency
|
return state.isEmergency ? const Positioned.fill(child: EmergencyOverlay()) : const SizedBox.shrink();
|
||||||
? const Positioned.fill(child: EmergencyOverlay())
|
|
||||||
: const SizedBox.shrink();
|
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -106,10 +103,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
final double centerAreaWidth = constraints.maxWidth * 0.5;
|
final double centerAreaWidth = constraints.maxWidth * 0.5;
|
||||||
|
|
||||||
// 关键:使用 BlocBuilder 局部刷新摇杆,不要 watch 整个 Page
|
// 关键:使用 BlocBuilder 局部刷新摇杆,不要 watch 整个 Page
|
||||||
return BlocBuilder<
|
return BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||||
RemoteControlCubit,
|
|
||||||
RemoteControlState
|
|
||||||
>(
|
|
||||||
// 只有 isLocked 改变时才重构摇杆区域,摇杆坐标改变由内部处理
|
// 只有 isLocked 改变时才重构摇杆区域,摇杆坐标改变由内部处理
|
||||||
buildWhen: (p, c) => p.isLocked != c.isLocked,
|
buildWhen: (p, c) => p.isLocked != c.isLocked,
|
||||||
builder: (context, remoteState) {
|
builder: (context, remoteState) {
|
||||||
@@ -124,10 +118,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
width: sideAreaWidth,
|
width: sideAreaWidth,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: LeftJoystickArea(
|
child: LeftJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.5 * 0.7),
|
||||||
isLocked: remoteState.isLocked,
|
|
||||||
width: sideAreaWidth * 0.5 * 0.7,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -136,9 +127,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
width: centerAreaWidth,
|
width: centerAreaWidth,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: CenterControlArea(
|
child: CenterControlArea(totalWidth: centerAreaWidth),
|
||||||
totalWidth: centerAreaWidth,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
@@ -147,10 +136,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
width: sideAreaWidth,
|
width: sideAreaWidth,
|
||||||
child: Align(
|
child: Align(
|
||||||
alignment: Alignment.bottomCenter,
|
alignment: Alignment.bottomCenter,
|
||||||
child: RightJoystickArea(
|
child: RightJoystickArea(isLocked: remoteState.isLocked, width: sideAreaWidth * 0.5 * 0.7),
|
||||||
isLocked: remoteState.isLocked,
|
|
||||||
width: sideAreaWidth * 0.5 * 0.7,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -167,8 +153,7 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
|
|
||||||
// 权限弹窗
|
// 权限弹窗
|
||||||
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
BlocBuilder<RemoteControlCubit, RemoteControlState>(
|
||||||
buildWhen: (p, c) =>
|
buildWhen: (p, c) => p.showPermissionRequestDialog != c.showPermissionRequestDialog,
|
||||||
p.showPermissionRequestDialog != c.showPermissionRequestDialog,
|
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.showPermissionRequestDialog) {
|
if (state.showPermissionRequestDialog) {
|
||||||
return _buildPermissionDialog(context, state);
|
return _buildPermissionDialog(context, state);
|
||||||
@@ -190,41 +175,24 @@ class _RemoteControlPageState extends State<RemoteControlPage> {
|
|||||||
children: [
|
children: [
|
||||||
const Icon(Icons.signal_wifi_off, color: Colors.white, size: 60),
|
const Icon(Icons.signal_wifi_off, color: Colors.white, size: 60),
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
const Text(
|
const Text("设备已断开连接", style: TextStyle(color: Colors.white, fontSize: 18)),
|
||||||
"设备已断开连接",
|
|
||||||
style: TextStyle(color: Colors.white, fontSize: 18),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
ElevatedButton(
|
ElevatedButton(onPressed: () => context.pop(), child: const Text("返回")),
|
||||||
onPressed: () => context.pop(),
|
|
||||||
child: const Text("返回"),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildPermissionDialog(
|
Widget _buildPermissionDialog(BuildContext context, RemoteControlState state) {
|
||||||
BuildContext context,
|
|
||||||
RemoteControlState state,
|
|
||||||
) {
|
|
||||||
return Container(
|
return Container(
|
||||||
color: Colors.black54,
|
color: Colors.black54,
|
||||||
child: AlertDialog(
|
child: AlertDialog(
|
||||||
title: const Text("权限变更"),
|
title: const Text("权限变更"),
|
||||||
content: Text("${state.permissionPlatform}端正请求控制权,同意释放吗?"),
|
content: Text("${state.permissionPlatform}端正请求控制权,同意释放吗?"),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(onPressed: () => context.read<RemoteControlCubit>().respondPermission(false), child: const Text("拒绝")),
|
||||||
onPressed: () =>
|
TextButton(onPressed: () => context.read<RemoteControlCubit>().respondPermission(true), child: const Text("同意")),
|
||||||
context.read<RemoteControlCubit>().respondPermission(false),
|
|
||||||
child: const Text("拒绝"),
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: () =>
|
|
||||||
context.read<RemoteControlCubit>().respondPermission(true),
|
|
||||||
child: const Text("同意"),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -219,7 +219,7 @@ class _WebRTCLocalPlayerState extends State<WebRTCLocalPlayer> {
|
|||||||
),
|
),
|
||||||
Positioned.fill(
|
Positioned.fill(
|
||||||
child: BackdropFilter(
|
child: BackdropFilter(
|
||||||
filter: ImageFilter.blur(sigmaX: 45, sigmaY: 45),
|
filter: ImageFilter.blur(sigmaX: 20, sigmaY: 20),
|
||||||
child: Container(color: Colors.black.withOpacity(0.55)),
|
child: Container(color: Colors.black.withOpacity(0.55)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user