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

feat: add participant list #15

Merged
merged 3 commits into from
Apr 2, 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
2 changes: 1 addition & 1 deletion src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type TLine = {
name: string;
id: string;
smbid: string;
connections: unknown;
participants: { name: string; sessionid: string }[];
};

type TFetchProductionResponse = {
Expand Down
30 changes: 29 additions & 1 deletion src/components/production-line/production-line.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import styled from "@emotion/styled";
import { FC, useEffect, useRef } from "react";
import { FC, useEffect, useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import { useGlobalState } from "../../global-state/context-provider.tsx";
import { useAudioInput } from "./use-audio-input.ts";
import { useRtcConnection } from "./use-rtc-connection.ts";
import { useEstablishSession } from "./use-establish-session.ts";
import { ActionButton } from "../landing-page/form-elements.tsx";
import { useAudioElement } from "./use-audio-element.ts";
import { UserList } from "./user-list.tsx";
import { API } from "../../api/api.ts";
import { noop } from "../../helpers.ts";

const TempDiv = styled.div`
padding: 1rem;
Expand All @@ -16,6 +19,9 @@ export const ProductionLine: FC = () => {
const [{ joinProductionOptions }, dispatch] = useGlobalState();
const navigate = useNavigate();
const audioContainerRef = useRef<HTMLDivElement>(null);
const [participants, setParticipants] = useState<
{ name: string; sessionid: string }[] | null
>(null);

const { playbackState, audioElement } = useAudioElement({
audioContainerRef,
Expand All @@ -37,6 +43,26 @@ export const ProductionLine: FC = () => {
audioElement,
});

// Participant list, TODO extract hook to separate file
useEffect(() => {
if (!joinProductionOptions) return noop;

let interval: number | null = null;

const productionId = parseInt(joinProductionOptions.productionId, 10);
const lineId = parseInt(joinProductionOptions.lineId, 10);

interval = window.setInterval(() => {
API.fetchProductionLine(productionId, lineId)
.then((line) => setParticipants(line.participants))
.catch(console.error);
}, 1000);

return () => {
window.clearInterval(interval);
};
}, [joinProductionOptions]);

// TODO temporary, this view should handle direct links
useEffect(() => {
if (!joinProductionOptions) {
Expand Down Expand Up @@ -73,6 +99,8 @@ export const ProductionLine: FC = () => {
{connectionState && (
<TempDiv>RTC Connection State: {connectionState}</TempDiv>
)}

<UserList participants={participants} />
</div>
);
};
Expand Down
43 changes: 43 additions & 0 deletions src/components/production-line/user-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import styled from "@emotion/styled";
import { DisplayContainerHeader } from "../landing-page/display-container-header.tsx";

const ListWrapper = styled.div`
padding: 1rem;
`;

const User = styled.div`
margin: 0 0 1rem;
background: #1a1a1a;
padding: 1rem;
color: #ddd;
max-width: 32rem;
display: flex;
align-items: center;
`;

const GreenCircle = styled.div`
width: 1rem;
height: 1rem;
border-radius: 2rem;
display: inline-block;
background: #7be27b;
margin: 0 1rem 0 0;
`;

type TUserListOptions = {
participants: { name: string; sessionid: string }[] | null;
};
export const UserList = ({ participants }: TUserListOptions) => {
if (!participants) return null;

return (
<ListWrapper>
<DisplayContainerHeader>Participants</DisplayContainerHeader>
{participants.map((p) => (
<User key={p.sessionid}>
<GreenCircle /> <div>{p.name}</div>
</User>
))}
</ListWrapper>
);
};