diff --git a/src/page/Meeting/ChatSmallWindow/index.tsx b/src/page/Meeting/ChatSmallWindow/index.tsx index 6370a9f..3848677 100644 --- a/src/page/Meeting/ChatSmallWindow/index.tsx +++ b/src/page/Meeting/ChatSmallWindow/index.tsx @@ -1,18 +1,22 @@ import styles from '@/page/Meeting/ChatSmallWindow/index.module.scss' import { Input } from 'antd'; import { useEffect, useState } from "react"; -import { storage } from '@/utils'; const ChatSmallWindow: React.FC = () => { const [inputValue, setInputValue] = useState('') const [chatLists, setChatLists] = useState([]) - const userInfo = JSON.parse(storage.getItem('user') as string) const channel = new BroadcastChannel('meeting_channel'); useEffect(() => { + let time: NodeJS.Timeout; + time = setInterval(() => { + setChatLists((res: any) => { + return res.length ? res.slice(0, -1) : res + }) + }, 10000) channel.onmessage = function (event) { - const { type, chatList } = event.data; + const { type, chatListIten } = event.data; switch (type) { - case 'chatList': - setChatLists(chatList.reverse()) + case 'chatListIten': + setChatLists((newChatList: any) => [chatListIten, ...newChatList]) setTimeout(() => { const chatSmallWindowView = document.getElementById('chatSmallWindowView') as HTMLElement; if (chatSmallWindowView) { @@ -22,6 +26,9 @@ const ChatSmallWindow: React.FC = () => { break; } } + return () => { + clearTimeout(time) + } }, []); diff --git a/src/page/Meeting/index.tsx b/src/page/Meeting/index.tsx index a2d780d..ef8a8b5 100644 --- a/src/page/Meeting/index.tsx +++ b/src/page/Meeting/index.tsx @@ -509,6 +509,10 @@ const Meeting: React.FC = () => { setNoViewChatList(storageNoViewChatList) } setChatList((newChatList: any) => [...newChatList, item]) + channel.postMessage({ + type: 'chatListIten', + chatListIten: item, + }); setStatusList((res: any) => { if (!res.userChatList) { api.open({ @@ -1673,12 +1677,17 @@ const Meeting: React.FC = () => { roomNum: state.channelId, msg: msg, }) - setChatList((newChatList: any) => [...newChatList, { + let item = { uid: userInfo.uid, userName: userInfo.userName, message: msg, timestamp: +new Date() - }]) + } + setChatList((newChatList: any) => [...newChatList, item]) + channel.postMessage({ + type: 'chatListIten', + chatListIten: item, + }); setTextMsg(''); chatScrollBotton() } else {