Commit a5e388c5 authored by Bill's avatar Bill

fix: 修改socket添加token以及规定接收信息的数据结构

parent ebf4cdf9
......@@ -16,6 +16,7 @@ import { SOCKET_URL } from '@/constants';
// layout: 'sidemenu' | 'topmenu';
// }
const NOT_READ_MESSAGE = 1;
const GlobalHeaderRight: React.FC<{}> = (props) => {
// const { theme, layout } = props;
const [message, setMessage] = useState<number>(0);
......@@ -31,17 +32,20 @@ const GlobalHeaderRight: React.FC<{}> = (props) => {
const webSocketInit = useCallback(() => {
console.log(ws.current)
if ((!ws.current || ws.current.readyState === 3) && userInfo) {
ws.current = new WebSocket(`${SOCKET_URL}/report/websocket?memberId=${userInfo.memberId}&roleId=${userInfo.memberRoleId}`);
const url = `${SOCKET_URL}/report/websocket?memberId=${userInfo.memberId}&roleId=${userInfo.memberRoleId}&token=${userInfo.token}`;
ws.current = new WebSocket(url);
ws.current.onopen = (e) => {
console.log(e)
}
ws.current.onmessage = (e) => {
console.log(e)
setMessage(e.data)
if(e.data.type === NOT_READ_MESSAGE) {
setMessage(e.data.data);
}
};
ws.current.onclose = (e) => {
console.log("关闭连接")
}
}
ws.current.onerror = (e) => {
console.log("socket 出错")
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment