|
@@ -1,6 +1,6 @@
|
|
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
|
import { useWebSocket } from 'ahooks'
|
|
|
-import { useEffect } from 'react'
|
|
|
+import { useEffect, useState } from 'react'
|
|
|
import { useModel } from 'umi'
|
|
|
|
|
|
export enum cmdType {
|
|
@@ -20,10 +20,17 @@ export default function useWebSocketFn() {
|
|
|
|
|
|
const { currentUser } = initialState
|
|
|
|
|
|
+ const [copyCount, setCopyCount] = useState('')
|
|
|
const { disconnect, connect, webSocketIns } = useWebSocket(
|
|
|
`ws://cld2qa.com/summon/v1/chat/link?username=${currentUser.username}&id=${currentUser.staffId}`,
|
|
|
{
|
|
|
manual: true,
|
|
|
+ onMessage: msg => {
|
|
|
+ const data = JSON.parse(msg.data)
|
|
|
+ if (data.cmd === 1) {
|
|
|
+ setCopyCount(data.CopyCount)
|
|
|
+ }
|
|
|
+ },
|
|
|
reconnectLimit: 0,
|
|
|
reconnectInterval: 2000
|
|
|
}
|
|
@@ -36,13 +43,14 @@ export default function useWebSocketFn() {
|
|
|
connect()
|
|
|
}
|
|
|
return () => {
|
|
|
- window.removeEventListener('beforeunload', () => {})
|
|
|
disconnect()
|
|
|
}
|
|
|
}, [])
|
|
|
|
|
|
function sendMsg(cmd: cmdType, options: any) {
|
|
|
- webSocketIns?.send(JSON.stringify({ cmd, userid: currentUser.staffId, ...options }))
|
|
|
+ webSocketIns?.send(
|
|
|
+ JSON.stringify({ cmd, userid: `${currentUser.staffId}_${copyCount}`, ...options })
|
|
|
+ )
|
|
|
}
|
|
|
return { webSocketIns, sendMsg }
|
|
|
}
|