mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-29 22:23:01 +00:00
Co-authored-by: Steven Enamakel <31011319+senamakel@users.noreply.github.com> Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
25 lines
793 B
TypeScript
25 lines
793 B
TypeScript
import { getCoreStateSnapshot } from '../lib/coreState/store';
|
|
import type { RootState } from './index';
|
|
|
|
const PENDING_USER = '__pending__';
|
|
|
|
/**
|
|
* Derive the socket user ID — must match the key used by
|
|
* socketService.ts when writing to byUser[].
|
|
*/
|
|
function selectSocketUserId(_state: RootState): string {
|
|
return getCoreStateSnapshot().snapshot?.auth?.userId ?? PENDING_USER;
|
|
}
|
|
|
|
export const selectSocketStatus = (state: RootState) => {
|
|
const userId = selectSocketUserId(state);
|
|
const userState = state.socket.byUser[userId];
|
|
return userState?.status ?? 'disconnected';
|
|
};
|
|
|
|
export const selectSocketId = (state: RootState): string | null => {
|
|
const userId = selectSocketUserId(state);
|
|
const userState = state.socket.byUser[userId];
|
|
return userState?.socketId ?? null;
|
|
};
|