Skip to content

Commit c014141

Browse files
committed
Add mute/unmute HID actions
1 parent c58982e commit c014141

File tree

5 files changed

+63
-46
lines changed

5 files changed

+63
-46
lines changed
Loading
Loading

appliance-application/packages/main/src/HID.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ export interface HID {
44
verificationAccepted(): void;
55
verificationRejected(): void;
66

7-
connected(leave: () => void): void;
7+
connected(actions: HIDActions): void;
88

99
disconnected(): void;
1010

1111
close(): Promise<void>;
1212
}
13+
14+
export interface HIDActions {
15+
leave: () => void;
16+
mute: () => void;
17+
unmute: () => void;
18+
}

appliance-application/packages/main/src/mainWindow.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,18 @@ async function createWindow() {
131131
ipcMain.off('pluginDisconnected', pluginDisconnected);
132132
};
133133

134+
134135
// Notify all connected HDI devices that the user has joined the meeting
135136
hdiDevices.forEach(device => {
136-
device.connected(leaveMeeting);
137+
device.connected({
138+
leave: leaveMeeting,
139+
mute: () => {
140+
bbbMeeting.mute();
141+
},
142+
unmute: () => {
143+
bbbMeeting.unmute();
144+
},
145+
});
137146
});
138147
});
139148

appliance-application/packages/main/src/streamdeck.ts

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as path from 'path';
2-
import sharp from 'sharp';
2+
import sharp, {Sharp} from 'sharp';
33
import type {StreamDeck} from '@elgato-stream-deck/node';
44
import {fileURLToPath} from 'url';
5-
import type {HID} from './HID';
5+
import type {HID, HIDActions} from './HID';
66
import type {StreamDeckButtonControlDefinitionLcdFeedback} from '@elgato-stream-deck/core/dist/controlDefinition';
77

88
const __filename = fileURLToPath(import.meta.url);
@@ -13,6 +13,8 @@ export class StreamDeckHID implements HID {
1313
static ACCEPT_BUTTON: StreamDeckButtonControlDefinitionLcdFeedback;
1414
static REJECT_BUTTON: StreamDeckButtonControlDefinitionLcdFeedback;
1515
static LEAVE_BUTTON: StreamDeckButtonControlDefinitionLcdFeedback;
16+
static MUTE_BUTTON: StreamDeckButtonControlDefinitionLcdFeedback;
17+
static UNMUTE_BUTTON: StreamDeckButtonControlDefinitionLcdFeedback;
1618

1719
private streamDeck: StreamDeck;
1820

@@ -21,13 +23,17 @@ export class StreamDeckHID implements HID {
2123
private ACCEPT_IMG;
2224
private REJECT_IMG;
2325
private LEAVE_IMG;
26+
private MUTE_IMG;
27+
private UNMUTE_IMG;
2428

2529
private hasVerificationPending = false;
2630

2731
private acceptCallback: () => void;
2832
private rejectCallback: () => void;
2933

3034
private leaveCallback: () => void;
35+
private muteCallback: () => void;
36+
private unmuteCallback: () => void;
3137
private isConnected: boolean;
3238

3339
constructor(streamDeck: StreamDeck) {
@@ -44,22 +50,30 @@ export class StreamDeckHID implements HID {
4450
this.streamDeck.on('up', button => {
4551
console.log('key %d up', button.index);
4652

47-
if (button.index === StreamDeckHID.ACCEPT_BUTTON.index && this.hasVerificationPending) {
48-
this.hasVerificationPending = false;
49-
this.hideVerificationButtons();
50-
this.acceptCallback();
51-
}
53+
if(this.hasVerificationPending){
54+
if (button.index === StreamDeckHID.ACCEPT_BUTTON.index) {
55+
this.acceptCallback();
56+
}
5257

53-
if (button.index === StreamDeckHID.REJECT_BUTTON.index && this.hasVerificationPending) {
54-
this.hasVerificationPending = false;
55-
this.hideVerificationButtons();
56-
this.rejectCallback();
58+
if (button.index === StreamDeckHID.REJECT_BUTTON.index) {
59+
this.rejectCallback();
60+
}
5761
}
5862

59-
if (button.index === StreamDeckHID.LEAVE_BUTTON.index) {
60-
this.isConnected = true;
61-
this.leaveCallback();
63+
if(this.isConnected){
64+
if (button.index === StreamDeckHID.MUTE_BUTTON.index) {
65+
this.muteCallback();
66+
}
67+
68+
if (button.index === StreamDeckHID.UNMUTE_BUTTON.index) {
69+
this.unmuteCallback();
70+
}
71+
72+
if (button.index === StreamDeckHID.LEAVE_BUTTON.index) {
73+
this.leaveCallback();
74+
}
6275
}
76+
6377
});
6478

6579
this.streamDeck.on('error', error => {
@@ -86,21 +100,24 @@ export class StreamDeckHID implements HID {
86100
}
87101
if (control.row == rows && control.column == columns) {
88102
StreamDeckHID.LEAVE_BUTTON = control;
103+
StreamDeckHID.MUTE_BUTTON = control;
89104
}
90105
if (control.row == 1 && control.column == 0) {
91106
StreamDeckHID.ACCEPT_BUTTON = control;
107+
StreamDeckHID.UNMUTE_BUTTON = control;
92108
}
93109
if (control.row == 1 && control.column == 1) {
94110
StreamDeckHID.REJECT_BUTTON = control;
95111
}
96112
}
97113
});
98114

99-
this.BBB_IMG = await sharp(path.resolve(__dirname, '../assets/bbb.png'))
100-
.flatten()
101-
.resize(StreamDeckHID.BBB_BUTTON.pixelSize.width, StreamDeckHID.BBB_BUTTON.pixelSize.height)
102-
.raw()
103-
.toBuffer();
115+
this.BBB_IMG = await this.getButtonImageBuffer(StreamDeckHID.BBB_BUTTON, 'bbb.png');
116+
this.ACCEPT_IMG = await this.getButtonImageBuffer(StreamDeckHID.ACCEPT_BUTTON, 'accept.png');
117+
this.REJECT_IMG = await this.getButtonImageBuffer(StreamDeckHID.REJECT_BUTTON, 'reject.png');
118+
this.LEAVE_IMG = await this.getButtonImageBuffer(StreamDeckHID.LEAVE_BUTTON, 'leave.png');
119+
this.MUTE_IMG = await this.getButtonImageBuffer(StreamDeckHID.MUTE_BUTTON, 'mute.png');
120+
this.UNMUTE_IMG = await this.getButtonImageBuffer(StreamDeckHID.UNMUTE_BUTTON, 'unmute.png');
104121

105122
this.BBB_IMG_LG = await sharp(path.resolve(__dirname, '../assets/bbb.png'))
106123
.flatten()
@@ -114,31 +131,12 @@ export class StreamDeckHID implements HID {
114131
)
115132
.raw()
116133
.toBuffer();
134+
}
117135

118-
this.ACCEPT_IMG = await sharp(path.resolve(__dirname, '../assets/accept.png'))
119-
.flatten()
120-
.resize(
121-
StreamDeckHID.ACCEPT_BUTTON.pixelSize.width,
122-
StreamDeckHID.ACCEPT_BUTTON.pixelSize.height,
123-
)
124-
.raw()
125-
.toBuffer();
126-
127-
this.REJECT_IMG = await sharp(path.resolve(__dirname, '../assets/reject.png'))
128-
.flatten()
129-
.resize(
130-
StreamDeckHID.REJECT_BUTTON.pixelSize.width,
131-
StreamDeckHID.REJECT_BUTTON.pixelSize.height,
132-
)
133-
.raw()
134-
.toBuffer();
135-
136-
this.LEAVE_IMG = await sharp(path.resolve(__dirname, '../assets/leave.png'))
136+
async getButtonImageBuffer(button: StreamDeckButtonControlDefinitionLcdFeedback, image: string): Promise<Buffer> {
137+
return sharp(path.resolve(__dirname, '../assets/'+image))
137138
.flatten()
138-
.resize(
139-
StreamDeckHID.LEAVE_BUTTON.pixelSize.width,
140-
StreamDeckHID.LEAVE_BUTTON.pixelSize.height,
141-
)
139+
.resize(button.pixelSize.width, button.pixelSize.height)
142140
.raw()
143141
.toBuffer();
144142
}
@@ -185,14 +183,18 @@ export class StreamDeckHID implements HID {
185183
await this.streamDeck.close();
186184
}
187185

188-
connected(leave: () => void): void {
186+
connected(actions: HIDActions): void {
189187
this.streamDeck.clearPanel();
190188

191189
this.streamDeck.fillKeyBuffer(StreamDeckHID.BBB_BUTTON.index, this.BBB_IMG);
190+
this.streamDeck.fillKeyBuffer(StreamDeckHID.MUTE_BUTTON.index, this.MUTE_IMG);
191+
this.streamDeck.fillKeyBuffer(StreamDeckHID.UNMUTE_BUTTON.index, this.UNMUTE_IMG);
192192
this.streamDeck.fillKeyBuffer(StreamDeckHID.LEAVE_BUTTON.index, this.LEAVE_IMG);
193193

194194
this.isConnected = true;
195-
this.leaveCallback = leave;
195+
this.muteCallback = actions.mute;
196+
this.unmuteCallback = actions.unmute;
197+
this.leaveCallback = actions.leave;
196198
}
197199

198200
disconnected(): void {

0 commit comments

Comments
 (0)