Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FLUT-234: Leaderboard changes #1716

Merged
merged 21 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.14 - 2024-02-26

| Package | Version |
| -------------- | ------------------------------------------------------------------------------------------------------ |
| hms_room_kit | 1.0.14 |
| hmssdk_flutter | 1.9.11 |

### 🚀 Added

- Introducing leaderboards to our quiz experience

Adding leaderboard to our quizzes with leaderboard summary and rankings.

Updated `hmssdk_flutter` package version to 1.9.11

## 1.0.13 - 2024-02-16

| Package | Version |
Expand Down
7 changes: 3 additions & 4 deletions packages/hms_room_kit/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,9 @@ packages:
hmssdk_flutter:
dependency: transitive
description:
name: hmssdk_flutter
sha256: "4706d94dfd0136bf0bf2e8377cf0bd95a3d5e9edfa2a6a7c6b609c8a4bd6a16e"
url: "https://pub.dev"
source: hosted
path: "../../hmssdk_flutter"
relative: true
source: path
version: "1.9.10"
http:
dependency: transitive
Expand Down
2 changes: 1 addition & 1 deletion packages/hms_room_kit/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: "none" # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 1.0.13
version: 1.0.14

environment:
sdk: ">=2.19.6 <3.0.0"
Expand Down
8 changes: 8 additions & 0 deletions packages/hms_room_kit/lib/src/assets/icons/tick_circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/hms_room_kit/lib/src/assets/icons/topper.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 32 additions & 4 deletions packages/hms_room_kit/lib/src/hmssdk_interactor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,27 +424,55 @@ class HMSSDKInteractor {
{required HMSPoll poll,
required HMSPollQuestion question,
required HMSPollQuestionOption pollQuestionOption,
HMSPeer? peer}) {
HMSPeer? peer,
Duration? timeTakenToAnswer}) {
return HMSPollInteractivityCenter.addSingleChoicePollResponse(
hmsPoll: poll,
pollQuestion: question,
optionSelected: pollQuestionOption,
peer: peer);
peer: peer,
timeTakenToAnswer: timeTakenToAnswer);
}

Future<dynamic> addMultiChoicePollResponse(
{required HMSPoll poll,
required HMSPollQuestion question,
required List<HMSPollQuestionOption> pollQuestionOption,
HMSPeer? peer}) {
HMSPeer? peer,
Duration? timeTakenToAnswer}) {
return HMSPollInteractivityCenter.addMultiChoicePollResponse(
hmsPoll: poll,
pollQuestion: question,
optionsSelected: pollQuestionOption,
peer: peer);
peer: peer,
timeTakenToAnswer: timeTakenToAnswer);
}

Future<dynamic> stopPoll({required HMSPoll poll}) {
return HMSPollInteractivityCenter.stopPoll(poll: poll);
}

Future<dynamic> fetchLeaderboard(
{required HMSPoll poll,
required int count,
required int startIndex,
required bool includeCurrentPeer}) {
return HMSPollInteractivityCenter.fetchLeaderboard(
poll: poll,
count: count,
startIndex: startIndex,
includeCurrentPeer: includeCurrentPeer);
}

Future<dynamic> fetchPollList({required HMSPollState hmsPollState}) {
return HMSPollInteractivityCenter.fetchPollList(hmsPollState: hmsPollState);
}

Future<dynamic> fetchPollQuestions({required HMSPoll hmsPoll}) {
return HMSPollInteractivityCenter.fetchPollQuestions(hmsPoll: hmsPoll);
}

Future<dynamic> getPollResults({required HMSPoll hmsPoll}) {
return HMSPollInteractivityCenter.getPollResults(hmsPoll: hmsPoll);
}
}
89 changes: 85 additions & 4 deletions packages/hms_room_kit/lib/src/meeting/meeting_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ class MeetingStore extends ChangeNotifier
getAudioDevicesList();
notifyListeners();
setViewControllers();
// fetchPollList(HMSPollState.stopped);
// if (Platform.isIOS &&
// HMSRoomLayout.roleLayoutData?.screens?.conferencing?.defaultConf !=
// null) {
Expand Down Expand Up @@ -2243,27 +2244,104 @@ class MeetingStore extends ChangeNotifier

///Method to add Poll Response
void addSingleChoicePollResponse(HMSPoll poll, HMSPollQuestion question,
HMSPollQuestionOption pollQuestionOption) {
HMSPollQuestionOption pollQuestionOption,
{Duration? timeTakenToAnswer}) {
_hmsSDKInteractor.addSingleChoicePollResponse(
poll: poll,
question: question,
pollQuestionOption: pollQuestionOption,
peer: localPeer);
peer: localPeer,
timeTakenToAnswer: timeTakenToAnswer);
}

