@@ -52,6 +52,9 @@ public class ServerEventsClient implements Closeable {
5252
5353 protected ServerEventConnectCallback onConnect ;
5454 protected ServerEventMessageCallback onMessage ;
55+ protected ServerEventJoinCallback onJoin ;
56+ protected ServerEventLeaveCallback onLeave ;
57+ protected ServerEventUpdateCallback onUpdate ;
5558 protected ServerEventMessageCallback onCommand ;
5659 protected ServerEventMessageCallback onHeartbeat ;
5760 protected ExceptionCallback onException ;
@@ -156,6 +159,21 @@ public ServerEventsClient setOnMessage(ServerEventMessageCallback onMessage) {
156159 return this ;
157160 }
158161
162+ public ServerEventsClient setOnJoin (ServerEventJoinCallback onJoin ) {
163+ this .onJoin = onJoin ;
164+ return this ;
165+ }
166+
167+ public ServerEventsClient setOnLeave (ServerEventLeaveCallback onLeave ) {
168+ this .onLeave = onLeave ;
169+ return this ;
170+ }
171+
172+ public ServerEventsClient setOnUpdate (ServerEventUpdateCallback onUpdate ) {
173+ this .onUpdate = onUpdate ;
174+ return this ;
175+ }
176+
159177 public ServerEventsClient setOnCommand (ServerEventMessageCallback onCommand ) {
160178 this .onCommand = onCommand ;
161179 return this ;
@@ -377,6 +395,42 @@ private synchronized void internalStop() {
377395 stopBackgroundThread ();
378396 }
379397
398+ private void onJoinReceived (ServerEventJoin e ) {
399+ if (Log .isDebugEnabled ())
400+ Log .d ("[SSE-CLIENT] OnJoinReceived: ("
401+ + e .getClass ().getSimpleName () + ") #"
402+ + e .getEventId () + " on #"
403+ + getConnectionDisplayName () + " ("
404+ + Utils .join (channels , "," ) + ")" );
405+
406+ if (onJoin != null )
407+ onJoin .execute (e );
408+ }
409+
410+ private void onLeaveReceived (ServerEventLeave e ) {
411+ if (Log .isDebugEnabled ())
412+ Log .d ("[SSE-CLIENT] OnLeaveReceived: ("
413+ + e .getClass ().getSimpleName () + ") #"
414+ + e .getEventId () + " on #"
415+ + getConnectionDisplayName () + " ("
416+ + Utils .join (channels , "," ) + ")" );
417+
418+ if (onLeave != null )
419+ onLeave .execute (e );
420+ }
421+
422+ private void onUpdateReceived (ServerEventUpdate e ) {
423+ if (Log .isDebugEnabled ())
424+ Log .d ("[SSE-CLIENT] OnUpdateReceived: ("
425+ + e .getClass ().getSimpleName () + ") #"
426+ + e .getEventId () + " on #"
427+ + getConnectionDisplayName () + " ("
428+ + Utils .join (channels , "," ) + ")" );
429+
430+ if (onUpdate != null )
431+ onUpdate .execute (e );
432+ }
433+
380434 private void onCommandReceived (ServerEventMessage e ) {
381435 if (Log .isDebugEnabled ())
382436 Log .d ("[SSE-CLIENT] OnCommandReceived: ("
@@ -570,15 +624,24 @@ protected void processOnConnectMessage(ServerEventMessage e) {
570624 }
571625
572626 protected void processOnJoinMessage (ServerEventMessage e ) {
573- onCommandReceived (new ServerEventJoin ().populate (e , JsonUtils .toJsonObject (e .getJson ())));
627+ ServerEventJoin m = new ServerEventJoin ();
628+ m .populate (e , JsonUtils .toJsonObject (e .getJson ()));
629+ onJoinReceived (m );
630+ onCommandReceived (m );
574631 }
575632
576633 protected void processOnLeaveMessage (ServerEventMessage e ) {
577- onCommandReceived (new ServerEventLeave ().populate (e , JsonUtils .toJsonObject (e .getJson ())));
634+ ServerEventLeave m = new ServerEventLeave ();
635+ m .populate (e , JsonUtils .toJsonObject (e .getJson ()));
636+ onLeaveReceived (m );
637+ onCommandReceived (m );
578638 }
579639
580640 protected void processOnUpdateMessage (ServerEventMessage e ) {
581- onCommandReceived (new ServerEventUpdate ().populate (e , JsonUtils .toJsonObject (e .getJson ())));
641+ ServerEventUpdate m = new ServerEventUpdate ();
642+ m .populate (e , JsonUtils .toJsonObject (e .getJson ()));
643+ onUpdateReceived (m );
644+ onCommandReceived (m );
582645 }
583646
584647 protected void processOnHeartbeatMessage (ServerEventMessage e ) {
0 commit comments