import { accessToken, user } from '../auth/selectors' import { PRESENCE_API_BASE, PRESENCE_WSS_BASE, MESSAGES_API_BASE, MESSAGES_WSS_BASE, } from '../../utils/ResourceConstants' import { SocketCluster, SocketChannel, } from './constants' const root = (state: any) => state.socket const byCluster = (state: any, { clusterName }: any) => root(state)[clusterName] export const getUserId = (state: any, props: any) => byCluster(state, props).userId export const getUserIpAddress = (state: any, props: any) => byCluster(state, props).userIpAddress export const getSessionToken = (state: any, props: any = {}) => byCluster(state, props).sessionToken export const isAuthenticated = (state: any, props: any) => !!getSessionToken(state) export const getChannelName = (state: any, { clusterName, channelName }: any) => { switch (channelName) { case SocketChannel.USER: return `user:${getUserId(state, { clusterName })}` case SocketChannel.ORG_PUBLIC: return `org:${user(state).orgId}` case SocketChannel.ORG_PRIVATE: return `private-org:${user(state).orgId}` } } export const getWssBaseUrl = (state: any, { clusterName }: any) => { switch (clusterName) { case SocketCluster.PRESENCE: return PRESENCE_WSS_BASE case SocketCluster.MESSAGES: return MESSAGES_WSS_BASE } } export const getApiBaseUrl = (state: any, { clusterName }: any) => { switch (clusterName) { case SocketCluster.PRESENCE: return PRESENCE_API_BASE case SocketCluster.MESSAGES: return MESSAGES_API_BASE } } export const getAuthParams = (state: any) => { return { access_token: accessToken(state), } }