import React, { useState, useEffect } from 'react' import VideoContainer from '../components/VideoContainer' import cn from 'classnames' import Counter from 'App/components/shared/SessionItem/Counter' import stl from './chatWindow.module.css' import ChatControls from '../ChatControls/ChatControls' import Draggable from 'react-draggable'; import type { LocalStream } from 'Player/MessageDistributor/managers/LocalStream'; export interface Props { incomeStream: MediaStream[] | null, localStream: LocalStream | null, userId: string, isPrestart?: boolean; endCall: () => void } function ChatWindow({ userId, incomeStream, localStream, endCall, isPrestart }: Props) { const [localVideoEnabled, setLocalVideoEnabled] = useState(false) const [remoteVideoEnabled, setRemoteVideoEnabled] = useState(false) useEffect(() => { if (!incomeStream || incomeStream.length === 0) { return } const iid = setInterval(() => { const settings = incomeStream.map(stream => stream.getVideoTracks()[0]?.getSettings()).filter(Boolean) const isDummyVideoTrack = settings.length > 0 ? (settings.every(s => s.width === 2 || s.frameRate === 0 || s.frameRate === undefined)) : true const shouldBeEnabled = !isDummyVideoTrack if (shouldBeEnabled !== localVideoEnabled) { setRemoteVideoEnabled(shouldBeEnabled) } }, 1000) return () => clearInterval(iid) }, [ incomeStream, localVideoEnabled ]) const minimize = !localVideoEnabled && !remoteVideoEnabled return (
Talking to {userId ? userId : 'Anonymous User'} {incomeStream && incomeStream.length > 2 ? ' (+ other agents in the call)' : ''}
{!incomeStream &&
Error obtaining incoming streams
} {incomeStream && incomeStream.map(stream => )}
) } export default ChatWindow