diff --git a/app/components/dashboard.js b/app/components/dashboard.js index 425c63ea..ff6d839f 100644 --- a/app/components/dashboard.js +++ b/app/components/dashboard.js @@ -1,104 +1,17 @@ import { Mulberry32 } from "../utils.js"; import React, { useState, useEffect } from "react"; -export function Dashboard(props) { +export function Dashboard({ + isRecording, + onRecord, + transcriptionText, + finalSummary, + topics, + stream, +}) { const [openIndex, setOpenIndex] = useState(null); const [liveTranscript, setLiveTranscript] = useState(""); - const fakeTranscripts = [ - "This is the first transcript. We are discussing the current situation of our company. We are currently leading the market with a significant margin, and our future outlook is also very promising...", - "Here is the second transcript. We are now moving to our next topic, which is the progress in our ongoing projects. Most of them are on schedule and the quality of work is up to our standard...", - "This is the third transcript. It's about the financial status of our company. We are doing quite well financially. The revenue for this quarter is higher than expected...", - // add more fake transcripts as needed - ]; - - useEffect(() => { - // Randomly select a fake transcript - const selectedTranscript = - fakeTranscripts[Math.floor(Math.random() * fakeTranscripts.length)]; - // Split the selected transcript into characters - const characters = Array.from(selectedTranscript); - - let counter = 0; - let liveTranscriptCopy = ""; - let intervalId = setInterval(() => { - if (counter < characters.length) { - liveTranscriptCopy += characters[counter]; - setLiveTranscript(liveTranscriptCopy); - counter++; - } else { - clearInterval(intervalId); - } - }, 50); // delay of 100ms - - // Cleanup function to clear the interval when the component unmounts - return () => clearInterval(intervalId); - }, []); - - const generateDecibelData = (x) => { - let data = []; - let random = Mulberry32(123456789 + x); - for (let i = 0; i < 50; i++) { - data.push(Math.floor(random() * 30) + 10); // generate random values between 10 and 40 - } - return data; - }; - const generateDecibelGraph = (decibelData) => { - return decibelData.map((decibel, i) => ( -
-   -
- )); - }; - - // This is hardcoded data for proof of concept - const data = [ - { - timestamp: "00:00", - topic: "Meeting Introduction", - decibel: generateDecibelData(1), - transcript: - "This is the meeting introduction, we will be discussing several important topics today.", - }, - { - timestamp: "00:48", - topic: "Discussing Quarterly Revenue", - decibel: generateDecibelData(2), - transcript: - "We are discussing the quarterly revenue here, it appears our revenue has grown by 15% compared to the previous quarter.", - }, - { - timestamp: "01:35", - topic: "Annual Sales Review", - decibel: generateDecibelData(3), - transcript: - "Now we're reviewing the annual sales, there was a significant boost during the holiday season.", - }, - { - timestamp: "02:20", - topic: "Operational Costs Analysis", - decibel: generateDecibelData(4), - transcript: - "Moving on to the operational costs analysis, we have managed to reduce unnecessary expenses.", - }, - { - timestamp: "03:10", - topic: "Employee Performance", - decibel: generateDecibelData(5), - transcript: - "Let's talk about the employee performance, overall the team has done a great job.", - }, - /* { timestamp: '03:45', topic: 'New Marketing Strategies', decibel: generateDecibelData(6), transcript: "Our marketing team has proposed some new strategies that we'll discuss now." }, - { timestamp: '04:30', topic: 'Customer Feedback', decibel: generateDecibelData(7), transcript: "Let's go through some customer feedback that we've received." }, - { timestamp: '05:15', topic: 'Product Development', decibel: generateDecibelData(8), transcript: "Product development is going well and the new product line will be ready to launch next quarter." }, - { timestamp: '06:00', topic: 'Discussing Future Projects', decibel: generateDecibelData(9), transcript: "Now we are talking about the future projects, we have some exciting projects lined up." }, - { timestamp: '06:45', topic: 'Meeting Conclusion', decibel: generateDecibelData(10), transcript: "As we conclude the meeting, I want to thank everyone for their hard work and dedication." }, */ - ]; - return ( <>
@@ -107,7 +20,8 @@ export function Dashboard(props) {
Topic
- {data.map((item, index) => ( + + {topics.map((item, index) => (
{item.timestamp}
- {item.topic}{" "} + {item.title}{" "}
- {generateDecibelGraph(item.decibel)}
{openIndex === index && ( @@ -133,17 +46,27 @@ export function Dashboard(props) { )}
))} +
Live
Transcript
- {generateDecibelGraph(generateDecibelData())}
-
{props.transcriptionText}
+
+ {transcriptionText} +
+ {finalSummary && ( +
+

Final Summary

+

Duration: {finalSummary.duration}

+

{finalSummary.summary}

+
+ )} + ); diff --git a/app/components/webrtc.js b/app/components/webrtc.js index f13e8356..927b8a95 100644 --- a/app/components/webrtc.js +++ b/app/components/webrtc.js @@ -3,16 +3,19 @@ import Peer from "simple-peer"; const WebRTC_SERVER_URL = "http://127.0.0.1:1250/offer"; -const useWebRTC = (stream) => { - const [data, setData] = useState(null); +const useWebRTC = (stream, setIsRecording) => { + const [data, setData] = useState({ + peer: null, + }); useEffect(() => { + if (!stream) { + return; + } + let peer = new Peer({ initiator: true, stream: stream }); peer.on("signal", (data) => { - // This is where you'd send the signal data to the server. - // The server would then send it back to other peers who would then - // use `peer.signal()` method to continue the connection negotiation. if ("sdp" in data) { fetch(WebRTC_SERVER_URL, { body: JSON.stringify({ @@ -24,13 +27,9 @@ const useWebRTC = (stream) => { }, method: "POST", }) - .then(function (response) { - return response.json(); - }) - .then(function (answer) { - return peer.signal(answer); - }) - .catch(function (e) { + .then((response) => response.json()) + .then((answer) => peer.signal(answer)) + .catch((e) => { alert(e); }); } @@ -38,20 +37,45 @@ const useWebRTC = (stream) => { peer.on("connect", () => { console.log("WebRTC connected"); + setData(prevData => ({ ...prevData, peer: peer })); }); peer.on("data", (data) => { - // Received data from the server. - console.log(data.toString()); const serverData = JSON.parse(data.toString()); - setData(serverData); + console.log(serverData); + + switch (serverData.cmd) { + case "SHOW_TRANSCRIPTION": + setData((prevData) => ({ + ...prevData, + text: serverData.text, + })); + break; + case "UPDATE_TOPICS": + setData((prevData) => ({ + ...prevData, + topics: serverData.topics, + })); + break; + case "DISPLAY_FINAL_SUMMARY": + setData((prevData) => ({ + ...prevData, + finalSummary: { + duration: serverData.duration, + summary: serverData.summary, + }, + })); + setIsRecording(false); + break; + default: + console.error(`Unknown command ${serverData.cmd}`); + } }); - // Clean up return () => { peer.destroy(); }; - }, [stream]); + }, [stream, setIsRecording]); return data; }; diff --git a/app/globals.css b/app/globals.scss similarity index 90% rename from app/globals.css rename to app/globals.scss index a4532f27..a1c78d64 100644 --- a/app/globals.css +++ b/app/globals.scss @@ -17,7 +17,6 @@ } body { - color: rgb(var(--foreground-rgb)); background: linear-gradient( to bottom, transparent, @@ -28,8 +27,7 @@ body { font-family: "Roboto", sans-serif; } -.temp-transcription -{ +.temp-transcription { background: beige; border-radius: 5px; } diff --git a/app/layout.js b/app/layout.js index df1a0ac7..0e91a9e4 100644 --- a/app/layout.js +++ b/app/layout.js @@ -1,4 +1,4 @@ -import "./globals.css"; +import "./globals.scss"; import { Roboto } from "next/font/google"; import Head from "next/head"; diff --git a/app/page.js b/app/page.js index 393b8fd2..2a21c9a7 100644 --- a/app/page.js +++ b/app/page.js @@ -10,7 +10,7 @@ const App = () => { // This is where you'd send the stream and receive the data from the server. // transcription, summary, etc - const serverData = useWebRTC(stream); + const serverData = useWebRTC(stream, () => {}); const text = serverData?.text ?? ""; return ( @@ -20,10 +20,12 @@ const App = () => {

Capture The Signal, Not The Noise

- + serverData.peer.send(JSON.stringify({ cmd: 'STOP' }))}/>