mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-04-24 10:57:52 +02:00
107 lines
3.0 KiB
Dart
107 lines
3.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_webrtc/flutter_webrtc.dart';
|
|
import 'package:matrix/matrix.dart';
|
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
|
|
|
class StreamView extends StatefulWidget {
|
|
const StreamView(this.wrappedStream,
|
|
{Key? key, this.mainView = false, required this.matrixClient})
|
|
: super(key: key);
|
|
|
|
final WrappedMediaStream wrappedStream;
|
|
final Client matrixClient;
|
|
|
|
final bool mainView;
|
|
|
|
@override
|
|
State<StreamView> createState() => _StreamViewState();
|
|
}
|
|
|
|
class _StreamViewState extends State<StreamView> {
|
|
Uri? get avatarUrl => widget.wrappedStream.getUser().avatarUrl;
|
|
|
|
String? get displayName => widget.wrappedStream.displayName;
|
|
|
|
String get avatarName => widget.wrappedStream.avatarName;
|
|
|
|
bool get isLocal => widget.wrappedStream.isLocal();
|
|
|
|
bool get mirrored =>
|
|
widget.wrappedStream.isLocal() &&
|
|
widget.wrappedStream.purpose == SDPStreamMetadataPurpose.Usermedia;
|
|
|
|
late bool audioMuted;
|
|
late bool videoMuted;
|
|
|
|
bool get isScreenSharing =>
|
|
widget.wrappedStream.purpose == SDPStreamMetadataPurpose.Screenshare;
|
|
|
|
@override
|
|
void initState() {
|
|
audioMuted = widget.wrappedStream.audioMuted;
|
|
videoMuted = widget.wrappedStream.videoMuted;
|
|
widget.wrappedStream.onMuteStateChanged.stream.listen((stream) {
|
|
if (stream.audioMuted != audioMuted) {
|
|
setState(() {
|
|
audioMuted = stream.audioMuted;
|
|
});
|
|
}
|
|
if (stream.videoMuted != videoMuted) {
|
|
setState(() {
|
|
videoMuted = stream.videoMuted;
|
|
});
|
|
}
|
|
});
|
|
super.initState();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Container(
|
|
decoration: const BoxDecoration(
|
|
color: Colors.black54,
|
|
),
|
|
child: Stack(
|
|
alignment: Alignment.center,
|
|
children: <Widget>[
|
|
if (videoMuted)
|
|
Container(
|
|
color: Colors.transparent,
|
|
),
|
|
if (!videoMuted)
|
|
RTCVideoView(widget.wrappedStream.renderer as RTCVideoRenderer,
|
|
mirror: mirrored,
|
|
objectFit:
|
|
RTCVideoViewObjectFit.RTCVideoViewObjectFitContain),
|
|
if (videoMuted)
|
|
Positioned(
|
|
child: Avatar(
|
|
mxContent: avatarUrl,
|
|
name: displayName ?? '',
|
|
size: widget.mainView ? 96 : 48,
|
|
fontSize: widget.mainView ? 36 : 24,
|
|
client: widget.matrixClient,
|
|
),
|
|
),
|
|
if (!isScreenSharing)
|
|
Positioned(
|
|
left: 4.0,
|
|
bottom: 4.0,
|
|
child: Icon(audioMuted ? Icons.mic_off : Icons.mic,
|
|
color: Colors.white, size: 18.0),
|
|
),
|
|
Positioned(
|
|
right: 4.0,
|
|
bottom: 4.0,
|
|
child: Text(
|
|
widget.wrappedStream.displayName.toString(),
|
|
style: TextStyle(color: Colors.white),
|
|
),
|
|
),
|
|
],
|
|
));
|
|
}
|
|
}
|