feat: 斗鱼外部单协作台账与店铺实时同步
This commit is contained in:
@@ -12,9 +12,11 @@ export interface CollabRealtimeEvent {
|
||||
interface UseCollabRealtimeOptions {
|
||||
enabled: boolean;
|
||||
onInvalidate: (event: CollabRealtimeEvent) => void;
|
||||
/** 默认是虎牙协作台账;斗鱼页面传入自己的 WS 路径。 */
|
||||
path?: string;
|
||||
}
|
||||
|
||||
const WS_PATH = '/api/huya/external-orders/ws';
|
||||
const DEFAULT_WS_PATH = '/api/huya/external-orders/ws';
|
||||
const HEARTBEAT_TIMEOUT_MS = 60_000;
|
||||
const MAX_RECONNECT_DELAY_MS = 30_000;
|
||||
|
||||
@@ -32,6 +34,7 @@ function websocketUrl(path: string): string {
|
||||
export function useCollabRealtime({
|
||||
enabled,
|
||||
onInvalidate,
|
||||
path = DEFAULT_WS_PATH,
|
||||
}: UseCollabRealtimeOptions) {
|
||||
const [connected, setConnected] = useState(false);
|
||||
const [reconnecting, setReconnecting] = useState(false);
|
||||
@@ -129,7 +132,7 @@ export function useCollabRealtime({
|
||||
return;
|
||||
}
|
||||
|
||||
const nextSocket = new WebSocket(websocketUrl(WS_PATH));
|
||||
const nextSocket = new WebSocket(websocketUrl(path));
|
||||
socket = nextSocket;
|
||||
|
||||
nextSocket.onopen = () => {
|
||||
@@ -179,7 +182,7 @@ export function useCollabRealtime({
|
||||
setConnected(false);
|
||||
setReconnecting(false);
|
||||
};
|
||||
}, [enabled]);
|
||||
}, [enabled, path]);
|
||||
|
||||
return { connected, reconnecting };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user