Skip to content

Commit

Permalink
feat: gets levelcontrolslist working for DSP and other level control
Browse files Browse the repository at this point in the history
  • Loading branch information
ndorin committed May 17, 2024
1 parent 1f13c21 commit 1a57523
Show file tree
Hide file tree
Showing 14 changed files with 75 additions and 24 deletions.
9 changes: 6 additions & 3 deletions src/lib/shared/hooks/interfaces/useILevelControls.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { useGetDevice } from 'src/lib/store';
import { useGetDevice, useRoomLevelControls } from 'src/lib/store';
import { LevelControlsState } from 'src/lib/types/state/state/LevelControlsState';
import { useWebsocketContext } from 'src/lib/utils/useWebsocketContext';


export function useILevelControls(key: string): ILevelControlsReturn | undefined {
const { sendMessage, sendSimpleMessage } = useWebsocketContext();
const device = useGetDevice<LevelControlsState>(key);
const room = useRoomLevelControls(key);

if (!device) return undefined;
const state: LevelControlsState | undefined = device || room;

if (!state) return undefined;

const setLevel = (levelKey: string, value: number) =>
sendSimpleMessage(`${levelKey}/level`, value);
Expand All @@ -19,7 +22,7 @@ export function useILevelControls(key: string): ILevelControlsReturn | undefined
const muteOff = (levelKey: string) => sendMessage(`${levelKey}/muteOff`, null);

return {
levelState: device,
levelState: state,
setLevel,
muteToggle,
muteOn,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export const useGetAllDeviceStateFromRoomConfiguration = ({config}: {config: Roo
deviceKeys.push(dli.sinkKey);
});

if(config.levelControlList) {
Object.values(config.levelControlList).forEach((lcl) => {
deviceKeys.push(lcl.deviceKey);
});
}

config.touchpanelKeys?.forEach((d) => {
deviceKeys.push(d);
});
Expand Down
5 changes: 4 additions & 1 deletion src/lib/store/devices/devices.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ const devicesSlice = createSlice({
state[key] = newState;

return state;
}
},
clearDevices() {
return initialState;
},
},
})

Expand Down
5 changes: 4 additions & 1 deletion src/lib/store/rooms/rooms.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ const roomsSlice = createSlice({
console.log(state);

return state;
}
},
clearRooms() {
return initialState;
},
},
})

Expand Down
14 changes: 13 additions & 1 deletion src/lib/store/rooms/roomsSelectors.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector } from '@reduxjs/toolkit';
import { RoomVolumeType, Volume } from 'src/lib/types';
import { DisplayState, RoomConfiguration } from "src/lib/types/state/state";
import { DisplayState, LevelControlsState, RoomConfiguration } from "src/lib/types/state/state";
import { useGetAllDevices } from '../devices/devicesSelectors';
import { useAppSelector } from "../hooks";
import store, { RootState } from '../rootReducer';
Expand All @@ -26,13 +26,25 @@ export const useRoomVolume = (roomKey: string, volumeKey: RoomVolumeType) =>
state.rooms[roomKey] ? state.rooms[roomKey]?.volumes[volumeKey] as Volume : undefined
);

export const useRoomLevelControls = (roomKey: string) =>
useAppSelector((state) =>
state.rooms[roomKey] ? state.rooms[roomKey] as unknown as LevelControlsState : undefined
);

export const useRoomSourceList = (roomKey: string) =>
useAppSelector((state) =>
state.rooms[roomKey]
? state.rooms[roomKey]?.configuration?.sourceList
: undefined
);

export const useRoomLevelControlList = (roomKey: string) =>
useAppSelector((state) =>
state.rooms[roomKey]
? state.rooms[roomKey]?.configuration?.levelControlList
: undefined
);

