@100mslive/react-native-room-kit 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/HMSRoomSetup.js +13 -1
- package/lib/commonjs/HMSRoomSetup.js.map +1 -1
- package/lib/commonjs/Icons/Clock/assets/clock-vector.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock@2x.png +0 -0
- package/lib/commonjs/Icons/Clock/assets/clock@3x.png +0 -0
- package/lib/commonjs/Icons/Clock/index.js +7 -2
- package/lib/commonjs/Icons/Clock/index.js.map +1 -1
- package/lib/commonjs/components/CreatePoll.js +3 -2
- package/lib/commonjs/components/CreatePoll.js.map +1 -1
- package/lib/commonjs/components/HLSView.js +15 -1
- package/lib/commonjs/components/HLSView.js.map +1 -1
- package/lib/commonjs/components/HMSPollsQuizzesNotification.js +1 -1
- package/lib/commonjs/components/HMSPollsQuizzesNotification.js.map +1 -1
- package/lib/commonjs/components/LeaderboardEntry.js +135 -0
- package/lib/commonjs/components/LeaderboardEntry.js.map +1 -0
- package/lib/commonjs/components/PollAndQuizSheetScreen.js +69 -0
- package/lib/commonjs/components/PollAndQuizSheetScreen.js.map +1 -0
- package/lib/commonjs/components/PollAndQuizVoting.js +133 -4
- package/lib/commonjs/components/PollAndQuizVoting.js.map +1 -1
- package/lib/commonjs/components/PollQuestions.js +104 -4
- package/lib/commonjs/components/PollQuestions.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizBottomSheet.js +9 -11
- package/lib/commonjs/components/PollsAndQuizBottomSheet.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizzesCard.js +1 -1
- package/lib/commonjs/components/PollsAndQuizzesCard.js.map +1 -1
- package/lib/commonjs/components/PollsAndQuizzesModalContent.js +26 -120
- package/lib/commonjs/components/PollsAndQuizzesModalContent.js.map +1 -1
- package/lib/commonjs/components/PollsConfigAndList.js +81 -4
- package/lib/commonjs/components/PollsConfigAndList.js.map +1 -1
- package/lib/commonjs/components/PreviousPollsAndQuizzesList.js +7 -15
- package/lib/commonjs/components/PreviousPollsAndQuizzesList.js.map +1 -1
- package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js +284 -0
- package/lib/commonjs/components/QuizLeaderboardEntriesScreen.js.map +1 -0
- package/lib/commonjs/components/QuizLeaderboardScreen.js +279 -0
- package/lib/commonjs/components/QuizLeaderboardScreen.js.map +1 -0
- package/lib/commonjs/components/QuizLeaderboardSummary.js +195 -0
- package/lib/commonjs/components/QuizLeaderboardSummary.js.map +1 -0
- package/lib/commonjs/components/VoterParticipationSummary.js +46 -0
- package/lib/commonjs/components/VoterParticipationSummary.js.map +1 -0
- package/lib/commonjs/redux/actionTypes.js +7 -1
- package/lib/commonjs/redux/actionTypes.js.map +1 -1
- package/lib/commonjs/redux/actions/index.js +25 -5
- package/lib/commonjs/redux/actions/index.js.map +1 -1
- package/lib/commonjs/redux/reducers/polls.js +65 -5
- package/lib/commonjs/redux/reducers/polls.js.map +1 -1
- package/lib/commonjs/utils/hooks.js +107 -2
- package/lib/commonjs/utils/hooks.js.map +1 -1
- package/lib/module/HMSRoomSetup.js +13 -1
- package/lib/module/HMSRoomSetup.js.map +1 -1
- package/lib/module/Icons/Clock/assets/clock-vector.png +0 -0
- package/lib/module/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock.png +0 -0
- package/lib/module/Icons/Clock/assets/clock@2x.png +0 -0
- package/lib/module/Icons/Clock/assets/clock@3x.png +0 -0
- package/lib/module/Icons/Clock/index.js +7 -2
- package/lib/module/Icons/Clock/index.js.map +1 -1
- package/lib/module/components/CreatePoll.js +4 -3
- package/lib/module/components/CreatePoll.js.map +1 -1
- package/lib/module/components/HLSView.js +17 -3
- package/lib/module/components/HLSView.js.map +1 -1
- package/lib/module/components/HMSPollsQuizzesNotification.js +2 -2
- package/lib/module/components/HMSPollsQuizzesNotification.js.map +1 -1
- package/lib/module/components/LeaderboardEntry.js +126 -0
- package/lib/module/components/LeaderboardEntry.js.map +1 -0
- package/lib/module/components/PollAndQuizSheetScreen.js +60 -0
- package/lib/module/components/PollAndQuizSheetScreen.js.map +1 -0
- package/lib/module/components/PollAndQuizVoting.js +135 -6
- package/lib/module/components/PollAndQuizVoting.js.map +1 -1
- package/lib/module/components/PollQuestions.js +107 -7
- package/lib/module/components/PollQuestions.js.map +1 -1
- package/lib/module/components/PollsAndQuizBottomSheet.js +11 -13
- package/lib/module/components/PollsAndQuizBottomSheet.js.map +1 -1
- package/lib/module/components/PollsAndQuizzesCard.js +2 -2
- package/lib/module/components/PollsAndQuizzesCard.js.map +1 -1
- package/lib/module/components/PollsAndQuizzesModalContent.js +28 -122
- package/lib/module/components/PollsAndQuizzesModalContent.js.map +1 -1
- package/lib/module/components/PollsConfigAndList.js +82 -5
- package/lib/module/components/PollsConfigAndList.js.map +1 -1
- package/lib/module/components/PreviousPollsAndQuizzesList.js +7 -15
- package/lib/module/components/PreviousPollsAndQuizzesList.js.map +1 -1
- package/lib/module/components/QuizLeaderboardEntriesScreen.js +275 -0
- package/lib/module/components/QuizLeaderboardEntriesScreen.js.map +1 -0
- package/lib/module/components/QuizLeaderboardScreen.js +270 -0
- package/lib/module/components/QuizLeaderboardScreen.js.map +1 -0
- package/lib/module/components/QuizLeaderboardSummary.js +186 -0
- package/lib/module/components/QuizLeaderboardSummary.js.map +1 -0
- package/lib/module/components/VoterParticipationSummary.js +37 -0
- package/lib/module/components/VoterParticipationSummary.js.map +1 -0
- package/lib/module/redux/actionTypes.js +7 -1
- package/lib/module/redux/actionTypes.js.map +1 -1
- package/lib/module/redux/actions/index.js +18 -3
- package/lib/module/redux/actions/index.js.map +1 -1
- package/lib/module/redux/reducers/polls.js +65 -5
- package/lib/module/redux/reducers/polls.js.map +1 -1
- package/lib/module/utils/hooks.js +105 -2
- package/lib/module/utils/hooks.js.map +1 -1
- package/lib/typescript/HMSRoomSetup.d.ts.map +1 -1
- package/lib/typescript/Icons/Clock/index.d.ts +1 -0
- package/lib/typescript/Icons/Clock/index.d.ts.map +1 -1
- package/lib/typescript/components/CreatePoll.d.ts.map +1 -1
- package/lib/typescript/components/HLSView.d.ts.map +1 -1
- package/lib/typescript/components/LeaderboardEntry.d.ts +11 -0
- package/lib/typescript/components/LeaderboardEntry.d.ts.map +1 -0
- package/lib/typescript/components/PollAndQuizSheetScreen.d.ts +8 -0
- package/lib/typescript/components/PollAndQuizSheetScreen.d.ts.map +1 -0
- package/lib/typescript/components/PollAndQuizVoting.d.ts +2 -0
- package/lib/typescript/components/PollAndQuizVoting.d.ts.map +1 -1
- package/lib/typescript/components/PollQuestions.d.ts +2 -0
- package/lib/typescript/components/PollQuestions.d.ts.map +1 -1
- package/lib/typescript/components/PollsAndQuizBottomSheet.d.ts.map +1 -1
- package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts +0 -1
- package/lib/typescript/components/PollsAndQuizzesModalContent.d.ts.map +1 -1
- package/lib/typescript/components/PollsConfigAndList.d.ts +1 -0
- package/lib/typescript/components/PollsConfigAndList.d.ts.map +1 -1
- package/lib/typescript/components/PreviousPollsAndQuizzesList.d.ts.map +1 -1
- package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts +8 -0
- package/lib/typescript/components/QuizLeaderboardEntriesScreen.d.ts.map +1 -0
- package/lib/typescript/components/QuizLeaderboardScreen.d.ts +8 -0
- package/lib/typescript/components/QuizLeaderboardScreen.d.ts.map +1 -0
- package/lib/typescript/components/QuizLeaderboardSummary.d.ts +9 -0
- package/lib/typescript/components/QuizLeaderboardSummary.d.ts.map +1 -0
- package/lib/typescript/components/VoterParticipationSummary.d.ts +7 -0
- package/lib/typescript/components/VoterParticipationSummary.d.ts.map +1 -0
- package/lib/typescript/redux/actionTypes.d.ts +29 -8
- package/lib/typescript/redux/actionTypes.d.ts.map +1 -1
- package/lib/typescript/redux/actions/index.d.ts +6 -2
- package/lib/typescript/redux/actions/index.d.ts.map +1 -1
- package/lib/typescript/redux/index.d.ts +2 -1
- package/lib/typescript/redux/index.d.ts.map +1 -1
- package/lib/typescript/redux/reducers/index.d.ts +2 -1
- package/lib/typescript/redux/reducers/index.d.ts.map +1 -1
- package/lib/typescript/redux/reducers/polls.d.ts +3 -2
- package/lib/typescript/redux/reducers/polls.d.ts.map +1 -1
- package/lib/typescript/utils/hooks.d.ts +6 -0
- package/lib/typescript/utils/hooks.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/HMSRoomSetup.tsx +19 -1
- package/src/Icons/Clock/assets/clock-vector.png +0 -0
- package/src/Icons/Clock/assets/clock-vector@2x.png +0 -0
- package/src/Icons/Clock/assets/clock-vector@3x.png +0 -0
- package/src/Icons/Clock/assets/clock.png +0 -0
- package/src/Icons/Clock/assets/clock@2x.png +0 -0
- package/src/Icons/Clock/assets/clock@3x.png +0 -0
- package/src/Icons/Clock/index.tsx +16 -3
- package/src/components/CreatePoll.tsx +7 -2
- package/src/components/HLSView.tsx +27 -1
- package/src/components/HMSPollsQuizzesNotification.tsx +2 -2
- package/src/components/LeaderboardEntry.tsx +172 -0
- package/src/components/PollAndQuizSheetScreen.tsx +85 -0
- package/src/components/PollAndQuizVoting.tsx +181 -7
- package/src/components/PollQuestions.tsx +171 -49
- package/src/components/PollsAndQuizBottomSheet.tsx +20 -42
- package/src/components/PollsAndQuizzesCard.tsx +2 -2
- package/src/components/PollsAndQuizzesModalContent.tsx +40 -163
- package/src/components/PollsConfigAndList.tsx +107 -11
- package/src/components/PreviousPollsAndQuizzesList.tsx +33 -40
- package/src/components/QuizLeaderboardEntriesScreen.tsx +323 -0
- package/src/components/QuizLeaderboardScreen.tsx +342 -0
- package/src/components/QuizLeaderboardSummary.tsx +207 -0
- package/src/components/VoterParticipationSummary.tsx +67 -0
- package/src/redux/actionTypes.ts +35 -5
- package/src/redux/actions/index.ts +34 -6
- package/src/redux/reducers/polls.ts +84 -6
- package/src/utils/hooks.ts +190 -3
package/src/utils/hooks.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
2
|
import { useDispatch, useSelector } from 'react-redux';
|
|
3
3
|
import {
|
|
4
4
|
HMSLocalAudioStats,
|
|
@@ -13,10 +13,12 @@ import {
|
|
|
13
13
|
HMSTrackSource,
|
|
14
14
|
HMSUpdateListenerActions,
|
|
15
15
|
} from '@100mslive/react-native-hms';
|
|
16
|
+
import type { HMSPoll } from '@100mslive/react-native-hms';
|
|
16
17
|
|
|
17
|
-
import type { RootState } from '../redux';
|
|
18
|
-
import { setRTCStats } from '../redux/actions';
|
|
19
18
|
import { ModalTypes } from './types';
|
|
19
|
+
import type { RootState } from '../redux';
|
|
20
|
+
import { addLeaderboard, setRTCStats } from '../redux/actions';
|
|
21
|
+
import { useHMSInstance } from '../hooks-util';
|
|
20
22
|
|
|
21
23
|
export const useRTCStatsListeners = () => {
|
|
22
24
|
const dispatch = useDispatch();
|
|
@@ -102,3 +104,188 @@ export const useRTCStatsListeners = () => {
|
|
|
102
104
|
}
|
|
103
105
|
}, [hmsInstance, addListeners]);
|
|
104
106
|
};
|
|
107
|
+
|
|
108
|
+
export const useFetchLeaderboardResponse = (
|
|
109
|
+
pollId: HMSPoll['pollId'] | undefined
|
|
110
|
+
) => {
|
|
111
|
+
const dispatch = useDispatch();
|
|
112
|
+
const hmsInstance = useHMSInstance();
|
|
113
|
+
|
|
114
|
+
const hasPollWritePermission = useSelector((state: RootState) => {
|
|
115
|
+
const permissions = state.hmsStates.localPeer?.role?.permissions;
|
|
116
|
+
return permissions?.pollWrite;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
const leaderboardData = useSelector((state: RootState) => {
|
|
120
|
+
if (!pollId) return null;
|
|
121
|
+
return state.polls.leaderboards[pollId] || null;
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const leaderboardDataExist = !!leaderboardData;
|
|
125
|
+
|
|
126
|
+
useEffect(() => {
|
|
127
|
+
if (!!leaderboardData) return;
|
|
128
|
+
|
|
129
|
+
let mounted = true;
|
|
130
|
+
|
|
131
|
+
async function fetchLeaderboard() {
|
|
132
|
+
if (pollId) {
|
|
133
|
+
const response = await hmsInstance.interactivityCenter.fetchLeaderboard(
|
|
134
|
+
pollId,
|
|
135
|
+
5,
|
|
136
|
+
1, // Indexing starts from 1
|
|
137
|
+
!hasPollWritePermission // fetchCurrentUser only if user has only pollRead permission
|
|
138
|
+
);
|
|
139
|
+
if (mounted) {
|
|
140
|
+
dispatch(addLeaderboard(pollId, response));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
fetchLeaderboard();
|
|
145
|
+
|
|
146
|
+
return () => {
|
|
147
|
+
mounted = false;
|
|
148
|
+
};
|
|
149
|
+
}, [pollId, leaderboardDataExist, hasPollWritePermission]);
|
|
150
|
+
|
|
151
|
+
return leaderboardData;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
export const useLeaderboardSummaryData = (
|
|
155
|
+
pollId: HMSPoll['pollId'] | undefined
|
|
156
|
+
): { label: string; value: any }[][] | null => {
|
|
157
|
+
const localPeerUserId = useSelector(
|
|
158
|
+
(state: RootState) => state.hmsStates.localPeer?.customerUserID
|
|
159
|
+
);
|
|
160
|
+
const localPeerPollInitiator = useSelector((state: RootState) => {
|
|
161
|
+
if (!pollId) return null;
|
|
162
|
+
const pollInitiatorUserID =
|
|
163
|
+
state.polls.polls[pollId]?.createdBy?.customerUserID;
|
|
164
|
+
return (
|
|
165
|
+
localPeerUserId &&
|
|
166
|
+
pollInitiatorUserID &&
|
|
167
|
+
localPeerUserId === pollInitiatorUserID
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
const canCreateOrEndPoll = useSelector((state: RootState) => {
|
|
171
|
+
const permissions = state.hmsStates.localPeer?.role?.permissions;
|
|
172
|
+
return permissions?.pollWrite;
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const leaderboardData = useSelector((state: RootState) => {
|
|
176
|
+
if (!pollId) return null;
|
|
177
|
+
return state.polls.leaderboards[pollId] || null;
|
|
178
|
+
});
|
|
179
|
+
const pollQuestionsLength = useSelector((state: RootState) => {
|
|
180
|
+
if (!pollId) return null;
|
|
181
|
+
return state.polls.polls[pollId]?.questions?.length;
|
|
182
|
+
});
|
|
183
|
+
const leaderboardSummary = leaderboardData?.summary;
|
|
184
|
+
|
|
185
|
+
const pollInitiatorSummaryData = useMemo(() => {
|
|
186
|
+
if (!localPeerPollInitiator) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return [
|
|
190
|
+
[
|
|
191
|
+
{
|
|
192
|
+
label: 'ANSWERED',
|
|
193
|
+
value:
|
|
194
|
+
leaderboardSummary &&
|
|
195
|
+
typeof leaderboardSummary.respondedPeersCount === 'number' &&
|
|
196
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
197
|
+
? `${Math.round((leaderboardSummary.respondedPeersCount / leaderboardSummary.totalPeersCount) * 100)}% (${leaderboardSummary.respondedPeersCount}/${leaderboardSummary.totalPeersCount})`
|
|
198
|
+
: '-',
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
label: 'CORRECT ANSWERS',
|
|
202
|
+
value:
|
|
203
|
+
leaderboardSummary &&
|
|
204
|
+
typeof leaderboardSummary.respondedCorrectlyPeersCount ===
|
|
205
|
+
'number' &&
|
|
206
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
207
|
+
? `${Math.round((leaderboardSummary.respondedCorrectlyPeersCount / leaderboardSummary?.totalPeersCount) * 100)}% (${leaderboardSummary.respondedCorrectlyPeersCount}/${leaderboardSummary.totalPeersCount})`
|
|
208
|
+
: '-',
|
|
209
|
+
},
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
{
|
|
213
|
+
label: 'AVG. TIME TAKEN',
|
|
214
|
+
value:
|
|
215
|
+
leaderboardSummary &&
|
|
216
|
+
typeof leaderboardSummary.averageTime === 'number'
|
|
217
|
+
? `${(leaderboardSummary.averageTime / 1000).toFixed(2)}s`
|
|
218
|
+
: '-', // averageTime is in milliseconds
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
label: 'AVG. SCORE',
|
|
222
|
+
value:
|
|
223
|
+
leaderboardSummary &&
|
|
224
|
+
typeof leaderboardSummary.averageScore === 'number'
|
|
225
|
+
? leaderboardSummary.averageScore.toFixed(2)
|
|
226
|
+
: '-',
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
];
|
|
230
|
+
}, [leaderboardSummary, localPeerPollInitiator]);
|
|
231
|
+
|
|
232
|
+
const localLeaderboardEntry =
|
|
233
|
+
localPeerUserId && leaderboardData && Array.isArray(leaderboardData.entries)
|
|
234
|
+
? leaderboardData.entries.find(
|
|
235
|
+
(entry) => entry.peer?.customerUserId === localPeerUserId
|
|
236
|
+
)
|
|
237
|
+
: null;
|
|
238
|
+
|
|
239
|
+
const voterSummaryData = useMemo(() => {
|
|
240
|
+
if (!localLeaderboardEntry || canCreateOrEndPoll) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return [
|
|
244
|
+
[
|
|
245
|
+
{
|
|
246
|
+
label: 'YOUR RANK',
|
|
247
|
+
value:
|
|
248
|
+
localLeaderboardEntry &&
|
|
249
|
+
typeof localLeaderboardEntry.totalResponses === 'number' &&
|
|
250
|
+
leaderboardSummary &&
|
|
251
|
+
typeof leaderboardSummary.totalPeersCount === 'number'
|
|
252
|
+
? `${localLeaderboardEntry.position}/${leaderboardSummary.totalPeersCount}`
|
|
253
|
+
: '-',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
label: 'CORRECT ANSWERS',
|
|
257
|
+
value:
|
|
258
|
+
localLeaderboardEntry &&
|
|
259
|
+
typeof localLeaderboardEntry.correctResponses === 'number' &&
|
|
260
|
+
typeof pollQuestionsLength === 'number'
|
|
261
|
+
? `${Math.round((localLeaderboardEntry.correctResponses / pollQuestionsLength) * 100)}% (${localLeaderboardEntry.correctResponses}/${pollQuestionsLength})`
|
|
262
|
+
: '-',
|
|
263
|
+
},
|
|
264
|
+
],
|
|
265
|
+
[
|
|
266
|
+
{
|
|
267
|
+
label: 'TIME TAKEN',
|
|
268
|
+
value:
|
|
269
|
+
localLeaderboardEntry &&
|
|
270
|
+
typeof localLeaderboardEntry.duration === 'number'
|
|
271
|
+
? `${(localLeaderboardEntry.duration / 1000).toFixed(2)}s`
|
|
272
|
+
: '-',
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
label: 'YOUR POINTS',
|
|
276
|
+
value:
|
|
277
|
+
localLeaderboardEntry &&
|
|
278
|
+
typeof localLeaderboardEntry.score === 'number'
|
|
279
|
+
? localLeaderboardEntry.score
|
|
280
|
+
: '-',
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
];
|
|
284
|
+
}, [localLeaderboardEntry, leaderboardSummary?.totalPeersCount]);
|
|
285
|
+
|
|
286
|
+
return localPeerPollInitiator
|
|
287
|
+
? pollInitiatorSummaryData
|
|
288
|
+
: voterSummaryData
|
|
289
|
+
? voterSummaryData
|
|
290
|
+
: null;
|
|
291
|
+
};
|