@@ -152,7 +152,16 @@ public class OBSCommunicator {
152
152
private Callback <TransitionBeginResponse > onTransitionBegin ;
153
153
private Callback <TransitionEndResponse > onTransitionEnd ;
154
154
private Callback <SourceFilterVisibilityChangedResponse > onSourceFilterVisibilityChanged ;
155
+ private Callback <SourceVolumeChangedResponse > onSourceVolumeChanged ;
155
156
private Callback <PreviewSceneChangedResponse > onPreviewSceneChanged ;
157
+ private Callback <MediaEndedResponse > onMediaEnded ;
158
+ private Callback <MediaStartedResponse > onMediaStarted ;
159
+ private Callback <MediaPreviousResponse > onMediaPrevious ;
160
+ private Callback <MediaNextResponse > onMediaNext ;
161
+ private Callback <MediaStoppedResponse > onMediaStopped ;
162
+ private Callback <MediaRestartedResponse > onMediaRestarted ;
163
+ private Callback <MediaPausedResponse > onMediaPaused ;
164
+ private Callback <MediaPlayingResponse > onMediaPlaying ;
156
165
157
166
private GetVersionResponse versionInfo ;
158
167
@@ -197,8 +206,7 @@ public void onConnect(Session session) {
197
206
Future <Void > fut ;
198
207
fut = session .getRemote ().sendStringByFuture (this .gson .toJson (new GetVersionRequest (this )));
199
208
fut .get (2 , TimeUnit .SECONDS );
200
- }
201
- catch (Throwable t ) {
209
+ } catch (Throwable t ) {
202
210
runOnError ("An error occurred while trying to get a session" , t );
203
211
}
204
212
}
@@ -227,32 +235,26 @@ public void onMessage(String msg) {
227
235
228
236
try {
229
237
processIncomingResponse (responseBase , responseType );
230
- }
231
- catch (Throwable t ) {
238
+ } catch (Throwable t ) {
232
239
runOnError ("Failed to process response '" + responseType .getSimpleName () + "' from websocket" , t );
233
240
}
234
- }
235
- else if (jsonObject .has ("update-type" )) {
241
+ } else if (jsonObject .has ("update-type" )) {
236
242
try {
237
243
EventType eventType = EventType .valueOf (jsonObject .get ("update-type" ).getAsString ());
238
244
239
245
try {
240
246
processIncomingEvent (msg , eventType );
241
- }
242
- catch (Throwable t ) {
247
+ } catch (Throwable t ) {
243
248
runOnError ("Failed to execute callback for event: " + eventType , t );
244
249
}
245
- }
246
- catch (IllegalArgumentException ignored ) {
250
+ } catch (IllegalArgumentException ignored ) {
247
251
log .trace ("Unsupported Event received" );
248
252
}
249
253
}
250
- }
251
- else {
254
+ } else {
252
255
throw new IllegalArgumentException ("Received message is not a JsonObject" );
253
256
}
254
- }
255
- catch (Throwable t ) {
257
+ } catch (Throwable t ) {
256
258
runOnError ("Failed to process message from websocket" , t );
257
259
}
258
260
}
@@ -270,8 +272,7 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
270
272
if (authRequiredResponse .isAuthRequired ()) {
271
273
log .info ("Authentication is required." );
272
274
authenticateWithServer (authRequiredResponse .getChallenge (), authRequiredResponse .getSalt ());
273
- }
274
- else {
275
+ } else {
275
276
log .info ("Authentication is not required. You're ready to go!" );
276
277
runOnConnect (versionInfo );
277
278
}
@@ -282,8 +283,7 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
282
283
283
284
if ("ok" .equals (authenticateResponse .getStatus ())) {
284
285
runOnConnect (versionInfo );
285
- }
286
- else {
286
+ } else {
287
287
runOnConnectionFailed ("Failed to authenticate with password. Error: " + authenticateResponse .getError (), null );
288
288
}
289
289
@@ -298,8 +298,7 @@ private void processIncomingResponse(ResponseBase responseBase, Class type) {
298
298
299
299
try {
300
300
callbacks .get (type ).run (responseBase );
301
- }
302
- catch (Throwable t ) {
301
+ } catch (Throwable t ) {
303
302
runOnError ("Failed to execute callback for response: " + type , t );
304
303
}
305
304
}
@@ -324,39 +323,36 @@ private void processIncomingEvent(String msg, EventType eventType) {
324
323
onReplayStopping .run ();
325
324
break ;
326
325
case SwitchScenes :
327
- if (onSwitchScenes != null ) {
326
+ if (onSwitchScenes != null )
328
327
onSwitchScenes .run (this .gson .fromJson (msg , SwitchScenesResponse .class ));
329
- }
330
328
break ;
331
329
case ScenesChanged :
332
- if (onScenesChanged != null ) {
330
+ if (onScenesChanged != null )
333
331
onScenesChanged .run (new Gson ().fromJson (msg , ScenesChangedResponse .class ));
334
- }
335
332
break ;
336
333
case SourceFilterVisibilityChanged :
337
- if (onSourceFilterVisibilityChanged != null ) {
334
+ if (onSourceFilterVisibilityChanged != null )
338
335
onSourceFilterVisibilityChanged .run (this .gson .fromJson (msg , SourceFilterVisibilityChangedResponse .class ));
339
- }
336
+ break ;
337
+ case SourceVolumeChanged :
338
+ if (onSourceVolumeChanged != null )
339
+ onSourceVolumeChanged .run (this .gson .fromJson (msg , SourceVolumeChangedResponse .class ));
340
340
break ;
341
341
case SwitchTransition :
342
- if (onSwitchTransition != null ) {
342
+ if (onSwitchTransition != null )
343
343
onSwitchTransition .run (this .gson .fromJson (msg , SwitchTransitionResponse .class ));
344
- }
345
344
break ;
346
345
case TransitionListChanged :
347
- if (onTransitionListChanged != null ) {
346
+ if (onTransitionListChanged != null )
348
347
onTransitionListChanged .run (this .gson .fromJson (msg , TransitionListChangedResponse .class ));
349
- }
350
348
break ;
351
349
case TransitionBegin :
352
- if (onTransitionBegin != null ) {
350
+ if (onTransitionBegin != null )
353
351
onTransitionBegin .run (this .gson .fromJson (msg , TransitionBeginResponse .class ));
354
- }
355
352
break ;
356
353
case TransitionEnd :
357
- if (onTransitionEnd != null ) {
354
+ if (onTransitionEnd != null )
358
355
onTransitionEnd .run (this .gson .fromJson (msg , TransitionEndResponse .class ));
359
- }
360
356
break ;
361
357
case RecordingStarted :
362
358
if (onRecordingStarted != null )
@@ -375,9 +371,40 @@ private void processIncomingEvent(String msg, EventType eventType) {
375
371
onStreamStopped .run ();
376
372
break ;
377
373
case PreviewSceneChanged :
378
- if (onPreviewSceneChanged != null ) {
374
+ if (onPreviewSceneChanged != null )
379
375
onPreviewSceneChanged .run (this .gson .fromJson (msg , PreviewSceneChangedResponse .class ));
380
- }
376
+ break ;
377
+ case MediaPlaying :
378
+ if (onMediaPlaying != null )
379
+ onMediaPlaying .run (this .gson .fromJson (msg , MediaPlayingResponse .class ));
380
+ break ;
381
+ case MediaPaused :
382
+ if (onMediaPaused != null )
383
+ onMediaPaused .run (this .gson .fromJson (msg , MediaPausedResponse .class ));
384
+ break ;
385
+ case MediaRestarted :
386
+ if (onMediaRestarted != null )
387
+ onMediaRestarted .run (this .gson .fromJson (msg , MediaRestartedResponse .class ));
388
+ break ;
389
+ case MediaStopped :
390
+ if (onMediaStopped != null )
391
+ onMediaStopped .run (this .gson .fromJson (msg , MediaStoppedResponse .class ));
392
+ break ;
393
+ case MediaNext :
394
+ if (onMediaNext != null )
395
+ onMediaNext .run (this .gson .fromJson (msg , MediaNextResponse .class ));
396
+ break ;
397
+ case MediaPrevious :
398
+ if (onMediaPrevious != null )
399
+ onMediaPrevious .run (this .gson .fromJson (msg , MediaPreviousResponse .class ));
400
+ break ;
401
+ case MediaStarted :
402
+ if (onMediaStarted != null )
403
+ onMediaStarted .run (this .gson .fromJson (msg , MediaStartedResponse .class ));
404
+ break ;
405
+ case MediaEnded :
406
+ if (onMediaEnded != null )
407
+ onMediaEnded .run (this .gson .fromJson (msg , MediaEndedResponse .class ));
381
408
break ;
382
409
}
383
410
}
@@ -404,8 +431,7 @@ private String generateAuthenticationResponseString(String challenge, String sal
404
431
MessageDigest digest ;
405
432
try {
406
433
digest = MessageDigest .getInstance ("SHA-256" );
407
- }
408
- catch (NoSuchAlgorithmException e ) {
434
+ } catch (NoSuchAlgorithmException e ) {
409
435
runOnConnectionFailed ("Failed to perform password authentication with server" , null );
410
436
return null ;
411
437
}
@@ -431,7 +457,9 @@ public void registerOnDisconnect(VoidCallback onDisconnect) {
431
457
this .onDisconnect = onDisconnect ;
432
458
}
433
459
434
- public void registerOnClose (CloseCallback closeCallback ) { this .onClose = closeCallback ; }
460
+ public void registerOnClose (CloseCallback closeCallback ) {
461
+ this .onClose = closeCallback ;
462
+ }
435
463
436
464
public void registerOnConnectionFailed (StringCallback onConnectionFailed ) {
437
465
this .onConnectionFailed = onConnectionFailed ;
@@ -469,6 +497,10 @@ public void registerOnSourceFilterVisibilityChanged(Callback<SourceFilterVisibil
469
497
this .onSourceFilterVisibilityChanged = onSourceFilterVisibilityChanged ;
470
498
}
471
499
500
+ public void registerOnSourceVolumeChanged (Callback <SourceVolumeChangedResponse > onSourceVolumeChanged ) {
501
+ this .onSourceVolumeChanged = onSourceVolumeChanged ;
502
+ }
503
+
472
504
public void registerOnSwitchTransition (Callback <SwitchTransitionResponse > onSwitchTransition ) {
473
505
this .onSwitchTransition = onSwitchTransition ;
474
506
}
@@ -501,6 +533,38 @@ public void registerOnStreamStopped(VoidCallback onStreamStopped) {
501
533
this .onStreamStopped = onStreamStopped ;
502
534
}
503
535
536
+ public void registerOnMediaPlaying (Callback <MediaPlayingResponse > onMediaPlaying ) {
537
+ this .onMediaPlaying = onMediaPlaying ;
538
+ }
539
+
540
+ public void registerOnMediaPaused (Callback <MediaPausedResponse > onMediaPaused ) {
541
+ this .onMediaPaused = onMediaPaused ;
542
+ }
543
+
544
+ public void registerOnMediaRestarted (Callback <MediaRestartedResponse > onMediaRestarted ) {
545
+ this .onMediaRestarted = onMediaRestarted ;
546
+ }
547
+
548
+ public void registerOnMediaStopped (Callback <MediaStoppedResponse > onMediaStopped ) {
549
+ this .onMediaStopped = onMediaStopped ;
550
+ }
551
+
552
+ public void registerOnMediaNext (Callback <MediaNextResponse > onMediaNext ) {
553
+ this .onMediaNext = onMediaNext ;
554
+ }
555
+
556
+ public void registerOnMediaPrevious (Callback <MediaPreviousResponse > onMediaPrevious ) {
557
+ this .onMediaPrevious = onMediaPrevious ;
558
+ }
559
+
560
+ public void registerOnMediaStarted (Callback <MediaStartedResponse > onMediaStarted ) {
561
+ this .onMediaStarted = onMediaStarted ;
562
+ }
563
+
564
+ public void registerOnMediaEnded (Callback <MediaEndedResponse > onMediaEnded ) {
565
+ this .onMediaEnded = onMediaEnded ;
566
+ }
567
+
504
568
public void getScenes (Callback <GetSceneListResponse > callback ) {
505
569
session .getRemote ().sendStringByFuture (this .gson .toJson (new GetSceneListRequest (this )));
506
570
callbacks .put (GetSceneListResponse .class , callback );
@@ -803,8 +867,7 @@ private void runOnError(String message, Throwable throwable) {
803
867
804
868
try {
805
869
onError .run (message , throwable );
806
- }
807
- catch (Throwable t ) {
870
+ } catch (Throwable t ) {
808
871
log .error ("Unable to run onError callback" , t );
809
872
}
810
873
}
@@ -818,8 +881,7 @@ private void runOnConnectionFailed(String message, Throwable throwable) {
818
881
819
882
try {
820
883
onConnectionFailed .run (message );
821
- }
822
- catch (Throwable t ) {
884
+ } catch (Throwable t ) {
823
885
log .error ("Unable to run OnConnectionFailed callback" , t );
824
886
}
825
887
}
@@ -833,8 +895,7 @@ private void runOnConnect(GetVersionResponse versionInfo) {
833
895
834
896
try {
835
897
onConnect .run (versionInfo );
836
- }
837
- catch (Throwable t ) {
898
+ } catch (Throwable t ) {
838
899
log .error ("Unable to run OnConnect callback" , t );
839
900
}
840
901
}
@@ -857,7 +918,7 @@ void runOnDisconnect() {
857
918
private void runOnClosed (int statusCode , String reason ) {
858
919
log .debug ("Running onClose with statusCode " + statusCode + " and reason: " + reason );
859
920
860
- if (this .onClose == null ) {
921
+ if (this .onClose == null ) {
861
922
log .debug ("No onClose was registered." );
862
923
return ;
863
924
}
0 commit comments