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(luna): improved the call object and implement the todos #215

Merged
merged 4 commits into from
Dec 23, 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
9 changes: 9 additions & 0 deletions packages/assets/assets/minimize.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions packages/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"./EmptyLesson2": "./dist/EmptyLesson2.tsx",
"./EmptyLessons": "./dist/EmptyLessons.tsx",
"./EmptyUpcomingLessons": "./dist/EmptyUpcomingLessons.tsx",
"./EndCall": "./dist/EndCall.tsx",
"./Error": "./dist/Error.tsx",
"./ExclaimationMarkCircle": "./dist/ExclaimationMarkCircle.tsx",
"./ExclamationMark": "./dist/ExclamationMark.tsx",
Expand Down Expand Up @@ -88,6 +89,7 @@
"./RegisterLight": "./dist/RegisterLight.tsx",
"./RightArrowHead": "./dist/RightArrowHead.tsx",
"./SStar": "./dist/SStar.tsx",
"./Save": "./dist/Save.tsx",
"./Search": "./dist/Search.tsx",
"./Send": "./dist/Send.tsx",
"./SettingsScrew": "./dist/SettingsScrew.tsx",
Expand Down
1 change: 1 addition & 0 deletions packages/luna/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"./Loading": "./dist/components/Loading/index.js",
"./Lessons": "./dist/components/Lessons/index.js",
"./Menu": "./dist/components/Menu/index.js",
"./MovableMedia": "./dist/components/MovableMedia/index.js",
"./MultiSelect": "./dist/components/MultiSelect/index.js",
"./Navbar": "./dist/components/Navbar/index.js",
"./NumericInput": "./dist/components/NumericInput/index.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import React from "react";
import cn from "classnames";
import ExclamationMark from "@litespace/assets/ExclamationMark";
import { useFormatMessage } from "@/hooks";
import { Typography } from "@/components/Typography";

