@@ -6,24 +6,16 @@ import {
6
6
StreamElementsFollowEvent ,
7
7
StreamElementsHostEvent ,
8
8
StreamElementsRaidEvent ,
9
- StreamElementsReplayEvent ,
10
9
StreamElementsSubBombEvent ,
11
10
StreamElementsSubscriberEvent ,
12
- StreamElementsTestCheerEvent ,
13
- StreamElementsTestEvent ,
14
- StreamElementsTestFollowEvent ,
15
- StreamElementsTestHostEvent ,
16
- StreamElementsTestRaidEvent ,
17
- StreamElementsTestSubscriberEvent ,
18
- StreamElementsTestTipEvent ,
19
11
StreamElementsTipEvent ,
20
12
} from "./StreamElementsEvent" ;
21
13
import { EventEmitter } from "events" ;
22
14
import NodeCG from "@nodecg/types" ;
23
15
24
16
export interface StreamElementsReplicant {
25
17
lastSubscriber ?: StreamElementsSubscriberEvent ;
26
- lastSubBomb ?: StreamElementsSubBombEvent < StreamElementsSubscriberEvent > ;
18
+ lastSubBomb ?: StreamElementsSubBombEvent ;
27
19
lastTip ?: StreamElementsTipEvent ;
28
20
lastCheer ?: StreamElementsCheerEvent ;
29
21
lastGift ?: StreamElementsSubscriberEvent ;
@@ -37,14 +29,14 @@ export interface StreamElementsReplicant {
37
29
*/
38
30
interface SubBomb {
39
31
timeout : NodeJS . Timeout ;
40
- subs : Array < StreamElementsSubscriberEvent | StreamElementsTestSubscriberEvent > ;
32
+ subs : Array < StreamElementsSubscriberEvent > ;
41
33
}
42
34
43
35
export class StreamElementsServiceClient extends EventEmitter {
44
36
private socket : SocketIOClient . Socket ;
45
37
private subBombDetectionMap : Map < string , SubBomb > = new Map ( ) ;
46
38
47
- constructor ( private jwtToken : string , private handleTestEvents : boolean ) {
39
+ constructor ( private jwtToken : string ) {
48
40
super ( ) ;
49
41
}
50
42
@@ -73,32 +65,12 @@ export class StreamElementsServiceClient extends EventEmitter {
73
65
}
74
66
this . emit ( data . type , data ) ;
75
67
} ) ;
76
-
77
- if ( this . handleTestEvents ) {
78
- this . onTestEvent ( ( data : StreamElementsTestEvent ) => {
79
- if ( data . listener ) {
80
- this . emit ( "test" , data ) ;
81
- this . emit ( "test:" + data . listener , data ) ;
82
- }
83
- } ) ;
84
-
85
- this . onTestSubscriber ( ( data ) => {
86
- if ( data . event . gifted ) {
87
- this . handleSubGift (
88
- data . event . sender ,
89
- data ,
90
- ( subBomb ) => this . emit ( "test:subbomb" , subBomb ) ,
91
- ( gift ) => this . emit ( "test:gift" , gift ) ,
92
- ) ;
93
- }
94
- } ) ;
95
- }
96
68
}
97
69
98
- private handleSubGift < T extends StreamElementsSubscriberEvent | StreamElementsTestSubscriberEvent > (
70
+ private handleSubGift < T extends StreamElementsSubscriberEvent > (
99
71
subGifter : string | undefined ,
100
72
gift : T ,
101
- handlerSubBomb : ( data : StreamElementsSubBombEvent < T > ) => void ,
73
+ handlerSubBomb : ( data : StreamElementsSubBombEvent ) => void ,
102
74
handlerGift : ( data : T ) => void ,
103
75
) {
104
76
const gifter = subGifter ?? "anonymous" ;
@@ -116,6 +88,10 @@ export class StreamElementsServiceClient extends EventEmitter {
116
88
subscribers : subBomb . subs as T [ ] ,
117
89
} ;
118
90
handlerSubBomb ( subBombEvent ) ;
91
+
92
+ subBomb . subs . forEach ( sub => {
93
+ sub . data . isFromSubBomb = true ;
94
+ } ) ;
119
95
}
120
96
121
97
subBomb . subs . forEach ( handlerGift ) ;
@@ -183,36 +159,14 @@ export class StreamElementsServiceClient extends EventEmitter {
183
159
} ) ;
184
160
}
185
161
186
- private onTestEvent ( handler : ( data : StreamElementsTestEvent ) => void ) : void {
187
- this . socket . on ( "event:test" , ( data : StreamElementsTestEvent ) => {
188
- if ( data ) {
189
- handler ( data ) ;
190
- }
191
- } ) ;
192
-
193
- this . socket . on ( "event:update" , ( data : StreamElementsReplayEvent ) => {
194
- // event:update is all replays of previous real events.
195
- // Because the structure is similar to the test events and just the keys in the root element
196
- // are named differently we rename those to align with the naming in the test events
197
- // and handle it as a test event from here on.
198
- if ( data ) {
199
- handler ( {
200
- event : data . data ,
201
- listener : data . name ,
202
- provider : data . provider ,
203
- } as unknown as StreamElementsTestEvent ) ;
204
- }
205
- } ) ;
206
- }
207
-
208
162
public onSubscriber ( handler : ( data : StreamElementsSubscriberEvent ) => void , includeSubGifts = true ) : void {
209
163
this . on ( "subscriber" , ( data ) => {
210
164
if ( data . data . gifted && ! includeSubGifts ) return ;
211
165
handler ( data ) ;
212
166
} ) ;
213
167
}
214
168
215
- public onSubscriberBomb ( handler : ( data : StreamElementsSubBombEvent < StreamElementsSubscriberEvent > ) => void ) : void {
169
+ public onSubscriberBomb ( handler : ( data : StreamElementsSubBombEvent ) => void ) : void {
216
170
this . on ( "subbomb" , handler ) ;
217
171
}
218
172
@@ -240,47 +194,6 @@ export class StreamElementsServiceClient extends EventEmitter {
240
194
this . on ( "host" , handler ) ;
241
195
}
242
196
243
- public onTest ( handler : ( data : StreamElementsEvent ) => void ) : void {
244
- this . on ( "test" , handler ) ;
245
- }
246
-
247
- public onTestSubscriber ( handler : ( data : StreamElementsTestSubscriberEvent ) => void , includeSubGifts = true ) : void {
248
- this . on ( "test:subscriber-latest" , ( data ) => {
249
- if ( data . event . gifted && ! includeSubGifts ) return ;
250
- handler ( data ) ;
251
- } ) ;
252
- }
253
-
254
- public onTestSubscriberBomb (
255
- handler : ( data : StreamElementsSubBombEvent < StreamElementsTestSubscriberEvent > ) => void ,
256
- ) : void {
257
- this . on ( "test:subbomb" , handler ) ;
258
- }
259
-
260
- public onTestGift ( handler : ( data : StreamElementsTestSubscriberEvent ) => void ) : void {
261
- this . on ( "test:gift" , handler ) ;
262
- }
263
-
264
- public onTestCheer ( handler : ( data : StreamElementsTestCheerEvent ) => void ) : void {
265
- this . on ( "test:cheer-latest" , handler ) ;
266
- }
267
-
268
- public onTestFollow ( handler : ( data : StreamElementsTestFollowEvent ) => void ) : void {
269
- this . on ( "test:follower-latest" , handler ) ;
270
- }
271
-
272
- public onTestRaid ( handler : ( data : StreamElementsTestRaidEvent ) => void ) : void {
273
- this . on ( "test:raid-latest" , handler ) ;
274
- }
275
-
276
- public onTestHost ( handler : ( data : StreamElementsTestHostEvent ) => void ) : void {
277
- this . on ( "test:host-latest" , handler ) ;
278
- }
279
-
280
- public onTestTip ( handler : ( data : StreamElementsTestTipEvent ) => void ) : void {
281
- this . on ( "test:tip-latest" , handler ) ;
282
- }
283
-
284
197
public setupReplicant ( rep : NodeCG . ServerReplicant < StreamElementsReplicant > ) : void {
285
198
if ( rep . value === undefined ) {
286
199
rep . value = { } ;
0 commit comments