@@ -62,9 +62,11 @@ export class StreamElementsServiceClient extends EventEmitter {
62
62
this . onEvent ( ( data : StreamElementsEvent ) => {
63
63
if ( data . type === "subscriber" ) {
64
64
if ( data . data . gifted ) {
65
- this . handleSubGift ( data . data . sender , data ,
65
+ this . handleSubGift (
66
+ data . data . sender ,
67
+ data ,
66
68
( subBomb ) => this . emit ( "subbomb" , subBomb ) ,
67
- ( gift ) => this . emit ( "gift" , gift )
69
+ ( gift ) => this . emit ( "gift" , gift ) ,
68
70
) ;
69
71
}
70
72
}
@@ -81,9 +83,11 @@ export class StreamElementsServiceClient extends EventEmitter {
81
83
82
84
this . onTestSubscriber ( ( data ) => {
83
85
if ( data . event . gifted ) {
84
- this . handleSubGift ( data . event . sender , data ,
86
+ this . handleSubGift (
87
+ data . event . sender ,
88
+ data ,
85
89
( subBomb ) => this . emit ( "test:subbomb" , subBomb ) ,
86
- ( gift ) => this . emit ( "test:gift" , gift )
90
+ ( gift ) => this . emit ( "test:gift" , gift ) ,
87
91
) ;
88
92
}
89
93
} ) ;
@@ -186,8 +190,11 @@ export class StreamElementsServiceClient extends EventEmitter {
186
190
} ) ;
187
191
}
188
192
189
- public onSubscriber ( handler : ( data : StreamElementsSubscriberEvent ) => void ) : void {
190
- this . on ( "subscriber" , handler ) ;
193
+ public onSubscriber ( handler : ( data : StreamElementsSubscriberEvent ) => void , includeSubGifts = true ) : void {
194
+ this . on ( "subscriber" , ( data ) => {
195
+ if ( data . data . gifted && ! includeSubGifts ) return ;
196
+ handler ( data ) ;
197
+ } ) ;
191
198
}
192
199
193
200
public onSubscriberBomb ( handler : ( data : StreamElementsSubBombEvent < StreamElementsSubscriberEvent > ) => void ) : void {
@@ -222,8 +229,11 @@ export class StreamElementsServiceClient extends EventEmitter {
222
229
this . on ( "test" , handler ) ;
223
230
}
224
231
225
- public onTestSubscriber ( handler : ( data : StreamElementsTestSubscriberEvent ) => void ) : void {
226
- this . on ( "test:subscriber-latest" , handler ) ;
232
+ public onTestSubscriber ( handler : ( data : StreamElementsTestSubscriberEvent ) => void , includeSubGifts = true ) : void {
233
+ this . on ( "test:subscriber-latest" , ( data ) => {
234
+ if ( data . event . gifted && ! includeSubGifts ) return ;
235
+ handler ( data ) ;
236
+ } ) ;
227
237
}
228
238
229
239
public onTestSubscriberBomb (
@@ -261,13 +271,13 @@ export class StreamElementsServiceClient extends EventEmitter {
261
271
rep . value = { } ;
262
272
}
263
273
264
- this . onSubscriber ( data => rep . value . lastSubscriber = data ) ;
265
- this . onSubscriberBomb ( data => rep . value . lastSubBomb = data ) ;
266
- this . onTip ( data => rep . value . lastTip = data ) ;
267
- this . onCheer ( data => rep . value . lastCheer = data ) ;
268
- this . onGift ( data => rep . value . lastGift = data ) ;
269
- this . onFollow ( data => rep . value . lastFollow = data ) ;
270
- this . onRaid ( data => rep . value . lastRaid = data ) ;
271
- this . onHost ( data => rep . value . lastHost = data ) ;
274
+ this . onSubscriber ( ( data ) => ( rep . value . lastSubscriber = data ) ) ;
275
+ this . onSubscriberBomb ( ( data ) => ( rep . value . lastSubBomb = data ) ) ;
276
+ this . onTip ( ( data ) => ( rep . value . lastTip = data ) ) ;
277
+ this . onCheer ( ( data ) => ( rep . value . lastCheer = data ) ) ;
278
+ this . onGift ( ( data ) => ( rep . value . lastGift = data ) ) ;
279
+ this . onFollow ( ( data ) => ( rep . value . lastFollow = data ) ) ;
280
+ this . onRaid ( ( data ) => ( rep . value . lastRaid = data ) ) ;
281
+ this . onHost ( ( data ) => ( rep . value . lastHost = data ) ) ;
272
282
}
273
283
}
0 commit comments