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