-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added robot-to-operator audio streaming (#62)
- Loading branch information
1 parent
0dce880
commit 365fbb8
Showing
8 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
.audioControlContainer { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
text-align: center; | ||
} | ||
|
||
.audioControl { | ||
display: none; | ||
} | ||
|
||
.audioControlButton { | ||
border-radius: 50%; | ||
aspect-ratio: 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import "operator/css/AudioControl.css"; | ||
import { className, RemoteStream } from "shared/util"; | ||
import React from "react"; | ||
|
||
/**Props for {@link AudioControl} */ | ||
type AudioControlProps = { | ||
/** Remote robot video streams */ | ||
remoteStreams: Map<string, RemoteStream>; | ||
}; | ||
|
||
export const AudioControl = (props: AudioControlProps) => { | ||
// Create the audio element for listening to audio from the robot | ||
const audioRef = React.useRef<HTMLAudioElement>(null); | ||
|
||
// Keep track of whether the audio stream is muted or not. | ||
// NOTE: Audio must start muted for AutoPlay to work (see below) | ||
// https://developer.mozilla.org/en-US/docs/Web/Media/Autoplay_guide#autoplay_availability | ||
const [muted, setMuted] = React.useState(true); | ||
|
||
// Assign the source of the audio element to the audio stream from the robot | ||
const stream = React.useMemo(() => { | ||
if (props.remoteStreams.has("audio")) { | ||
return props.remoteStreams.get("audio")?.stream; | ||
} else { | ||
return null; | ||
} | ||
}, [props.remoteStreams]); | ||
React.useEffect(() => { | ||
if (!audioRef?.current) return; | ||
if (stream) { | ||
audioRef.current.srcObject = stream; | ||
} | ||
}, [audioRef.current, stream]); | ||
|
||
// Callback for when the user presses the button to toggle mute | ||
const toggleMute = React.useCallback(() => { | ||
setMuted((prev) => !prev); | ||
}, [setMuted]); | ||
|
||
return ( | ||
<div className="audioControlContainer"> | ||
<audio | ||
id="audio" | ||
ref={audioRef} | ||
className="audioControl" | ||
autoPlay | ||
muted={muted} | ||
> | ||
Robot audio playback is not supported on this browser | ||
</audio> | ||
<button className="button audioControlButton" onClick={toggleMute}> | ||
{muted ? ( | ||
<span className="material-icons">volume_off</span> | ||
) : ( | ||
<span className="material-icons">volume_up</span> | ||
)} | ||
</button> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
|
||
type AudioStreamProps = {}; | ||
|
||
export class AudioStream extends React.Component<AudioStreamProps> { | ||
outputAudioStream?: MediaStream; | ||
|
||
constructor(props: AudioStreamProps) { | ||
super(props); | ||
this.outputAudioStream = new MediaStream(); | ||
} | ||
|
||
async start() { | ||
this.outputAudioStream = await navigator.mediaDevices.getUserMedia({ | ||
audio: true, | ||
video: false, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters