From a015a711ab466358b54cda095792e319251fb5d9 Mon Sep 17 00:00:00 2001 From: Kaustubh Kumar Date: Wed, 4 Sep 2024 11:39:42 +0530 Subject: [PATCH 1/5] Update README.md (#3222) --- examples/prebuilt-react-integration/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/prebuilt-react-integration/README.md b/examples/prebuilt-react-integration/README.md index a4ee892a36..c0ba926c6d 100644 --- a/examples/prebuilt-react-integration/README.md +++ b/examples/prebuilt-react-integration/README.md @@ -4,7 +4,7 @@ ### How to run locally? -- Run `yarn build` at the root level of the repo. +- Run `yarn && yarn build` at the root level of the repo (./web-sdks) - Then, navigate to this folder and run `yarn dev` ### Facing a problem? From c094ee272ccb2f9fb1995a9b74f7bd14c9f0d58a Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Wed, 18 Sep 2024 17:47:34 +0530 Subject: [PATCH 2/5] feat: apply policy settings to tracks added via addTrack --- packages/hms-video-store/src/sdk/index.ts | 46 ++++++++++++++++++- .../hms-video-store/src/utils/validations.ts | 12 +++++ 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/packages/hms-video-store/src/sdk/index.ts b/packages/hms-video-store/src/sdk/index.ts index 4bfda90f5e..e0a015a817 100644 --- a/packages/hms-video-store/src/sdk/index.ts +++ b/packages/hms-video-store/src/sdk/index.ts @@ -24,6 +24,7 @@ import { HMSAction } from '../error/HMSAction'; import { HMSException } from '../error/HMSException'; import { EventBus } from '../events/EventBus'; import { + HMSAudioCodec, HMSChangeMultiTrackStateParams, HMSConfig, HMSConnectionQualityListener, @@ -37,6 +38,7 @@ import { HMSRole, HMSRoleChangeRequest, HMSScreenShareConfig, + HMSVideoCodec, TokenRequest, TokenRequestOptions, } from '../interfaces'; @@ -51,6 +53,7 @@ import { RTMPRecordingConfig } from '../interfaces/rtmp-recording-config'; import InitialSettings from '../interfaces/settings'; import { HMSAudioListener, HMSPeerUpdate, HMSTrackUpdate, HMSUpdateListener } from '../interfaces/update-listener'; import { PlaylistManager, TranscriptionConfig } from '../internal'; +import { HMSAudioTrackSettingsBuilder, HMSVideoTrackSettingsBuilder } from '../media/settings'; import { HMSLocalStream } from '../media/streams/HMSLocalStream'; import { HMSLocalAudioTrack, @@ -95,7 +98,7 @@ import HMSLogger, { HMSLogLevel } from '../utils/logger'; import { HMSAudioContextHandler } from '../utils/media'; import { isNode } from '../utils/support'; import { workerSleep } from '../utils/timer-utils'; -import { validateMediaDevicesExistence, validateRTCPeerConnection } from '../utils/validations'; +import { validateMediaDevicesExistence, validatePublishParams, validateRTCPeerConnection } from '../utils/validations'; const INITIAL_STATE = { published: false, @@ -954,7 +957,8 @@ export class HMSSdk implements HMSInterface { const TrackKlass = type === 'audio' ? HMSLocalAudioTrack : HMSLocalVideoTrack; const hmsTrack = new TrackKlass(stream, track, source, this.eventBus); - this.setPlaylistSettings({ + await this.applySettings(hmsTrack); + await this.setPlaylistSettings({ track, hmsTrack, source, @@ -1603,4 +1607,42 @@ export class HMSSdk implements HMSInterface { this.playlistManager.stop(HMSPlaylistType.video); } } + + // eslint-disable-next-line complexity + private async applySettings(track: HMSLocalTrack) { + validatePublishParams(this.store); + const publishParams = this.store.getPublishParams(); + // this is not needed but added for avoiding ? later + if (!publishParams) { + return; + } + if (track instanceof HMSLocalVideoTrack) { + const publishKey = track.source === 'regular' ? 'video' : track.source === 'screen' ? 'screen' : ''; + if (!publishKey || !publishParams.allowed.includes(publishKey)) { + return; + } + const video = publishParams[publishKey]; + if (!video) { + return; + } + const settings = new HMSVideoTrackSettingsBuilder() + .codec(video.codec as HMSVideoCodec) + .maxBitrate(video.bitRate) + .maxFramerate(video.frameRate) + .setWidth(video.width) + .setHeight(video.height) + .build(); + + await track.setSettings(settings); + } else if (track instanceof HMSLocalAudioTrack) { + if (!publishParams.allowed.includes('audio')) { + return; + } + const settings = new HMSAudioTrackSettingsBuilder() + .codec(publishParams.audio.codec as HMSAudioCodec) + .maxBitrate(publishParams.audio.bitRate) + .build(); + await track.setSettings(settings); + } + } } diff --git a/packages/hms-video-store/src/utils/validations.ts b/packages/hms-video-store/src/utils/validations.ts index fc75902e44..a1a1824c16 100644 --- a/packages/hms-video-store/src/utils/validations.ts +++ b/packages/hms-video-store/src/utils/validations.ts @@ -1,5 +1,7 @@ import HMSLogger from './logger'; import { ErrorFactory } from '../error/ErrorFactory'; +import { HMSAction } from '../error/HMSAction'; +import { Store } from '../sdk/store'; const TAG = `[VALIDATIONS]`; @@ -32,3 +34,13 @@ export const validateMediaDevicesExistence = () => { throw error; } }; + +export const validatePublishParams = (store: Store) => { + const publishParams = store.getPublishParams(); + if (!publishParams) { + throw ErrorFactory.GenericErrors.NotConnected( + HMSAction.VALIDATION, + 'call addTrack after preview or join is successful', + ); + } +}; From da50781c2357d6201da1c94dcfef574a0081e2dc Mon Sep 17 00:00:00 2001 From: Ravi theja Date: Wed, 18 Sep 2024 19:59:15 +0530 Subject: [PATCH 3/5] Release - 0.12.20 --- .../prebuilt-react-integration/package.json | 2 +- packages/hls-player/package.json | 4 +-- packages/hls-stats/package.json | 2 +- packages/hms-video-store/package.json | 2 +- packages/hms-virtual-background/package.json | 6 ++-- packages/hms-whiteboard/package.json | 2 +- packages/react-icons/package.json | 2 +- packages/react-sdk/package.json | 4 +-- packages/roomkit-react/package.json | 12 +++---- packages/roomkit-web/package.json | 4 +-- yarn.lock | 31 ++----------------- 11 files changed, 23 insertions(+), 48 deletions(-) diff --git a/examples/prebuilt-react-integration/package.json b/examples/prebuilt-react-integration/package.json index ed6de5ef5c..d42595fd1b 100644 --- a/examples/prebuilt-react-integration/package.json +++ b/examples/prebuilt-react-integration/package.json @@ -10,7 +10,7 @@ "preview": "vite preview" }, "dependencies": { - "@100mslive/roomkit-react": "0.3.19", + "@100mslive/roomkit-react": "0.3.20", "react": "^18.2.0", "react-dom": "^18.2.0" }, diff --git a/packages/hls-player/package.json b/packages/hls-player/package.json index aef1341044..31993c800e 100644 --- a/packages/hls-player/package.json +++ b/packages/hls-player/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/hls-player", - "version": "0.3.19", + "version": "0.3.20", "description": "HLS client library which uses HTML5 Video element and Media Source Extension for playback", "main": "dist/index.cjs.js", "module": "dist/index.js", @@ -36,7 +36,7 @@ "author": "100ms", "license": "MIT", "dependencies": { - "@100mslive/hls-stats": "0.4.19", + "@100mslive/hls-stats": "0.4.20", "eventemitter2": "^6.4.9", "hls.js": "1.4.12" } diff --git a/packages/hls-stats/package.json b/packages/hls-stats/package.json index 22693113c2..43a02194e3 100644 --- a/packages/hls-stats/package.json +++ b/packages/hls-stats/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/hls-stats", - "version": "0.4.19", + "version": "0.4.20", "description": "A simple library that provides stats for your hls stream", "main": "dist/index.cjs.js", "module": "dist/index.js", diff --git a/packages/hms-video-store/package.json b/packages/hms-video-store/package.json index 4de8b79e14..5feeb58a55 100644 --- a/packages/hms-video-store/package.json +++ b/packages/hms-video-store/package.json @@ -1,5 +1,5 @@ { - "version": "0.12.19", + "version": "0.12.20", "license": "MIT", "repository": { "type": "git", diff --git a/packages/hms-virtual-background/package.json b/packages/hms-virtual-background/package.json index db95e6229e..7e4aef1d06 100755 --- a/packages/hms-virtual-background/package.json +++ b/packages/hms-virtual-background/package.json @@ -1,5 +1,5 @@ { - "version": "1.13.19", + "version": "1.13.20", "license": "MIT", "name": "@100mslive/hms-virtual-background", "author": "100ms", @@ -62,10 +62,10 @@ "format": "prettier --write src/**/*.ts" }, "peerDependencies": { - "@100mslive/hms-video-store": "0.12.19" + "@100mslive/hms-video-store": "0.12.20" }, "devDependencies": { - "@100mslive/hms-video-store": "0.12.19" + "@100mslive/hms-video-store": "0.12.20" }, "dependencies": { "@mediapipe/selfie_segmentation": "^0.1.1632777926", diff --git a/packages/hms-whiteboard/package.json b/packages/hms-whiteboard/package.json index 16cefb5a0b..1d28822d5d 100644 --- a/packages/hms-whiteboard/package.json +++ b/packages/hms-whiteboard/package.json @@ -2,7 +2,7 @@ "name": "@100mslive/hms-whiteboard", "author": "100ms", "license": "MIT", - "version": "0.0.9", + "version": "0.0.10", "main": "dist/index.cjs.js", "module": "dist/index.js", "types": "dist/index.d.ts", diff --git a/packages/react-icons/package.json b/packages/react-icons/package.json index 36b2f3f81d..5e92a12522 100644 --- a/packages/react-icons/package.json +++ b/packages/react-icons/package.json @@ -4,7 +4,7 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "version": "0.10.19", + "version": "0.10.20", "author": "100ms", "license": "MIT", "repository": { diff --git a/packages/react-sdk/package.json b/packages/react-sdk/package.json index d11b5e48e4..36dccbbf5f 100644 --- a/packages/react-sdk/package.json +++ b/packages/react-sdk/package.json @@ -4,7 +4,7 @@ "main": "dist/index.cjs.js", "module": "dist/index.js", "typings": "dist/index.d.ts", - "version": "0.10.19", + "version": "0.10.20", "author": "100ms", "license": "MIT", "repository": { @@ -48,7 +48,7 @@ "react": ">=16.8 <19.0.0" }, "dependencies": { - "@100mslive/hms-video-store": "0.12.19", + "@100mslive/hms-video-store": "0.12.20", "react-resize-detector": "^7.0.0", "zustand": "^3.6.2" } diff --git a/packages/roomkit-react/package.json b/packages/roomkit-react/package.json index 6088afa43c..64143afab3 100644 --- a/packages/roomkit-react/package.json +++ b/packages/roomkit-react/package.json @@ -10,7 +10,7 @@ "prebuilt", "roomkit" ], - "version": "0.3.19", + "version": "0.3.20", "author": "100ms", "license": "MIT", "repository": { @@ -75,12 +75,12 @@ "react": ">=17.0.2 <19.0.0" }, "dependencies": { - "@100mslive/hls-player": "0.3.19", + "@100mslive/hls-player": "0.3.20", "@100mslive/hms-noise-cancellation": "0.0.1", - "@100mslive/hms-virtual-background": "1.13.19", - "@100mslive/hms-whiteboard": "0.0.9", - "@100mslive/react-icons": "0.10.19", - "@100mslive/react-sdk": "0.10.19", + "@100mslive/hms-virtual-background": "1.13.20", + "@100mslive/hms-whiteboard": "0.0.10", + "@100mslive/react-icons": "0.10.20", + "@100mslive/react-sdk": "0.10.20", "@100mslive/types-prebuilt": "0.12.12", "@emoji-mart/data": "^1.0.6", "@emoji-mart/react": "^1.0.1", diff --git a/packages/roomkit-web/package.json b/packages/roomkit-web/package.json index 59220be296..a505315d10 100644 --- a/packages/roomkit-web/package.json +++ b/packages/roomkit-web/package.json @@ -1,6 +1,6 @@ { "name": "@100mslive/roomkit-web", - "version": "0.2.19", + "version": "0.2.20", "description": "A web component implementation of 100ms Prebuilt component", "keywords": [ "web-components", @@ -33,7 +33,7 @@ "build": "rm -rf dist && node ../../scripts/build-webapp" }, "dependencies": { - "@100mslive/roomkit-react": "0.3.19", + "@100mslive/roomkit-react": "0.3.20", "@r2wc/react-to-web-component": "2.0.2" } } diff --git a/yarn.lock b/yarn.lock index 091e434c67..8cb23dcb50 100644 --- a/yarn.lock +++ b/yarn.lock @@ -16534,16 +16534,7 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0": - version "4.2.3" - resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" - integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== - dependencies: - emoji-regex "^8.0.0" - is-fullwidth-code-point "^3.0.0" - strip-ansi "^6.0.1" - -"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -16648,14 +16639,7 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1": - version "6.0.1" - resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" - integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== - dependencies: - ansi-regex "^5.0.1" - -strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== @@ -18008,7 +17992,7 @@ worker-timers@^7.0.40: worker-timers-broker "^6.0.95" worker-timers-worker "^7.0.59" -"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0": +"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0: version "7.0.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== @@ -18026,15 +18010,6 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0: string-width "^4.1.0" strip-ansi "^6.0.0" -wrap-ansi@^7.0.0: - version "7.0.0" - resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43" - integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q== - dependencies: - ansi-styles "^4.0.0" - string-width "^4.1.0" - strip-ansi "^6.0.0" - wrap-ansi@^8.1.0: version "8.1.0" resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214" From d56ae09ccfeaa3ce805fc8f3f42722c9218dee96 Mon Sep 17 00:00:00 2001 From: hdz-666 <93115614+hdz-666@users.noreply.github.com> Date: Tue, 3 Dec 2024 13:22:26 +0530 Subject: [PATCH 4/5] fix: disable voting for ice disconncetion --- .../components/Polls/Voting/QuestionCard.jsx | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx index fcedf91f95..bbc1994d0b 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx @@ -1,7 +1,14 @@ // @ts-check import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { match } from 'ts-pattern'; -import { selectLocalPeer, selectLocalPeerRoleName, useHMSActions, useHMSStore } from '@100mslive/react-sdk'; +import { + HMSRoomState, + selectLocalPeer, + selectLocalPeerRoleName, + selectRoomState, + useHMSActions, + useHMSStore, +} from '@100mslive/react-sdk'; import { CheckCircleIcon, ChevronDownIcon, CrossCircleIcon } from '@100mslive/react-icons'; import { Box, Button, Flex, Text } from '../../../../'; import { checkCorrectAnswer } from '../../../common/utils'; @@ -27,7 +34,7 @@ export const QuestionCard = ({ }) => { const actions = useHMSActions(); const localPeer = useHMSStore(selectLocalPeer); - + const roomState = useHMSStore(selectRoomState); const isLocalPeerCreator = localPeer?.id === startedBy; const localPeerRoleName = useHMSStore(selectLocalPeerRoleName); const roleCanViewResponse = @@ -183,13 +190,19 @@ export const QuestionCard = ({ ) : null} {isLive && ( - + )} ); }; -const QuestionActions = ({ isValidVote, response, isQuiz, onVote }) => { +const QuestionActions = ({ isValidVote, response, isQuiz, onVote, disableVote }) => { return ( {response ? ( @@ -199,7 +212,7 @@ const QuestionActions = ({ isValidVote, response, isQuiz, onVote }) => { {!isQuiz && !response.skipped ? 'Voted' : null} ) : ( - )} From 3d09fe3d5c206fbc534a45fa9e8ea37bd2cd02df Mon Sep 17 00:00:00 2001 From: hdz-666 <93115614+hdz-666@users.noreply.github.com> Date: Mon, 9 Dec 2024 14:04:11 +0530 Subject: [PATCH 5/5] fix: add localstate handling for vote for polls and quiz on disconnect --- .../components/Polls/Voting/QuestionCard.jsx | 21 +++++++++--- .../Polls/Voting/StandardVoting.tsx | 3 ++ .../components/Polls/Voting/TimedVoting.tsx | 3 ++ .../components/Polls/Voting/Voting.tsx | 32 +++++++++++++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx index bbc1994d0b..0f43aa4f73 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/QuestionCard.jsx @@ -11,6 +11,7 @@ import { } from '@100mslive/react-sdk'; import { CheckCircleIcon, ChevronDownIcon, CrossCircleIcon } from '@100mslive/react-icons'; import { Box, Button, Flex, Text } from '../../../../'; +import { isNotNullish } from '../../../../Stats/Stats'; import { checkCorrectAnswer } from '../../../common/utils'; import { MultipleChoiceOptions } from '../common/MultipleChoiceOptions'; import { SingleChoiceOptions } from '../common/SingleChoiceOptions'; @@ -30,6 +31,7 @@ export const QuestionCard = ({ answer, localPeerResponse, updateSavedResponses, + updateUnsavedResponses, rolesThatCanViewResponses, }) => { const actions = useHMSActions(); @@ -55,7 +57,6 @@ export const QuestionCard = ({ const canRespond = isLive && !localPeerChoice; const startTime = useRef(Date.now()); const isCorrectAnswer = checkCorrectAnswer(answer, localPeerChoice, type); - const [singleOptionAnswer, setSingleOptionAnswer] = useState(); const [multipleOptionAnswer, setMultipleOptionAnswer] = useState(new Set()); const [showOptions, setShowOptions] = useState(true); @@ -80,7 +81,15 @@ export const QuestionCard = ({ options: Array.from(multipleOptionAnswer), duration: Date.now() - startTime.current, }; - await actions.interactivityCenter.addResponsesToPoll(pollID, [submittedResponse]); + if (roomState === HMSRoomState.Connected) { + await actions.interactivityCenter.addResponsesToPoll(pollID, [submittedResponse]); + } else { + updateUnsavedResponses(prev => { + const prevCopy = { ...prev }; + prevCopy[index] = { pollID: pollID, ...submittedResponse }; + return prevCopy; + }); + } updateSavedResponses(prev => { const prevCopy = { ...prev }; prevCopy[index] = { option: singleOptionAnswer, options: Array.from(multipleOptionAnswer) }; @@ -92,9 +101,11 @@ export const QuestionCard = ({ index, singleOptionAnswer, multipleOptionAnswer, + roomState, + updateSavedResponses, actions.interactivityCenter, pollID, - updateSavedResponses, + updateUnsavedResponses, ]); return ( @@ -191,7 +202,9 @@ export const QuestionCard = ({ {isLive && ( 0 + } isValidVote={isValidVote} onVote={handleVote} response={localPeerChoice} diff --git a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/StandardVoting.tsx b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/StandardVoting.tsx index 16a6ef2f46..676af59d2f 100644 --- a/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/StandardVoting.tsx +++ b/packages/roomkit-react/src/Prebuilt/components/Polls/Voting/StandardVoting.tsx @@ -8,10 +8,12 @@ export const StandardView = ({ poll, localPeerResponses, updateSavedResponses, + updateUnsavedResponses, }: { poll: HMSPoll; localPeerResponses: Record; updateSavedResponses: Dispatch>>; + updateUnsavedResponses: Dispatch>>; }) => { if (!poll?.questions) { return null; @@ -25,6 +27,7 @@ export const StandardView = ({ {isQuiz && isStopped ? : null} {poll.questions?.map((question, index) => ( ; updateSavedResponses: Dispatch>>; + updateUnsavedResponses: Dispatch>>; }) => { const [currentIndex, setCurrentIndex] = useState(getIndexToShow(localPeerResponses)); const activeQuestion = poll.questions?.find(question => question.index === currentIndex); @@ -32,6 +34,7 @@ export const TimedView = ({ {poll.questions.map(question => { return attemptedAll || activeQuestion?.index === question.index ? ( v const showSingleView = poll?.type === 'quiz' && poll.state === 'started'; const fetchedInitialResponses = useRef(false); const [savedResponses, setSavedResponses] = useState>({}); + const [unsavedResponses, setUnsavedResponses] = useState>({}); const localPeer = useHMSStore(selectLocalPeer); const localPeerId = localPeer?.id; const customerUserId = localPeer?.customerUserId; - + const roomState = useHMSStore(selectRoomState); // To reset whenever a different poll is opened useEffect(() => { fetchedInitialResponses.current = false; setSavedResponses({}); }, [id, setSavedResponses]); + // To send whenever room is connected back + useEffect(() => { + const handleDisconnectedVote = async () => { + if (unsavedResponses && Object.keys(unsavedResponses).length > 0 && roomState === HMSRoomState.Connected) { + for (const key in unsavedResponses) { + await actions.interactivityCenter.addResponsesToPoll(unsavedResponses[key].pollID, [unsavedResponses[key]]); + } + setUnsavedResponses({}); + } + }; + handleDisconnectedVote(); + }, [actions.interactivityCenter, roomState, setUnsavedResponses, unsavedResponses]); + useEffect(() => { const getResponses = async () => { if (poll && actions.interactivityCenter && !fetchedInitialResponses.current) { @@ -115,9 +131,19 @@ export const Voting = ({ id, toggleVoting }: { id: string; toggleVoting: () => v ) : null} {showSingleView ? ( - + ) : ( - + )}