Skip to content

Commit 4feb739

Browse files
Mitix-EPIEmeryckClerin
authored andcommitted
Socket restructuration (#10)
* core(socket): getAllMics works setVolumeToMic WIP setAutoAudioLeveler WIP * feat(socket): add setMicLevel * fix(socket): setMicLevel with mics as arg * feat(socket): add "setSubtitles" socket * fix(action): change format source * feat(): add actionReaction socket + core changes getActReactCouples socket setActionReaction socket WordDetection add loading * feat(): Remove an actReaction + fix minor bugs
1 parent 5c230a5 commit 4feb739

File tree

13 files changed

+703
-369
lines changed

13 files changed

+703
-369
lines changed

public/electron.js

Lines changed: 231 additions & 125 deletions
Large diffs are not rendered by default.

src/Components/Actions/GeneralActions.tsx

Lines changed: 94 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -15,70 +15,77 @@ import DialogActions from '@mui/material/DialogActions';
1515
import DialogContent from '@mui/material/DialogContent';
1616
import DialogContentText from '@mui/material/DialogContentText';
1717
import DialogTitle from '@mui/material/DialogTitle';
18-
import NumericInput from 'material-ui-numeric-input';
1918
import { LocalStorage } from '../../LocalStorage/LocalStorage';
2019

21-
export enum ActionType {
22-
ChangeCamera,
23-
ChangeScene,
24-
StartLive,
25-
StopLive,
26-
ActivateSoundboard
20+
export enum ReactionType {
21+
CAMERA_SWITCH = "CAMERA_SWITCH",
22+
SCENE_SWITCH = "SCENE_SWITCH",
23+
START_LIVE = "START_LIVE",
24+
STOP_LIVE = "STOP_LIVE",
25+
TOGGLE_AUDIO_COMPRESSOR = "TOGGLE_AUDIO_COMPRESSOR"
2726
}
2827

2928
export const GeneralActions = () => {
3029

31-
const keysActionType = Object.keys(ActionType).filter(k => typeof ActionType[k as any] === "number");
32-
const valuesActionType = keysActionType.map(k => ActionType[k as any]);
33-
34-
const [open, setOpen] = React.useState(false);
35-
const [newActionName, setNewActionName] = React.useState("");
36-
const [newActionSelected, setNewActionSelected] = React.useState(0);
37-
const [newActionParam, setNewActionParam] = React.useState(0)
38-
39-
const handleOnChangeSelect = (action: SelectChangeEvent<unknown>) => {
40-
const value = action.target.value as ActionType;
41-
setNewActionSelected(value);
42-
};
43-
44-
const handleClickOpen = () => {
45-
setOpen(true);
46-
};
47-
48-
const [ actionsList, setActionsList ] = React.useState(LocalStorage.getItemObject("actionsList") || [])
49-
50-
const handleSave = () => {
51-
console.log("newActionName", newActionName);
52-
console.log("newActionSelected", newActionSelected);
53-
console.log("newActionParam", newActionParam);
54-
if (newActionName !== "") {
55-
let newElem: any = {
56-
id: actionsList.length > 0 ? Math.max(...actionsList.map((o: any) => o.id)) + 1 : 1,
57-
name: newActionName,
58-
action: newActionSelected as ActionType,
30+
const keysReactionType = Object.keys(ReactionType);
31+
32+
const [open, setOpen] = React.useState(false);
33+
const [newActionName, setNewActionName] = React.useState("");
34+
const [newActionSelected, setNewActionSelected] = React.useState("CAMERA_SWITCH");
35+
const [newActionParam, setNewActionParam] = React.useState("")
36+
37+
const handleOnChangeSelect = (action: SelectChangeEvent<unknown>) => {
38+
const value = action.target.value as ReactionType;
39+
setNewActionSelected(value);
40+
};
41+
42+
const handleClickOpen = () => {
43+
setOpen(true);
44+
};
45+
46+
const [ actionsList, setActionsList ] = React.useState(LocalStorage.getItemObject("actionsList") || [])
47+
48+
const handleSave = () => {
49+
console.log("newActionName", newActionName);
50+
console.log("newActionSelected", newActionSelected);
51+
console.log("newActionParam", newActionParam);
52+
if (newActionName !== "") {
53+
let newElem: any = {
54+
id: actionsList.length > 0 ? Math.max(...actionsList.map((o: any) => o.id)) + 1 : 1,
55+
name: newActionName,
56+
action: newActionSelected as ReactionType,
57+
}
58+
if (newActionParam) {
59+
if (newActionSelected === ReactionType.TOGGLE_AUDIO_COMPRESSOR)
60+
newElem.params = { "audio-source": newActionParam };
61+
if (newActionSelected === ReactionType.CAMERA_SWITCH)
62+
newElem.params = { "video-source": newActionParam };
63+
if (newActionSelected === ReactionType.SCENE_SWITCH)
64+
newElem.params = { "scene-name": newActionParam };
65+
if (newActionSelected === ReactionType.START_LIVE)
66+
newElem.params = { "seconds": newActionParam };
67+
if (newActionSelected === ReactionType.STOP_LIVE)
68+
newElem.params = { "seconds": newActionParam };
69+
}
70+
71+
const newList = actionsList.concat([newElem]);
72+
73+
setActionsList(newList);
74+
LocalStorage.setItemObject("actionsList", newList)
75+
alert("Action saved");
76+
} else {
77+
// Put alert
78+
alert("Missing parameters");
5979
}
60-
if (newActionParam) {
61-
newElem.param_value = newActionParam;
62-
}
63-
64-
const newList = actionsList.concat([newElem]);
65-
66-
setActionsList(newList);
67-
LocalStorage.setItemObject("actionsList", newList)
68-
alert("Action saved");
69-
} else {
70-
// Put alert
71-
alert("Missing parameters");
80+
setNewActionName("");
81+
setNewActionSelected("CAMERA_SWITCH");
82+
setNewActionParam("");
83+
setOpen(false);
84+
};
85+
86+
const handleCancel = () => {
87+
setOpen(false);
7288
}
73-
setNewActionName("");
74-
setNewActionSelected(0);
75-
setNewActionParam(0);
76-
setOpen(false);
77-
};
78-
79-
const handleCancel = () => {
80-
setOpen(false);
81-
}
8289

8390

8491
function deleteAction(id: number) {
@@ -89,29 +96,29 @@ export const GeneralActions = () => {
8996
}
9097

9198
function getAction(actionEnum: any) {
92-
if (actionEnum === ActionType.ActivateSoundboard)
93-
return "Activate Soundboard";
94-
if (actionEnum === ActionType.ChangeCamera)
99+
if (actionEnum === ReactionType.TOGGLE_AUDIO_COMPRESSOR)
100+
return "Toggle the audio compressor";
101+
if (actionEnum === ReactionType.CAMERA_SWITCH)
95102
return "Change the camera"
96-
if (actionEnum === ActionType.ChangeScene)
103+
if (actionEnum === ReactionType.SCENE_SWITCH)
97104
return "Change the scene"
98-
if (actionEnum === ActionType.StartLive)
105+
if (actionEnum === ReactionType.START_LIVE)
99106
return "Start the live"
100-
if (actionEnum === ActionType.StopLive)
107+
if (actionEnum === ReactionType.STOP_LIVE)
101108
return "Stop the live"
102109
return ""
103110
}
104111

105-
function getIcon(actionEnum: ActionType) {
106-
if (actionEnum === ActionType.ActivateSoundboard)
112+
function getIcon(actionEnum: ReactionType) {
113+
if (actionEnum === ReactionType.TOGGLE_AUDIO_COMPRESSOR)
107114
return <AiOutlineSound />
108-
if (actionEnum === ActionType.ChangeCamera)
115+
if (actionEnum === ReactionType.CAMERA_SWITCH)
109116
return <AiOutlineVideoCamera />
110-
if (actionEnum === ActionType.ChangeScene)
117+
if (actionEnum === ReactionType.SCENE_SWITCH)
111118
return <MdPanoramaHorizontal />
112-
if (actionEnum === ActionType.StartLive)
119+
if (actionEnum === ReactionType.START_LIVE)
113120
return <AiOutlinePlayCircle />
114-
if (actionEnum === ActionType.StopLive)
121+
if (actionEnum === ReactionType.STOP_LIVE)
115122
return <AiOutlineStop />
116123
return <AiOutlineBug />
117124
}
@@ -120,7 +127,7 @@ export const GeneralActions = () => {
120127
<>
121128
<div className="container events-container">
122129

123-
<h2>List of Actions</h2>
130+
<h2>List of Reactions</h2>
124131

125132
{
126133
actionsList.length === 0 ? (
@@ -138,7 +145,14 @@ export const GeneralActions = () => {
138145
{ getAction(item.action) }
139146
</Typography>
140147
<Typography variant="body2">
141-
{ item.param_value ? "Parameter:" + item.param_value : "" }
148+
{
149+
item.params ?
150+
Object.keys(item.params).map(key => {
151+
return `${key}: ${item.params[key]}`;
152+
}).join("\n")
153+
:
154+
""
155+
}
142156
</Typography>
143157
</CardContent>
144158
<CardActions disableSpacing className="rightAlignItem">
@@ -154,7 +168,7 @@ export const GeneralActions = () => {
154168
</div>
155169

156170
<Dialog open={open} onClose={handleCancel}>
157-
<DialogTitle>Add Action</DialogTitle>
171+
<DialogTitle>Add Reaction</DialogTitle>
158172
<DialogContent>
159173
<DialogContentText>
160174
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
@@ -187,22 +201,20 @@ export const GeneralActions = () => {
187201
label="Action"
188202
>
189203
{
190-
keysActionType.map((k) => {
191-
return (<MenuItem key={ActionType[k as any]} value={ActionType[k as any]}>{getAction(ActionType[k as any])}</MenuItem>)
204+
keysReactionType.map((k) => {
205+
return (<MenuItem key={k} value={k}>{getAction(k)}</MenuItem>)
192206
})
193207
}
194208
</Select>
195209
</div>
196210

197211
<div className="form-item">
198-
<NumericInput
199-
name='Parameter action'
200-
precision={0}
201-
decimalChar=','
202-
thousandChar='.'
203-
label='Parameter action'
204-
onChange={(action) => setNewActionParam(action.target.value as number)}
205-
variant='outlined'
212+
<TextField
213+
id="parameter-action"
214+
label="Parameter action"
215+
type="text"
216+
variant="outlined"
217+
onChange={(action) => setNewActionParam(action.target.value)}
206218
/>
207219
</div>
208220

@@ -216,7 +228,7 @@ export const GeneralActions = () => {
216228
<div className="add_button_pos">
217229
<Button variant="contained" className="add_button" onClick={handleClickOpen}
218230
>
219-
Add Action
231+
Add Reaction
220232
</Button>
221233
</div>
222234
</>

src/Components/AddNewWord/AddNewWord.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ export const AddNewWord = (props: any) => {
119119
newEvent={props.newEvent}
120120
setnewEvent={props.setnewEvent}
121121
addNewEvent={props.addNewEvent}
122-
changeEvent={props.changeEvent}
123122
open={open}
124123
/>
125124
</>

src/Components/App/App.tsx

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,12 @@ import { Report } from '../Report/Report'
1313
import { MicsLevel } from '../MicsLevel/MicsLevel';
1414
import { WordDetection } from '../WordDetection/WordDetection';
1515
import { GeneralActions } from '../Actions/GeneralActions';
16-
import { AllMics, resultFormat } from '../../Socket/interfaces';
1716
import { Scenes } from '../Scenes/Scenes';
1817
import { Login } from '../Login/login';
1918
const ipcRenderer = window.require('electron').ipcRenderer
2019

2120
export default function App() {
2221

23-
const [response, setResponse] = useState('');
24-
25-
const getAllMics = (): Promise<AllMics> => {
26-
return new Promise(async (resolve, reject) => {
27-
const result: AllMics = await ipcRenderer.sendSync('getAllMics', 'ping');
28-
console.log('getAllMics invoke', result);
29-
resolve(result);
30-
})
31-
}
32-
33-
const setVolumeToMic = (micId: string, value: number): Promise<resultFormat> => {
34-
return new Promise(async (resolve, reject) => {
35-
const result: resultFormat = await ipcRenderer.sendSync('setVolumeToMic', {'micId': micId, 'value': value});
36-
console.log('setVolumeToMic invoke', result);
37-
resolve(result)
38-
});
39-
}
40-
41-
useEffect(() => {
42-
setTimeout(() => {
43-
console.log('Call getAllMics');
44-
getAllMics()
45-
.then(_ => {
46-
setVolumeToMic('Audio Input Capture (PulseAudio)', 100)
47-
.then((res) => {
48-
if (res.statusCode === 200) {
49-
getAllMics()
50-
.then((allMics) => {
51-
console.log('FINALLY -> ', allMics);
52-
})
53-
}
54-
})
55-
})
56-
}, 5000);
57-
58-
return () => {
59-
console.log('unmounting');
60-
setResponse('');
61-
};
62-
}, []);
63-
6422
return (
6523
<div className='App'>
6624
<Router>

src/Components/BoxEvent/BoxEvent.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,28 @@ export default function BoxEvent(props: any) {
6161

6262
return (
6363
<>
64-
<Box style={boxStyles}>
65-
<span key="if-you-say" style={TextStylesTitle}>If you say : </span>
66-
{props.keyObj.keywords.map((item: any, index: number) => {
67-
return <span key={item} style={TextStyles}>[{item}] </span>
68-
})}
69-
<BsTrash
70-
style={IconStyles}
71-
onClick={() => { deleteEvent(props.i) }}
72-
/>
73-
<br></br>
74-
<span key="the-actions" style={TextStylesTitle}>The actions : </span>
75-
<span key={props.keyObj.source.name} style={TextStyles}>[{props.keyObj.source.name}]</span>
76-
<span style={TextStylesTitle}> will be done.</span>
77-
</Box>
64+
{
65+
props.keyObj.action.type === "WORD_DETECT" ?
66+
67+
<Box style={boxStyles}>
68+
<span key="if-you-say" style={TextStylesTitle}>If you say : </span>
69+
{
70+
props.keyObj.action.params.words.map((item: any, index: number) => {
71+
return <span key={item} style={TextStyles}>[{item}] </span>
72+
})
73+
}
74+
<BsTrash
75+
style={IconStyles}
76+
onClick={() => { deleteEvent(props.i) }}
77+
/>
78+
<br></br>
79+
<span key="the-actions" style={TextStylesTitle}>The reaction : </span>
80+
<span key={props.keyObj.reactionId } style={TextStyles}>[{props.keyObj.reaction?.name ? props.keyObj.reaction?.name : "NAME ERROR" }]</span>
81+
<span style={TextStylesTitle}> will be done.</span>
82+
</Box>
83+
84+
: <></>
85+
}
7886
</>
7987
);
8088
}

0 commit comments

Comments
 (0)