@@ -871,9 +871,8 @@ def start(self, host, port):
871871 self ._clientSupportsTLS = False
872872
873873 def retry (retries ):
874- self ._lastGlobalUpdate = None
875- self .ui .setSSLMode (False )
876- self .playlistMayNeedRestoring = True
874+ # Use shared state reset method
875+ self ._performRetryStateReset ()
877876 if retries == 0 :
878877 self .onDisconnect ()
879878 if retries > constants .RECONNECT_RETRIES :
@@ -882,8 +881,6 @@ def retry(retries):
882881 reactor .callLater (0.1 , self .stop , True )
883882 return None
884883
885- self .ui .showMessage (getMessage ("reconnection-attempt-notification" ))
886- self .reconnecting = True
887884 return (0.1 * (2 ** min (retries , 5 )))
888885
889886 self ._reconnectingService = ClientService (self ._endpoint , self .protocolFactory , retryPolicy = retry )
@@ -920,6 +917,42 @@ def stop(self, promptForAction=False):
920917 if promptForAction :
921918 self .ui .promptFor (getMessage ("enter-to-exit-prompt" ))
922919
920+ def _performRetryStateReset (self ):
921+ """
922+ Shared method to reset connection state for both automatic and manual retries.
923+ This contains the common logic from the original retry function.
924+ """
925+ self ._lastGlobalUpdate = None
926+ self .ui .setSSLMode (False )
927+ self .playlistMayNeedRestoring = True
928+ self .ui .showMessage (getMessage ("reconnection-attempt-notification" ))
929+ self .reconnecting = True
930+
931+ def manualReconnect (self ):
932+ """
933+ Trigger a manual reconnection by forcing the retry mechanism.
934+ This performs the same steps as the automatic retry function.
935+ """
936+ if not self ._running or not hasattr (self , '_reconnectingService' ):
937+ self .ui .showErrorMessage (getMessage ("connection-failed-notification" ))
938+ return
939+
940+ from twisted .internet import reactor
941+
942+ def performReconnect ():
943+ # Apply the shared state reset logic
944+ self ._performRetryStateReset ()
945+
946+ # Stop current service and restart it to trigger reconnection
947+ if self ._reconnectingService and self ._reconnectingService .running :
948+ self ._reconnectingService .stopService ()
949+
950+ # Restart the service to trigger a reconnection attempt
951+ self ._reconnectingService .startService ()
952+
953+ # Use callLater for threading purposes as suggested
954+ reactor .callLater (0.1 , performReconnect )
955+
923956 def requireServerFeature (featureRequired ):
924957 def requireServerFeatureDecorator (f ):
925958 @wraps (f )
0 commit comments