Skip to content

Commit

Permalink
Merge pull request #1721 from 100mslive/refactor-polls
Browse files Browse the repository at this point in the history
Refactor polls
  • Loading branch information
Decoder07 authored Mar 4, 2024
2 parents 6739e48 + f3e667e commit cde17c0
Show file tree
Hide file tree
Showing 22 changed files with 272 additions and 59 deletions.
15 changes: 15 additions & 0 deletions packages/hms_room_kit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
| hms_room_kit | [![Pub Version](https://img.shields.io/pub/v/hms_room_kit)](https://pub.dev/packages/hms_room_kit) |
| hmssdk_flutter | [![Pub Version](https://img.shields.io/pub/v/hmssdk_flutter)](https://pub.dev/packages/hmssdk_flutter) |

## 1.0.15 - 2024-03-04

| Package | Version |
| -------------- | ------------------------------------------------------------------------------------------------------ |
| hms_room_kit | 1.0.15 |
| hmssdk_flutter | 1.9.12 |

### 🚀 Added

- Ability to fetch concluded and draft polls

Prebuilt now fetches all the polls happened during the session. Additionally, users can now retrieve draft polls from other platforms and launch them.

Updated `hmssdk_flutter` package version to 1.9.12

## 1.0.14 - 2024-02-26

| Package | Version |
Expand Down
6 changes: 4 additions & 2 deletions packages/hms_room_kit/lib/src/hms_prebuilt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class HMSPrebuilt extends StatelessWidget {
/// The room code is: xvm-wxwo-gbl
final String? roomCode;

///[token]: The auth token to join the room
///[authToken]: The auth token to join the room
final String? authToken;

///The options for the prebuilt
Expand Down Expand Up @@ -47,8 +47,10 @@ class HMSPrebuilt extends StatelessWidget {
///Returns a [ScreenController] widget
///The [ScreenController] is the main widget that renders the prebuilt
///For more details checkout the [ScreenController] class
///It takes the [roomCode],[options] and [onLeave] as parameters
///It takes the [roomCode],[authToken], [options] and [onLeave] as parameters
///The [roomCode] is the room code of the room to join
///The [authToken] is the auth token to join the room
///User need to pass either [roomCode] or [authToken] to join the room
///The [options] are the options for the prebuilt
///For more details checkout the [HMSPrebuiltOptions] class
///The [options] are optional and are used to customize the prebuilt
Expand Down
17 changes: 12 additions & 5 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ class MeetingStore extends ChangeNotifier
dynamic tokenData;

if (Constant.roomCode != null) {
await _hmsSDKInteractor.getAuthTokenByRoomCode(
tokenData = await _hmsSDKInteractor.getAuthTokenByRoomCode(
userId: Constant.prebuiltOptions?.userId,
roomCode: Constant.roomCode!,
endPoint: Constant.tokenEndPoint);
Expand Down Expand Up @@ -1377,8 +1377,10 @@ class MeetingStore extends ChangeNotifier
_hmsSessionStore?.removeKeyChangeListener(hmsKeyChangeListener: this);
_hmsSDKInteractor.removeHMSLogger();
HMSHLSPlayerController.removeHMSHLSPlaybackEventsListener(this);
HMSPollInteractivityCenter.removePollUpdateListener();
}

///Function to toggle screen share
void toggleScreenShare() {
if (!isScreenShareOn) {
startScreenShare();
Expand Down Expand Up @@ -2666,10 +2668,7 @@ class MeetingStore extends ChangeNotifier
@override
void onCue({required HMSHLSCue hlsCue}) {
log("onCue -> payload:${hlsCue.startDate}");
/**
* Here we use a list of alignments and select an alignment at random and use it
* to position the toast for timed metadata
*/

if (hlsCue.payload != null) {
/*
* Below code shows the poll for hls-viewer who are viewing stream at a delay.
Expand Down Expand Up @@ -2838,6 +2837,9 @@ class MeetingStore extends ChangeNotifier
}
}
} else {
///This handles the draft polls since they are already in the list
///Here we update the poll in HMSPollStore and add toast as the poll state changes
///from `created` to `started`.
pollQuestions[index].updateState(poll);
sortPollQuestions();
toasts.add(HMSToastModel(pollQuestions[index],
Expand All @@ -2857,9 +2859,14 @@ class MeetingStore extends ChangeNotifier
break;

case HMSPollUpdateType.stopped:

///If it's a quiz we fetch the leaderboard
if (poll.category == HMSPollCategory.quiz) {
fetchLeaderboard(poll);
}

///Here we remove the toast if it's present
///update the poll in HMSPollStore and sort the poll questions
removeToast(HMSToastsType.pollStartedToast, data: poll.pollId);
int index = pollQuestions
.indexWhere((element) => element.poll.pollId == poll.pollId);
Expand Down
4 changes: 3 additions & 1 deletion packages/hms_room_kit/lib/src/preview/preview_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ class _PreviewPageState extends State<PreviewPage> {
_setMeetingStore(previewStore);

/// We join the room here
HMSException? ans = await _meetingStore.join(nameController.text.trim());
HMSException? ans = await _meetingStore.join(nameController.text.trim(),
roomConfig: previewStore.roomConfig);

///If the room join fails we show the error dialog
if (ans != null && mounted) {
Expand Down Expand Up @@ -154,6 +155,7 @@ class _PreviewPageState extends State<PreviewPage> {
CupertinoPageRoute(
builder: (_) => ScreenController(
roomCode: Constant.roomCode,
authToken: Constant.authToken,
options: widget.options,
)));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hms_room_kit/lib/src/screen_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ScreenController extends StatefulWidget {
///[roomCode] is the room code of the room to join
final String? roomCode;

///[token] auth token to join the room
///[authToken] auth token to join the room
final String? authToken;

///[options] is the options for the prebuilt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class HMSLeftRoomScreen extends StatelessWidget {
MaterialPageRoute(
builder: (_) => HMSPrebuilt(
roomCode: Constant.roomCode,
authToken: Constant.authToken,
options: Constant.prebuiltOptions,
onLeave: Constant.onLeave,
))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
///Package imports
import 'package:flutter/material.dart';

///Project imports
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/summary_box.dart';

///[LeaderboardCreatorSummary] renders the creator quiz summary
class LeaderboardCreatorSummary extends StatelessWidget {
final double? votedPercent;
final String? votedDescription;
Expand Down Expand Up @@ -51,6 +55,7 @@ class LeaderboardCreatorSummary extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
///This is only rendered if the time taken is significant
if (avgTimeInMilliseconds != null && avgTimeInMilliseconds! > 0)
Expanded(
child: SummaryBox(
Expand All @@ -59,7 +64,9 @@ class LeaderboardCreatorSummary extends StatelessWidget {
? "-"
: "${avgTimeInMilliseconds! / 1000}s"),
),
if (avgScore != null && avgScore! > 0)

///This is only rendered if the time taken is significant
if (avgTimeInMilliseconds != null && avgTimeInMilliseconds! > 0)
const SizedBox(
width: 10,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
///Package imports
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///Project imports
import 'package:hms_room_kit/hms_room_kit.dart';
import 'package:hms_room_kit/src/model/poll_store.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_subheading_text.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';

///[LeaderBoardEntryWidget] renders the tile for each peer ranking
class LeaderBoardEntryWidget extends StatelessWidget {
final HMSPollLeaderboardEntry entry;
final HMSPollStore pollStore;
Expand All @@ -18,7 +22,9 @@ class LeaderBoardEntryWidget extends StatelessWidget {
required this.pollStore,
this.tileColor});

Color getPositionBadgeColor() {
///[_getPositionBadgeColor] returns the circleAvatar color based on the position
///of the peer in the rankings
Color _getPositionBadgeColor() {
switch (entry.position) {
case 1:
return const Color.fromRGBO(214, 149, 22, 1);
Expand All @@ -31,11 +37,13 @@ class LeaderBoardEntryWidget extends StatelessWidget {
}
}

///[_showTime] returns whether to show time or not
bool _showTime() {
return (entry.duration != null && entry.duration!.inSeconds > 0);
}

String getFormattedTime() {
///[_getFormattedTime] returns the formatted time, in the format 1m 23s meaning 1 minute and 23 seconds
String _getFormattedTime() {
String time = "";
if (entry.duration == null) {
return time;
Expand All @@ -62,7 +70,7 @@ class LeaderBoardEntryWidget extends StatelessWidget {
horizontalTitleGap: 0,
leading: CircleAvatar(
radius: 12,
backgroundColor: getPositionBadgeColor(),
backgroundColor: _getPositionBadgeColor(),
child: HMSSubtitleText(
text: entry.position.toString(),
textColor: HMSThemeColors.baseWhite,
Expand All @@ -82,6 +90,7 @@ class LeaderBoardEntryWidget extends StatelessWidget {
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
///If the position of peer is 1st we render the trophy
if (entry.position == 1) const Text("🏆"),
if (entry.position == 1)
const SizedBox(
Expand All @@ -98,6 +107,8 @@ class LeaderBoardEntryWidget extends StatelessWidget {
text:
"${entry.correctResponses}/${pollStore.poll.questions?.length}",
textColor: HMSThemeColors.onSurfaceHighEmphasis),

///Below widgets are only rendered if the taken by the peer is significant
if (_showTime())
const SizedBox(
width: 12,
Expand All @@ -115,7 +126,7 @@ class LeaderBoardEntryWidget extends StatelessWidget {
),
if (_showTime())
HMSSubtitleText(
text: getFormattedTime(),
text: _getFormattedTime(),
textColor: HMSThemeColors.onSurfaceHighEmphasis)
],
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
///Dart imports
import 'dart:math' as math;

////Package imports
import 'package:flutter/material.dart';

///Project imports
import 'package:hms_room_kit/src/layout_api/hms_theme_colors.dart';
import 'package:hms_room_kit/src/model/poll_store.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_subtitle_text.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_title_text.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/leaderboard_entry_widget.dart';

///[LeaderboardRankings] renders the leaderboard rankings
class LeaderboardRankings extends StatefulWidget {
final int totalScore;
final HMSPollStore pollStore;
Expand Down Expand Up @@ -51,6 +55,9 @@ class _LeaderboardRankingsState extends State<LeaderboardRankings> {
shrinkWrap: true,
padding: EdgeInsets.zero,
physics: const NeverScrollableScrollPhysics(),

///If [showTopFivePeers] is true we show at max 5 peers
///else we show all the participants rankings
itemCount: widget.showTopFivePeers
? math.min(5,
widget.pollStore.pollLeaderboardResponse!.entries!.length)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
///Package imports
import 'package:flutter/material.dart';

///Project imports
import 'package:hms_room_kit/src/layout_api/hms_theme_colors.dart';
import 'package:hms_room_kit/src/model/poll_store.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/hms_title_text.dart';
import 'package:hms_room_kit/src/widgets/common_widgets/live_badge.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/leaderboard_rankings.dart';

///[LeaderboardRankingsList] renders the rankings list
class LeaderboardRankingsList extends StatelessWidget {
final int totalScore;
final HMSPollStore pollStore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
///Package imports
import 'package:flutter/material.dart';
import 'package:hms_room_kit/src/widgets/poll_widgets/leaderboard_widgets/summary_box.dart';

///[LeaderboardVoterSummary] renders the voter summary
class LeaderboardVoterSummary extends StatelessWidget {
final String? rank;
final int? points;
Expand All @@ -22,7 +24,8 @@ class LeaderboardVoterSummary extends StatelessWidget {
this.showPoints = true,
this.questionsAttempted});

String setAnsweredProperty() {
///[_setAnsweredProperty] returns the text to rendered based on the questionsAttempted and totalQuestions values
String _setAnsweredProperty() {
if (questionsAttempted == null || totalQuestions == null) {
return "-";
} else {
Expand All @@ -42,8 +45,10 @@ class LeaderboardVoterSummary extends StatelessWidget {
? SummaryBox(
title: "YOUR RANK", subtitle: rank == null ? "-" : rank!)
: SummaryBox(
title: "ANSWERED", subtitle: setAnsweredProperty()),
title: "ANSWERED", subtitle: _setAnsweredProperty()),
),

///This is only rendered is [showPoints] is true
if (showPoints)
const SizedBox(
width: 10,
Expand All @@ -70,6 +75,8 @@ class LeaderboardVoterSummary extends StatelessWidget {
? "-"
: "${avgTimeInMilliseconds! / 1000} secs"),
),

///This is only rendered if time taken to answer the question is relevant
if (avgTimeInMilliseconds != null && avgTimeInMilliseconds! > 0)
const SizedBox(
width: 10,
Expand Down
Loading

0 comments on commit cde17c0

Please sign in to comment.