import styles from '@/page/Meeting/CurrentSpeakUserWindow/index.module.scss'
import { useEffect, useState } from "react";
const CurrentSpeakUserWindow: React.FC = () => {
  const [inputValue, setInputValue] = useState('')
  const channel = new BroadcastChannel('meeting_channel');
  useEffect(() => {
    channel.onmessage = function (event) {
      const { type, currentSpeakUser } = event.data;
      switch (type) {
        case 'currentSpeakUser':
          if (currentSpeakUser.length) {
            setInputValue(currentSpeakUser.join(';'))
          } else {
            setInputValue('')
          }
          break;
      }
    }
    return () => {
      channel.close();
    }
  }, []);


  return (
    <>
      <div className={styles.currentSpeakUserWindow}>
        <div title={`正在说话: ${inputValue}`}>
          {`正在说话: ${inputValue}`}
        </div>
      </div >
    </>
  )
}

export default CurrentSpeakUserWindow
