From 3190924c1d82137ae76438c8ba4d390f2b642079 Mon Sep 17 00:00:00 2001 From: ShiKhu Date: Tue, 22 Jun 2021 01:33:22 +0200 Subject: [PATCH] wip (frontent): assist call functionality --- frontend/app/components/Assist/Assist.tsx | 47 +- .../Assist/ChatWindow/ChatWindow.tsx | 31 +- .../Assist/ChatWindow/{index.js => index.ts} | 0 .../Assist/ScreenSharing/ScreenSharing.tsx | 5 +- .../AssistActions/{index.js => index.ts} | 0 .../VideoContainer/VideoContainer.tsx | 17 +- .../VideoContainer/{index.js => index.ts} | 0 .../components/Assist/{index.js => index.ts} | 0 .../app/components/Session_/Player/Player.js | 2 +- .../MessageDistributor/MessageDistributor.js | 478 -------------- .../MessageDistributor/MessageDistributor.ts | 526 ++++++++++++++++ .../MessageDistributor/MessageGenerator.js | 82 --- .../MessageDistributor/MessageReader.ts | 80 +++ .../MessageDistributor/PrimitiveReader.ts | 36 ++ .../StatedScreen/Screen/screen.css | 1 + .../{StatedScreen.js => StatedScreen.ts} | 6 + .../StatedScreen/{index.js => index.ts} | 0 .../app/player/MessageDistributor/Timed.js | 5 - .../app/player/MessageDistributor/Timed.ts | 5 + .../managers/{ListWalker.js => ListWalker.ts} | 17 +- .../app/player/MessageDistributor/messages.js | 596 ------------------ .../app/player/MessageDistributor/messages.ts | 543 ++++++++++++++++ .../MessageDistributor/readPrimitives.js | 31 - frontend/app/player/{Player.js => Player.ts} | 32 +- frontend/app/player/singletone.js | 1 + frontend/package-lock.json | 50 ++ frontend/package.json | 1 + frontend/tsconfig.json | 6 +- 28 files changed, 1362 insertions(+), 1236 deletions(-) rename frontend/app/components/Assist/ChatWindow/{index.js => index.ts} (100%) rename frontend/app/components/Assist/components/AssistActions/{index.js => index.ts} (100%) rename frontend/app/components/Assist/components/VideoContainer/{index.js => index.ts} (100%) rename frontend/app/components/Assist/{index.js => index.ts} (100%) delete mode 100644 frontend/app/player/MessageDistributor/MessageDistributor.js create mode 100644 frontend/app/player/MessageDistributor/MessageDistributor.ts delete mode 100644 frontend/app/player/MessageDistributor/MessageGenerator.js create mode 100644 frontend/app/player/MessageDistributor/MessageReader.ts create mode 100644 frontend/app/player/MessageDistributor/PrimitiveReader.ts rename frontend/app/player/MessageDistributor/StatedScreen/{StatedScreen.js => StatedScreen.ts} (90%) rename frontend/app/player/MessageDistributor/StatedScreen/{index.js => index.ts} (100%) delete mode 100644 frontend/app/player/MessageDistributor/Timed.js create mode 100644 frontend/app/player/MessageDistributor/Timed.ts rename frontend/app/player/MessageDistributor/managers/{ListWalker.js => ListWalker.ts} (89%) delete mode 100644 frontend/app/player/MessageDistributor/messages.js create mode 100644 frontend/app/player/MessageDistributor/messages.ts delete mode 100644 frontend/app/player/MessageDistributor/readPrimitives.js rename frontend/app/player/{Player.js => Player.ts} (87%) diff --git a/frontend/app/components/Assist/Assist.tsx b/frontend/app/components/Assist/Assist.tsx index 9c8156631..0140fcdd0 100644 --- a/frontend/app/components/Assist/Assist.tsx +++ b/frontend/app/components/Assist/Assist.tsx @@ -1,14 +1,49 @@ -import React from 'react' +import React, { useEffect, useRef } from 'react'; +import { connect } from 'react-redux'; +import { findDOMNode } from 'react-dom'; +import { + PlayerProvider, + attach as attachPlayer, + init as initPlayer, + clean as cleanPlayer, + callPeer, + // scale +} from 'App/player'; import ChatWindow from './ChatWindow/ChatWindow' -import ScreenSharing from './ScreenSharing/ScreenSharing' +//import ScreenSharing from './ScreenSharing/ScreenSharing' -function Assist() { +function Assist({ session, jwt }) { + const screeRef = useRef(null); + useEffect(() => { + initPlayer(session, jwt); + return () => cleanPlayer() + }, [ session.sessionId ]); + useEffect(() => { + if (screeRef.current) { + attachPlayer(findDOMNode(screeRef.current)); + + } + }, [ ]) return ( -
- +
+
+ {/* */}
) } -export default Assist +export default connect(state => ({ + session: { // Testing mock. Should be retrieved from redux + startedAt: 1624314191394, + live: true, + sessionId: "4870254843916045", + }, + jwt: state.get('jwt'), +}))(Assist); diff --git a/frontend/app/components/Assist/ChatWindow/ChatWindow.tsx b/frontend/app/components/Assist/ChatWindow/ChatWindow.tsx index b142cd3a2..e6bcc001a 100644 --- a/frontend/app/components/Assist/ChatWindow/ChatWindow.tsx +++ b/frontend/app/components/Assist/ChatWindow/ChatWindow.tsx @@ -1,14 +1,35 @@ -import React from 'react' -import VideoContainer from '../components/VideoContainer/VideoContainer' +import React, { useState } from 'react'; +import { IconButton } from 'UI'; +import VideoContainer from '../components/VideoContainer'; // import stl from './chatWindow.css'; -function ChatWindow() { + +interface Props { + call: (oStream: MediaStream, cb: (iStream: MediaStream)=>void)=>void +} + +function ChatWindow({ call }: Props) { + const [ inputStream, setInputStream ] = useState(null); + const [ outputStream, setOutputStream ] = useState(null); + + const onCallClick = () => { + navigator.mediaDevices.getUserMedia({video:true, audio:true}) + .then(oStream => { + setOutputStream(oStream); + call(oStream, setInputStream); // Returns false when unable to connect. + // TODO: handle calling state + }) + .catch(console.log) // TODO: handle error in ui + } return (
- +
- + +
+ +
) diff --git a/frontend/app/components/Assist/ChatWindow/index.js b/frontend/app/components/Assist/ChatWindow/index.ts similarity index 100% rename from frontend/app/components/Assist/ChatWindow/index.js rename to frontend/app/components/Assist/ChatWindow/index.ts diff --git a/frontend/app/components/Assist/ScreenSharing/ScreenSharing.tsx b/frontend/app/components/Assist/ScreenSharing/ScreenSharing.tsx index 767b388e7..35d67f91b 100644 --- a/frontend/app/components/Assist/ScreenSharing/ScreenSharing.tsx +++ b/frontend/app/components/Assist/ScreenSharing/ScreenSharing.tsx @@ -2,12 +2,11 @@ import React from 'react' import { Button } from 'UI' function ScreenSharing() { - const videoRef: React.RefObject = React.createRef() + const videoRef = React.createRef() function handleSuccess(stream) { // startButton.disabled = true; - // @ts-ignore - videoRef.current.srcObject = stream; + //videoRef.current?.srcObject = stream; // @ts-ignore window.stream = stream; // make variable available to browser console diff --git a/frontend/app/components/Assist/components/AssistActions/index.js b/frontend/app/components/Assist/components/AssistActions/index.ts similarity index 100% rename from frontend/app/components/Assist/components/AssistActions/index.js rename to frontend/app/components/Assist/components/AssistActions/index.ts diff --git a/frontend/app/components/Assist/components/VideoContainer/VideoContainer.tsx b/frontend/app/components/Assist/components/VideoContainer/VideoContainer.tsx index cab7d5af4..b03702fe4 100644 --- a/frontend/app/components/Assist/components/VideoContainer/VideoContainer.tsx +++ b/frontend/app/components/Assist/components/VideoContainer/VideoContainer.tsx @@ -1,13 +1,22 @@ -import React, { useEffect } from 'react' +import React, { useEffect, useRef } from 'react' import { Button, Icon } from 'UI' -function VideoContainer() { +interface Props { + stream: MediaProvider | null + muted?: boolean +} + +function VideoContainer({ stream, muted = false }: Props) { + const ref = useRef(null); useEffect(() => { - // TODO check for video stream and display - }, []) + if (ref.current) { + ref.current.srcObject = stream; + } + }, [ ref.current, stream ]) return (
+