export const InternetIndicator: React.FC = () => {
const intl = useFormatMessage();
export const CallAlert: React.FC<{ alert: string }> = ({ alert }) => {
return (
<div className="tw-flex tw-items-center tw-justify-center tw-gap-2">
<div
Expand All @@ -21,7 +19,7 @@ export const InternetIndicator: React.FC = () => {
"tw-rounded-full tw-flex tw-items-center tw-justify-center tw-text-natural-50 tw-font-bold tw-h-16 tw-backdrop-blur-[15px] tw-p-4 tw-bg-background-internet"
)}
>
{intl("call.internet.problem")}
{alert}
</Typography>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion packages/luna/src/components/Call/CallBar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Void } from "@litespace/types";
import React from "react";
import { ToggleCallButton, EndCallButton } from "@/components/Call";
import { EndCallButton } from "@/components/Call/EndCallButton";
import { ToggleCallButton } from "@/components/Call/ToggleCallButton";

export const CallBar: React.FC<{
items: {
Expand Down
69 changes: 38 additions & 31 deletions packages/luna/src/components/Call/FocusedStream.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import React, { useEffect, useRef } from "react";
import { motion } from "framer-motion";
import { VideoBar, CallAvatar } from "@/components/Call";
import { VideoBar } from "@/components/Call/VideoBar";
import { CallAvatar } from "@/components/Call/CallAvatar";
import { StreamInfo } from "@/components/Call/types";
import { Void } from "@litespace/types";
import cn from "classnames";

export const FocusedStream: React.FC<{
internetProblem?: boolean;
alert?: string;
streamMuted: boolean;
stream: StreamInfo;
timer: {
duration: number;
Expand All @@ -14,7 +18,7 @@ export const FocusedStream: React.FC<{
enabled: boolean;
toggle: Void;
};
}> = ({ stream, timer, internetProblem, fullScreen }) => {
}> = ({ stream, timer, alert, fullScreen, streamMuted }) => {
const videoRef = useRef<HTMLVideoElement | null>(null);

useEffect(() => {
Expand All @@ -24,48 +28,51 @@ export const FocusedStream: React.FC<{
}, [stream.stream]);

return (
<motion.div
initial={{
opacity: 0,
scale: 0,
}}
animate={{
scale: 1,
opacity: 1,
}}
transition={{
duration: 0.5,
ease: "easeInOut",
}}
key={stream.user.id}
className="tw-aspect-video tw-relative tw-w-full tw-h-full tw-grow tw-rounded-lg tw-overflow-hidden"
>
{/* todo: keep the video ref alwayas accessable */}
{stream.camera || stream.cast ? (
<div className="tw-grow tw-rounded-lg tw-overflow-hidden">
<motion.div
initial={{
opacity: 0,
scale: 0,
}}
animate={{
scale: 1,
opacity: 1,
}}
transition={{
duration: 0.5,
ease: "easeInOut",
}}
key={stream.user.id}
className="tw-aspect-video tw-relative tw-w-full tw-h-full tw-grow tw-rounded-lg tw-overflow-hidden"
>
<video
ref={videoRef}
autoPlay
className="tw-w-full tw-aspect-video"
muted={false}
className={cn(
"tw-w-full tw-aspect-video tw-absolute tw-top-0",
!stream.stream || (!stream.camera && !stream.cast && "tw-opacity-0")
)}
muted={streamMuted}
playsInline
/>
) : (
<div className="tw-w-full tw-h-full tw-bg-brand-100 tw-flex tw-items-center tw-justify-center">
<div
className={cn(
"tw-w-full tw-h-full tw-bg-brand-100 tw-flex tw-items-center tw-justify-center",
(stream.camera || stream.cast) && "tw-opacity-0"
)}
>
<CallAvatar user={stream.user} speaking={stream.speaking} />
</div>
)}
</motion.div>

{/*
* TODO: animate by using opacities not the movement
*/}
<VideoBar
internetProblem={internetProblem}
alert={alert}
timer={timer}
fullScreen={fullScreen}
speaking={stream.speaking}
muted={stream.muted}
/>
</motion.div>
</div>
);
};

Expand Down
7 changes: 5 additions & 2 deletions packages/luna/src/components/Call/FullScreenButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from "react";
import FullScreen from "@litespace/assets/FullScreen";
import Minimize from "@litespace/assets/Minimize";
import { Void } from "@litespace/types";

export const FullScreenButton: React.FC<{ enabled: boolean; toggle: Void }> = ({
Expand All @@ -11,8 +12,10 @@ export const FullScreenButton: React.FC<{ enabled: boolean; toggle: Void }> = ({
className="tw-rounded-full tw-cursor-pointer tw-flex tw-justify-center tw-items-center tw-w-16 tw-h-16 tw-backdrop-blur-[15px] tw-p-4 tw-bg-brand-700"
onClick={toggle}
>
{enabled ? null : (
<FullScreen className="[&>*]:tw-stroke-natural-50 tw-cursor-pointer" />
{enabled ? (
<Minimize className="[&>*]:tw-stroke-natural-50" />
) : (
<FullScreen className="[&>*]:tw-stroke-natural-50" />
)}
</button>
);
Expand Down
25 changes: 9 additions & 16 deletions packages/luna/src/components/Call/InCall/Call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@ import Microphone from "@litespace/assets/Microphone";
import MicrophoneSlash from "@litespace/assets/MicrophoneSlash";
import Chat from "@litespace/assets/Chat";
import CastScreen from "@litespace/assets/CastScreen";
import { InCallStreams, CallBar } from "@/components/Call";
import { CallBar } from "@/components/Call/CallBar";
import { InCallStreams } from "@/components/Call/InCallStreams";
import { StreamInfo } from "@/components/Call/types";

/**
* @todo should accept list of streams
* - user alone => should be the main stream
* - two users => the other user is the focused stream.
* - two users with cast => cast is the focused stream.
* - one user with casting => cast is the focused stream.
* - two users with two streams => the other user cast should be focused.
*/
type Props = {
streams: {
focused: StreamInfo;
unfocused: StreamInfo[];
};
streams: StreamInfo[];
currentUserId: number;
chat: { enabled: boolean; toggle: Void };
fullScreen: {
enabled: boolean;
Expand All @@ -48,7 +39,7 @@ type Props = {
};
leaveCall: Void;
chatPanel?: React.ReactNode;
internetProblem?: boolean;
alert?: string;
Copy link
Member

Choose a reason for hiding this comment

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

Nice name!

};

export const Call: React.FC<Props> = ({
Expand All @@ -60,18 +51,20 @@ export const Call: React.FC<Props> = ({
cast,
streams,
timer,
internetProblem,
alert,
fullScreen,
currentUserId,
}) => {
return (
<div className="tw-flex tw-flex-col tw-gap-10 tw-w-full tw-h-full">
<div className="tw-h-full tw-grow tw-flex">
<InCallStreams
currentUserId={currentUserId}
fullScreen={fullScreen}
streams={streams}
chat={chat.enabled}
timer={timer}
internetProblem={internetProblem}
alert={alert}
/>
{chat.enabled ? chatPanel : null}
</div>
Expand Down
Loading
Loading