Skip to content

Commit

Permalink
fix: Dockerfile and tyescript error
Browse files Browse the repository at this point in the history
  • Loading branch information
mathias committed May 23, 2024
1 parent e82d4a7 commit 7a46241
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 36 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Start with a base image containing Node.js runtime
FROM node:lts-alpine as build-stage

ARG VITE_API_ENDPOINT
ENV VITE_API_ENDPOINT $VITE_API_ENDPOINT

# Set the working directory in the container to /app
WORKDIR /app

Expand Down
71 changes: 35 additions & 36 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function App() {
const [micDisabled, setMicDisabled] = useState(true)
const [iceStatus, setIceStatus] = useState('Waiting')
const [chanStatus, setChanStatus] = useState('Click Join Button...')
const [speaking, setSpeaking] = useState(false)
// const [speaking, setSpeaking] = useState(false)
// const [media, setMedia] = useState(new Array<element>())

const [micInputList, setMicInputList] = useState(new Array<MediaDeviceInfo>())
Expand Down Expand Up @@ -114,37 +114,36 @@ function App() {
console.log('onOpenCallback', onOpenCallback)
}

const checkSpeaking = (source: MediaStream, threshold: number) => {
const audioContext = new AudioContext()
const analyser = audioContext.createAnalyser()
const microphone = audioContext.createMediaStreamSource(source)
const javascriptNode = audioContext.createScriptProcessor(2048, 1, 1)

analyser.smoothingTimeConstant = 0.8
analyser.fftSize = 1024

microphone.connect(analyser)
analyser.connect(javascriptNode)
javascriptNode.connect(audioContext.destination)

javascriptNode.onaudioprocess = () => {
const array = new Uint8Array(analyser.frequencyBinCount)
analyser.getByteFrequencyData(array)
let values = 0

const length = array.length
for (let i = 0; i < length; i++) {
values += array[i]
}

const average = values / length
if (average > threshold) {
setSpeaking(true)
} else {
setSpeaking(false)
}
}
}
// const checkSpeaking = (source: MediaStream, threshold: number) => {
// const audioContext = new AudioContext()
// const analyser = audioContext.createAnalyser()
// const microphone = audioContext.createMediaStreamSource(source)
//
// analyser.smoothingTimeConstant = 0.8
// analyser.fftSize = 1024
//
// microphone.connect(analyser)
// analyser.connect(javascriptNode)
// javascriptNode.connect(audioContext.destination)
//
// javascriptNode.onaudioprocess = () => {
// const array = new Uint8Array(analyser.frequencyBinCount)
// analyser.getByteFrequencyData(array)
// let values = 0
//
// const length = array.length
// for (let i = 0; i < length; i++) {
// values += array[i]
// }
//
// const average = values / length
// if (average > threshold) {
// setSpeaking(true)
// } else {
// setSpeaking(false)
// }
// }
// }

const onTrackCallback = (e: RTCTrackEvent) => {
// console.log('ontrack', e.track);
Expand Down Expand Up @@ -201,7 +200,7 @@ function App() {
media.addTrack(track)
el.srcObject = media
if (track.kind === 'audio') {
checkSpeaking(media, 30)
// checkSpeaking(media, 30)
el.hidden = true
}
el.onloadedmetadata = () => console.log('unmuted workaround!')
Expand Down Expand Up @@ -255,8 +254,8 @@ function App() {
setCamDisabled(true)
streamCam.current = await navigator.mediaDevices.getUserMedia({
video: {
width: 640,
height: 360,
width: 480,
height: 270,
deviceId: selectedCam,
},
})
Expand Down Expand Up @@ -416,7 +415,7 @@ function App() {
Status: <span id="ice_status">{iceStatus}</span>
<div id="chan_status">{chanStatus}</div>
<div id="media"></div>
<p>{speaking ? 'Speaking' : 'Silent'}</p>
{/*<p>{speaking ? 'Speaking' : 'Silent'}</p>*/}
</div>
)
}
Expand Down

0 comments on commit 7a46241

Please sign in to comment.