void addMultiChoicePollResponse(HMSPoll poll, HMSPollQuestion question,
List<HMSPollQuestionOption> pollQuestionOption) {
List<HMSPollQuestionOption> pollQuestionOption,
{Duration? timeTakenToAnswer}) {
_hmsSDKInteractor.addMultiChoicePollResponse(
poll: poll,
question: question,
pollQuestionOption: pollQuestionOption,
peer: localPeer);
peer: localPeer,
timeTakenToAnswer: timeTakenToAnswer);
}

void stopPoll(HMSPoll poll) {
_hmsSDKInteractor.stopPoll(poll: poll);
}

void fetchLeaderboard(HMSPoll poll) async {
var data = await _hmsSDKInteractor.fetchLeaderboard(
poll: poll, count: 5, startIndex: 0, includeCurrentPeer: true);

if (data is HMSPollLeaderboardResponse) {
var pollIndex = pollQuestions
.indexWhere((element) => element.poll.pollId == poll.pollId);
if (pollIndex != -1) {
pollQuestions[pollIndex].updatePollLeaderboardResponse(data);
}
} else {
log("fetchLeaderboard error: $data");
}
notifyListeners();
}

// void fetchPollList(HMSPollState state) async {
// var data = await _hmsSDKInteractor.fetchPollList(hmsPollState: state);

// if (data is List<HMSPoll>) {
// for (var element in data) {
// pollQuestions.add(HMSPollStore(poll: element));
// }
// sortPollQuestions();
// } else {
// log("fetchPollList error: $data");
// }
// }

// void fetchPollQuestions(HMSPoll poll) async {
// var data = await _hmsSDKInteractor.fetchPollQuestions(hmsPoll: poll);

// if (data is List<HMSPollQuestion>) {
// int index = pollQuestions
// .indexWhere((element) => element.poll.pollId == poll.pollId);

// if (index != -1) {
// var newPoll = HMSPoll(
// pollId: poll.pollId,
// title: poll.title,
// anonymous: poll.anonymous,
// category: poll.category,
// createdBy: poll.createdBy,
// duration: poll.duration,
// pollUserTrackingMode: poll.pollUserTrackingMode,
// questionCount: data.length,
// questions: data,
// result: poll.result,
// rolesThatCanViewResponses: poll.rolesThatCanViewResponses,
// rolesThatCanVote: poll.rolesThatCanVote,
// startedAt: poll.startedAt,
// startedBy: poll.startedBy,
// state: poll.state,
// stoppedAt: poll.stoppedAt,
// stoppedBy: poll.stoppedBy);
// pollQuestions[index].updateState(newPoll);
// }
// }
// }

// void getPollResults(HMSPoll poll) async {
// var data = await _hmsSDKInteractor.getPollResults(hmsPoll: poll);

// if (data is HMSPoll) {
// int index = pollQuestions
// .indexWhere((element) => element.poll.pollId == poll.pollId);

// if (index != -1) {
// pollQuestions[index].updateState(data);
// }
// }
// }

//Get onSuccess or onException callbacks for HMSActionResultListenerMethod
@override
void onSuccess(
Expand Down Expand Up @@ -2749,6 +2827,9 @@ class MeetingStore extends ChangeNotifier
break;

case HMSPollUpdateType.stopped:
if (poll.category == HMSPollCategory.quiz) {
fetchLeaderboard(poll);
}
removeToast(HMSToastsType.pollStartedToast, data: poll.pollId);
int index = pollQuestions
.indexWhere((element) => element.poll.pollId == poll.pollId);
Expand Down
7 changes: 7 additions & 0 deletions packages/hms_room_kit/lib/src/model/poll_store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:hmssdk_flutter/hmssdk_flutter.dart';
///without rebuilding the whole UI
class HMSPollStore extends ChangeNotifier {
HMSPoll poll;
HMSPollLeaderboardResponse? pollLeaderboardResponse;

HMSPollStore({required this.poll});

Expand All @@ -17,4 +18,10 @@ class HMSPollStore extends ChangeNotifier {
this.poll = poll;
notifyListeners();
}

void updatePollLeaderboardResponse(
HMSPollLeaderboardResponse pollLeaderboardResponse) {
this.pollLeaderboardResponse = pollLeaderboardResponse;
notifyListeners();
}
}
Loading