Calculate duration

- The
isVisibleproperty ofZegoVideoConferenceDurationConfigcontrols the visibility of the duration label. If none of the participants have setcanSync, the duration label will not be visible regardless of the value ofisVisible. canSynccontrols whether the meeting starts counting the duration. IfcanSyncis set totruewhen any participant joins the meeting, the meeting duration will start counting from the time that participant joins.- The
ZegoVideoConferenceDurationEvents.onUpdatedcallback will only be triggered when a participant withcanSyncset totruejoins the meeting. Theduration.inSecondsmay not necessarily be increasing, as the timing can be reset by a new participant joining the meeting withcanSyncset totrue.
It is recommended to have only one participant with canSync set to true and others set to false. For example, if the administrator of a meeting sets canSync to true and others set it to false, the meeting duration will start counting from when the administrator joins, and the duration will not be affected by other participants joining.
You can achieve the automatic ending of a conference after a specified duration by using the ZegoVideoConferenceDurationEvents.onUpdated event and the leave method of ZegoUIKitPrebuiltVideoConferenceController().room. Let's take an example where the conference automatically ends after 5 minutes of starting:
enum Role { Host, Audience }
class VideoConferencePage extends StatefulWidget {
final String conferenceID;
final Role role;
const VideoConferencePage({
Key? key,
required this.conferenceID,
required this.role,
}) : super(key: key);
@override
State<StatefulWidget> createState() => VideoConferencePageState();
}
class VideoConferencePageState extends State<VideoConferencePage> {
@override
Widget build(BuildContext context) {
return SafeArea(
child: ZegoUIKitPrebuiltVideoConference(
appID: yourAppID /*input your AppID*/,
appSign: yourAppSign /*input your AppSign*/,
userID: 'userID',
userName: 'userName',
conferenceID: widget.conferenceID,
config: ZegoUIKitPrebuiltVideoConferenceConfig()
// !mark(1:3)
..duration = ZegoVideoConferenceDurationConfig(
canSync: widget.role == Role.Host,
),
events: ZegoUIKitPrebuiltVideoConferenceEvents(
// !mark(1:7)
duration: ZegoVideoConferenceDurationEvents(
onUpdated: (Duration d) {
if (duration.inSeconds == 5 * 60) {
ZegoUIKitPrebuiltVideoConferenceController().room.leave(context);
}
},
),
),
),
);
}
}
