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

Fix knock state error #61

Merged
merged 2 commits into from
Sep 1, 2023
Merged

Conversation

nandito
Copy link
Collaborator

@nandito nandito commented Aug 30, 2023

Only apply knock_handled event status changes when the event id matches the local client's id (selfId). This should prevent kicking other participants (incl. the host) when a knock is rejected.

Should fix #55

Test plan

  1. Use the app from issue BUG Rejecting a Participant results in the Host's roomConnectionStatus getting updated to rejected as well #55 or the example below
  2. Join the room with a host
  3. Join the room with 1,2,n not-hosts
  4. Apply/reject knockers: the applied should join room, the rejected should see the "rejected" screen.

Example app

import React, { useState } from "react";
import { useRoomConnection, VideoView } from "@whereby.com/browser-sdk";

const WaitingArea = ({ knock }) => {
    return (
        <div>
            <h1>Waiting Area</h1>
            <p>Waiting for host to let you in</p>
            <button onClick={knock}>Knock</button>
        </div>
    );
};

const Room = ({ roomUrl, localMedia, displayName, isHost }) => {
    const roomConnection = useRoomConnection(roomUrl, {
        localMedia: null,
        localMediaConstraints: localMedia,
        displayName,
        logger: console,
    });

    const {
        waitingParticipants,
        remoteParticipants,
        localParticipant,
        isJoining,
        roomConnectionStatus,
        chatMessages,
        mostRecentChatMessage,
    } = roomConnection.state;
    const {
        acceptWaitingParticipant,
        knock,
        rejectWaitingParticipant,
        sendChatMessage,
        toggleCamera,
    } = roomConnection.actions;

    if (roomConnectionStatus === "room_locked") {
        return <WaitingArea knock={knock} />;
    }

    if (roomConnectionStatus === "rejected") {
        return <p>You have been rejected access</p>;
    }

    return (
        <div>
            <h1>Room - {roomConnectionStatus}</h1>
            {isHost && (
                <div>
                    <h3>Participants in Waiting Area</h3>
                    {waitingParticipants.length > 0 ? (
                        <ul>
                            {waitingParticipants.map((a) => (
                                <li key={a.id}>
                                    <p>{a.displayName}</p>
                                    <button
                                        onClick={() =>
                                            acceptWaitingParticipant(a.id)
                                        }
                                    >
                                        Approve
                                    </button>
                                    <button
                                        onClick={() =>
                                            rejectWaitingParticipant(a.id)
                                        }
                                    >
                                        Reject
                                    </button>
                                </li>
                            ))}
                        </ul>
                    ) : (
                        <p>No participants in waiting area</p>
                    )}
                </div>
            )}
            <h3>Participants</h3>
            <div>
                {remoteParticipants.map((r) => (
                    <div key={r.id}>
                        <VideoView
                            style={{ width: "300px" }}
                            stream={r.stream}
                        />
                        <p>{r.displayName}</p>
                    </div>
                ))}
            </div>
            <hr />
            {localParticipant && (
                <div>
                    <VideoView
                        style={{ width: "200px" }}
                        stream={localParticipant.stream}
                    />
                    <p>{localParticipant.displayName}</p>
                </div>
            )}
        </div>
    );
};

const App = () => {
    const roomUrl = "<your-room-url>";
    const roomKey =  "<host-room-key>";
    const [isHost, setIsHost] = useState(null);

    if (isHost === null) {
        return (
            <div>
                <h1>Are you the host?</h1>
                <button onClick={() => setIsHost(true)}>Yes</button>
                <button onClick={() => setIsHost(false)}>No</button>
            </div>
        );
    }

    return (
        <div>
            <Room
                roomUrl={`${roomUrl}${isHost ? `?roomKey=${roomKey}` : ""}`}
                localMedia={{ audio: false, video: true }}
                displayName={`John Doe${isHost ? " (host)" : ""}`}
                isHost={isHost}
            />
        </div>
    );
};

export default App;

@nandito nandito self-assigned this Aug 30, 2023
@nandito nandito force-pushed the nandor/pan-238-fix-knock-state-error branch 2 times, most recently from a73825d to 848a12e Compare August 30, 2023 13:21
Copy link
Collaborator

@havardholvik havardholvik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected 👍 Remember to bump version, as alpha13 is already deployed

Only apply knock_handled event status changes when the event id matches
the local client's id (selfId). This should prevent kicking other
participants (incl. the host) when a knock is rejected.
@nandito nandito force-pushed the nandor/pan-238-fix-knock-state-error branch from 848a12e to c225e45 Compare September 1, 2023 07:20
@nandito nandito merged commit 98d8cca into development Sep 1, 2023
1 check passed
@nandito nandito deleted the nandor/pan-238-fix-knock-state-error branch September 1, 2023 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants