1
1
import * as path from 'path' ;
2
- import sharp from 'sharp' ;
2
+ import sharp , { Sharp } from 'sharp' ;
3
3
import type { StreamDeck } from '@elgato-stream-deck/node' ;
4
4
import { fileURLToPath } from 'url' ;
5
- import type { HID } from './HID' ;
5
+ import type { HID , HIDActions } from './HID' ;
6
6
import type { StreamDeckButtonControlDefinitionLcdFeedback } from '@elgato-stream-deck/core/dist/controlDefinition' ;
7
7
8
8
const __filename = fileURLToPath ( import . meta. url ) ;
@@ -13,6 +13,8 @@ export class StreamDeckHID implements HID {
13
13
static ACCEPT_BUTTON : StreamDeckButtonControlDefinitionLcdFeedback ;
14
14
static REJECT_BUTTON : StreamDeckButtonControlDefinitionLcdFeedback ;
15
15
static LEAVE_BUTTON : StreamDeckButtonControlDefinitionLcdFeedback ;
16
+ static MUTE_BUTTON : StreamDeckButtonControlDefinitionLcdFeedback ;
17
+ static UNMUTE_BUTTON : StreamDeckButtonControlDefinitionLcdFeedback ;
16
18
17
19
private streamDeck : StreamDeck ;
18
20
@@ -21,13 +23,17 @@ export class StreamDeckHID implements HID {
21
23
private ACCEPT_IMG ;
22
24
private REJECT_IMG ;
23
25
private LEAVE_IMG ;
26
+ private MUTE_IMG ;
27
+ private UNMUTE_IMG ;
24
28
25
29
private hasVerificationPending = false ;
26
30
27
31
private acceptCallback : ( ) => void ;
28
32
private rejectCallback : ( ) => void ;
29
33
30
34
private leaveCallback : ( ) => void ;
35
+ private muteCallback : ( ) => void ;
36
+ private unmuteCallback : ( ) => void ;
31
37
private isConnected : boolean ;
32
38
33
39
constructor ( streamDeck : StreamDeck ) {
@@ -44,22 +50,30 @@ export class StreamDeckHID implements HID {
44
50
this . streamDeck . on ( 'up' , button => {
45
51
console . log ( 'key %d up' , button . index ) ;
46
52
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
+ }
52
57
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
+ }
57
61
}
58
62
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
+ }
62
75
}
76
+
63
77
} ) ;
64
78
65
79
this . streamDeck . on ( 'error' , error => {
@@ -86,21 +100,24 @@ export class StreamDeckHID implements HID {
86
100
}
87
101
if ( control . row == rows && control . column == columns ) {
88
102
StreamDeckHID . LEAVE_BUTTON = control ;
103
+ StreamDeckHID . MUTE_BUTTON = control ;
89
104
}
90
105
if ( control . row == 1 && control . column == 0 ) {
91
106
StreamDeckHID . ACCEPT_BUTTON = control ;
107
+ StreamDeckHID . UNMUTE_BUTTON = control ;
92
108
}
93
109
if ( control . row == 1 && control . column == 1 ) {
94
110
StreamDeckHID . REJECT_BUTTON = control ;
95
111
}
96
112
}
97
113
} ) ;
98
114
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' ) ;
104
121
105
122
this . BBB_IMG_LG = await sharp ( path . resolve ( __dirname , '../assets/bbb.png' ) )
106
123
. flatten ( )
@@ -114,31 +131,12 @@ export class StreamDeckHID implements HID {
114
131
)
115
132
. raw ( )
116
133
. toBuffer ( ) ;
134
+ }
117
135
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 ) )
137
138
. flatten ( )
138
- . resize (
139
- StreamDeckHID . LEAVE_BUTTON . pixelSize . width ,
140
- StreamDeckHID . LEAVE_BUTTON . pixelSize . height ,
141
- )
139
+ . resize ( button . pixelSize . width , button . pixelSize . height )
142
140
. raw ( )
143
141
. toBuffer ( ) ;
144
142
}
@@ -185,14 +183,18 @@ export class StreamDeckHID implements HID {
185
183
await this . streamDeck . close ( ) ;
186
184
}
187
185
188
- connected ( leave : ( ) => void ) : void {
186
+ connected ( actions : HIDActions ) : void {
189
187
this . streamDeck . clearPanel ( ) ;
190
188
191
189
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 ) ;
192
192
this . streamDeck . fillKeyBuffer ( StreamDeckHID . LEAVE_BUTTON . index , this . LEAVE_IMG ) ;
193
193
194
194
this . isConnected = true ;
195
- this . leaveCallback = leave ;
195
+ this . muteCallback = actions . mute ;
196
+ this . unmuteCallback = actions . unmute ;
197
+ this . leaveCallback = actions . leave ;
196
198
}
197
199
198
200
disconnected ( ) : void {
0 commit comments