export const useRoomDestinations = (roomKey: string) =>
useAppSelector((state) =>
state.rooms[roomKey]
Expand Down
11 changes: 9 additions & 2 deletions src/lib/store/runtimeConfig/runtimeConfig.slice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { RoomData } from '../../types/index';
import { devicesActions } from '../devices/devices.slice';
import { roomsActions } from '../rooms/rooms.slice';
import store from '../rootReducer';

const initialState: RuntimeConfigState = {
apiVersion: '',
Expand All @@ -12,7 +15,8 @@ const initialState: RuntimeConfigState = {
token: '',
roomData: {
clientId: '',
roomKey: '',
defaultRoomKey: '',
currentRoomKey: '',
systemUuid: '',
roomUuid: '',
userAppUrl: '',
Expand Down Expand Up @@ -45,7 +49,10 @@ const runtimeConfigSlice = createSlice({
state.roomData = action.payload;
},
setCurrentRoomKey(state, action: PayloadAction<string>) {
state.roomData.roomKey = action.payload;
// clear out any existing room/device data
store.dispatch(roomsActions.clearRooms());
store.dispatch(devicesActions.clearDevices());
state.roomData.currentRoomKey = action.payload;
},
setUserCode(state, action: PayloadAction<UserCode>) {
state.roomData.userCode = action.payload.userCode;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/store/runtimeConfig/runtimeSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { useAppSelector } from '../hooks';

export const useWsIsConnected = () => useAppSelector((state) => state.runtimeConfig.websocket.isConnected);

export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomData.roomKey);
export const useRoomKey = () => useAppSelector((state) => state.runtimeConfig.roomData.currentRoomKey);

export const useClientId = () => useAppSelector((state) => state.runtimeConfig.roomData.clientId);
3 changes: 2 additions & 1 deletion src/lib/types/classes/room-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface RoomData {
clientId: string | number;
roomKey: string;
defaultRoomKey: string;
currentRoomKey: string;
systemUuid: string;
roomUuid: string;
userAppUrl: string;
Expand Down
4 changes: 1 addition & 3 deletions src/lib/types/interfaces/ISelectableItem.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { IKeyName } from 'src/lib';
import { IKeyName } from '.';

export interface ISelectableItem extends IKeyName {
isSelected: boolean;
Name: string;
Key: string;
}
10 changes: 10 additions & 0 deletions src/lib/types/state/LevelControlListItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export interface LevelControlListItem {
deviceKey: string;
preferredName: string;
name: string;
includeInUserList: boolean;
order: number;
type: LevelControlType;
}

export type LevelControlType = 'Level' | 'Mute' | 'LevelAndMute';
1 change: 1 addition & 0 deletions src/lib/types/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './LevelControlListItem';
export * from './collections';
export * from './common-functions-util';
export * from './config';
Expand Down
4 changes: 1 addition & 3 deletions src/lib/types/state/state/IEssentialsRoomCombinerState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ export interface RoomCombinationScenario extends IKeyName {
isActive: boolean;
}

export interface Partition {
export interface Partition extends IKeyName {
partitionPresent: boolean;
adjacentRoomKeys: string[];
Name: string;
Key: string;
}

export interface PartitionState {
Expand Down
18 changes: 10 additions & 8 deletions src/lib/types/state/state/RoomState.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable max-classes-per-file */

import { DestinationListItem } from '../DestinationListItem';
import { LevelControlListItem } from '../LevelControlListItem';
import { SourceListItem } from '../sourceListItem';
import { Volume } from '../volume/volume';
import { DeviceState } from './DeviceState';
Expand All @@ -23,30 +24,31 @@ export interface RoomState extends DeviceState{
}

export interface RoomConfiguration {
accessoryDeviceKeys?: string[];
audioCodecKey?: string;
ciscoNavigatorKey?: string;
defaultDisplayKey?: string;
defaultPresentationSourceKey: string;
destinations: Record<DestinationTypes, string>;
destinationList: Record<string, DestinationListItem>;
destinations: Record<DestinationTypes, string>;
endpointKeys?: string[];
environmentalDevices: EnvironmentalDeviceConfiguration[];
hasAudioConferencing?: boolean;
hasEnvironmentalControls?: boolean;
hasVideoConferencing?: boolean;
helpMessage?: string;
techPassword?: string;
levelControlList: Record<string, LevelControlListItem>;
matrixRoutingKey?: string;
roomCombinerKey?: string;
sourceList: Record<string, SourceListItem>;
supportsAdvancedSharing?: boolean;
techPassword?: string;
touchpanelKeys?: string[];
uiBehavior?: EssentialsRoomUiBehaviorConfiguration;
userCanChangeShareMode?: boolean;
videoCodecIsZoomRoom?: boolean;
videoCodecKey?: string;
touchpanelKeys?: string[];
zoomRoomControllerKey?: string;
ciscoNavigatorKey?: string;
matrixRoutingKey?: string;
endpointKeys?: string[];
accessoryDeviceKeys?: string[];
roomCombinerKey?: string;
}

export interface EssentialsRoomUiBehaviorConfiguration {
Expand Down
7 changes: 7 additions & 0 deletions src/lib/utils/WebsocketProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => {
runtimeConfigActions.setUserCode(message.content as UserCode)
);
break;
case "/system/roomCombinationChanged":
window.location.reload();
break;
default:
console.log("unhandled system message", message);
break;
}
} else if (message.type.startsWith("/event/")) {
console.log('event message received', message);
Expand Down Expand Up @@ -255,6 +261,7 @@ const WebsocketProvider = ({ children }: { children: ReactNode }) => {
* */
useEffect(() => {
if (roomKey) {
console.log("requesting status from room: ", roomKey);
sendMessage(`/room/${roomKey}/status`, null);
}
}, [roomKey, sendMessage]);
Expand Down

0 comments on commit 1a57523

Please sign in to comment.