From 5fe9dc191173a7f3e523fbeb0cf48b76fb4b97b3 Mon Sep 17 00:00:00 2001 From: Arnab Chatterjee Date: Tue, 3 Oct 2023 17:08:06 +0530 Subject: [PATCH] feat: added access control --- .../src/lib/space/acceptPromotionRequest.ts | 20 ++++++------- .../space/SpaceWidget/LiveWidgetContent.tsx | 28 +++++++++++++------ .../space/SpaceWidget/WidgetContent.tsx | 1 + packages/uiweb/src/lib/services/index.ts | 3 +- .../uiweb/src/lib/services/performAction.ts | 15 ++++++++++ 5 files changed, 47 insertions(+), 20 deletions(-) create mode 100644 packages/uiweb/src/lib/services/performAction.ts diff --git a/packages/restapi/src/lib/space/acceptPromotionRequest.ts b/packages/restapi/src/lib/space/acceptPromotionRequest.ts index 0a5ea4ea3..6ed125b25 100644 --- a/packages/restapi/src/lib/space/acceptPromotionRequest.ts +++ b/packages/restapi/src/lib/space/acceptPromotionRequest.ts @@ -36,14 +36,14 @@ export async function acceptPromotionRequest( }); // accept the promotion request - this.acceptRequest({ - signalData, - senderAddress: this.data.local.address, - recipientAddress: pCAIP10ToWallet(promoteeAddress), - chatId: spaceId, - details: { - type: SPACE_ACCEPT_REQUEST_TYPE.ACCEPT_PROMOTION, - data: {}, - }, - }); + // this.acceptRequest({ + // signalData, + // senderAddress: this.data.local.address, + // recipientAddress: pCAIP10ToWallet(promoteeAddress), + // chatId: spaceId, + // details: { + // type: SPACE_ACCEPT_REQUEST_TYPE.ACCEPT_PROMOTION, + // data: {}, + // }, + // }); } diff --git a/packages/uiweb/src/lib/components/space/SpaceWidget/LiveWidgetContent.tsx b/packages/uiweb/src/lib/components/space/SpaceWidget/LiveWidgetContent.tsx index 404ce6b53..a4b8fcf06 100644 --- a/packages/uiweb/src/lib/components/space/SpaceWidget/LiveWidgetContent.tsx +++ b/packages/uiweb/src/lib/components/space/SpaceWidget/LiveWidgetContent.tsx @@ -25,7 +25,7 @@ import MembersIcon from '../../../icons/Members.svg'; import { useSpaceData } from '../../../hooks'; import { SpaceStatus } from './WidgetContent'; import { pCAIP10ToWallet } from '../../../helpers'; -import { getLivekitRoomToken } from '../../../services'; +import { getLivekitRoomToken, performAction } from '../../../services'; import Microphone from './Microphone'; interface LiveWidgetContentProps { @@ -33,12 +33,14 @@ interface LiveWidgetContentProps { // temp props only for testing demo purpose for now isHost?: boolean; setSpaceStatusState: React.Dispatch>; + account: string | undefined; } export const LiveWidgetContent: React.FC = ({ spaceData, isHost, setSpaceStatusState, + account }) => { const [showMembersModal, setShowMembersModal] = useState(false); const [playBackUrl, setPlayBackUrl] = useState(''); @@ -72,11 +74,14 @@ export const LiveWidgetContent: React.FC = ({ useEffect(() => { (async function () { - if (isHost && spaceData?.spaceId) { - const livekitToken = await getLivekitRoomToken({ userType: "sender", roomId: spaceData?.spaceId }); + const removeEIP155 = (input: string) => input.substring(7); + const nonEIPAddress = removeEIP155(account as string); + + if ((isHost || isSpeaker) && spaceData?.spaceId) { + const livekitToken = await getLivekitRoomToken({ userType: "sender", roomId: spaceData?.spaceId, userId: nonEIPAddress }); setLivekitToken(livekitToken.data); } else if (isListener && spaceData?.spaceId) { - const livekitToken = await getLivekitRoomToken({ userType: "receiver", roomId: spaceData?.spaceId }); + const livekitToken = await getLivekitRoomToken({ userType: "receiver", roomId: spaceData?.spaceId, userId: nonEIPAddress }); setLivekitToken(livekitToken.data); } })(); @@ -102,11 +107,13 @@ export const LiveWidgetContent: React.FC = ({ }; useEffect(() => { - if (!spaceObjectData?.connectionData?.local?.stream || promotedListener.length === 0) + // if (!spaceObjectData?.connectionData?.local?.stream || promotedListener.length === 0) + // return; + if (promotedListener.length === 0) return; const options = { - signalData: raisedHandInfo[promotedListener].signalData, + // signalData: raisedHandInfo[promotedListener].signalData, promoteeAddress: pCAIP10ToWallet( raisedHandInfo[promotedListener].senderAddress ), @@ -121,14 +128,16 @@ export const LiveWidgetContent: React.FC = ({ }, [promotedListener]); const handleAcceptPromotion = async (requesterAddress: any) => { - await spacesObjectRef?.current?.createAudioStream?.(); + // await spacesObjectRef?.current?.createAudioStream?.(); setPromotedListener(requesterAddress); + await performAction({ roomId: spaceData?.spaceId, userId: requesterAddress, canPublish: true }); }; const handleRejectPromotion = async (requesterAddress: any) => { await spacesObjectRef?.current?.rejectPromotionRequest?.({ promoteeAddress: pCAIP10ToWallet(requesterAddress), }); + await performAction({ roomId: spaceData?.spaceId, userId: requesterAddress, canPublish: false }); }; const handleJoinSpace = async () => { @@ -367,9 +376,9 @@ export const LiveWidgetContent: React.FC = ({ token={livekitToken} room={livekitRoom} > - {/* */} - {isHost + + {isHost || isSpeaker ? @@ -381,6 +390,7 @@ export const LiveWidgetContent: React.FC = ({ alignItems={'center'} gap={'8px'} padding={'10px'} + onClick={() => handleRequest()} > = ({ spaceData={spaceData} isHost={isHost} setSpaceStatusState={setSpaceStatusState} + account={account} /> ) : spaceStatusState === SpaceStatus.Scheduled ? ( { + const url = `${LIVEKIT_TOKEN_GENERATOR_SERVER_URL}/execute?roomName=${roomId}&identity=${userId}&canPublish=${canPublish}`; + + return await axios.get(url); +}; \ No newline at end of file