File size: 740 Bytes
2f49513
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: BSD 2-Clause License

import { useEffect, useRef } from "react";

interface Props {
  streamOrTrack: MediaStream | MediaStreamTrack | null;
}
export function AudioStream(props: Props) {
  const audioRef = useRef<HTMLAudioElement>(null);
  useEffect(() => {
    if (audioRef.current && props.streamOrTrack) {
      audioRef.current.srcObject =
        props.streamOrTrack instanceof MediaStream
          ? props.streamOrTrack
          : new MediaStream([props.streamOrTrack]);
    }
  }, [props.streamOrTrack]);

  if (!props.streamOrTrack) {
    return;
  }

  return <audio ref={audioRef} autoPlay />;
}