Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/chat/video/launch-button.tsx
Views: 687
import { Button, Popover } from "antd";1import { debounce } from "lodash";2import type { CSSProperties, ReactNode } from "react";3import { useMemo } from "react";4import { useInterval } from "react-interval-hook";5import type { ChatActions } from "../actions";6import { React, useState, useTypedRedux } from "@cocalc/frontend/app-framework";7import { Icon } from "@cocalc/frontend/components";89const VIDEO_UPDATE_INTERVAL_MS = 30 * 1000;10// jit.si doesn't seem to have a limit...?11const VIDEO_CHAT_LIMIT = 99999;1213interface Props {14actions: ChatActions;15style?: CSSProperties;16label?: ReactNode;17}1819export default function VideoChatButton({20actions,21style: style0,22label,23}: Props) {24// to know if somebody else has video chat opened for this file25// @ts-ignore26const file_use = useTypedRedux("file_use", "file_use");2728const [counter, set_counter] = useState<number>(0); // to force updates periodically.29useInterval(() => set_counter(counter + 1), VIDEO_UPDATE_INTERVAL_MS / 2);30const videoChat = useMemo(31() => actions.frameTreeActions?.getVideoChat(),32[actions],33);3435if (videoChat == null) {36// eg sage worksheets...37return null;38}3940const click_video_button = debounce(41() => {42if (videoChat.weAreChatting()) {43// we are chatting, so stop chatting44videoChat.stopChatting();45} else {46videoChat.startChatting(); // not chatting, so start47actions.sendChat({48input: `${49videoChat.getUserName() ?? "User"50} joined [the video chat](${videoChat.url()}).`,51});52}53},54750,55{ leading: true },56);5758function render_num_chatting(59num_users_chatting: number,60): JSX.Element | undefined {61if (num_users_chatting > 0) {62return (63<span>64<hr />65There following {num_users_chatting} people are using video chat:66<br />67{videoChat?.getUserNames().join(", ")}68</span>69);70}71}7273function render_join(num_users_chatting: number): JSX.Element {74if (videoChat?.weAreChatting()) {75return (76<span>77<b>Leave</b> this video chatroom.78</span>79);80} else {81if (num_users_chatting < VIDEO_CHAT_LIMIT) {82return (83<span>84{num_users_chatting == 0 ? "Start a new " : "Join the current"}{" "}85video chat.86</span>87);88} else {89return (90<span>91At most {VIDEO_CHAT_LIMIT} people can use the video chat at once.92</span>93);94}95}96}9798const num_users_chatting: number = videoChat?.numUsersChatting() ?? 0;99const style: React.CSSProperties = { cursor: "pointer" };100if (num_users_chatting > 0) {101style.color = "#c9302c";102}103104const body = (105<>106<Icon name="video-camera" />107{num_users_chatting > 0 && (108<span style={{ marginLeft: "5px" }}>{num_users_chatting}</span>109)}110<span style={{ marginLeft: "5px" }}>{label ?? "Video Chat"}</span>111</>112);113114const btn = (115<Button onClick={click_video_button} style={{ ...style, ...style0 }}>116{body}117</Button>118);119120return (121<Popover122mouseEnterDelay={0.8}123title={() => (124<span>125{render_join(num_users_chatting)}126{render_num_chatting(num_users_chatting)}127</span>128)}129>130{btn}131</Popover>132);133}134135136