@@ -15,15 +15,12 @@ const reconnectErrors = [
1515export default ( ) => {
1616 let updatingToken = false ;
1717 const [ error , setError ] = useState < 'connecting' | string > ( '' ) ;
18- const [ transfer , setTransfer ] = useState < boolean > ( false ) ;
1918 const { connected, instance } = ServerContext . useStoreState ( state => state . socket ) ;
2019 const uuid = ServerContext . useStoreState ( state => state . server . data ?. uuid ) ;
2120 const setServerStatus = ServerContext . useStoreActions ( actions => actions . status . setServerStatus ) ;
2221 const { setInstance, setConnectionState } = ServerContext . useStoreActions ( actions => actions . socket ) ;
2322
24- const connect = ( uuid : string , transfer = false ) => {
25- setTransfer ( transfer ) ;
26-
23+ const connect = ( uuid : string ) => {
2724 const socket = new Websocket ( ) ;
2825
2926 socket . on ( 'auth success' , ( ) => setConnectionState ( true ) ) ;
@@ -52,21 +49,12 @@ export default () => {
5249 } ) ;
5350
5451 socket . on ( 'transfer status' , ( status : string ) => {
55- if ( status === 'success' ) {
56- setTransfer ( false ) ;
52+ if ( status === 'starting' || status === 'success' ) {
5753 return ;
5854 }
5955
60- if ( status === 'starting' ) {
61- return ;
62- }
63-
64- // This doesn't use the `setTransfer` hook as it doesn't want to work properly in this context,
65- // and causes all kinds of fuckery with the websocket.
66- let transfer = false ;
67- if ( status === 'archived' ) {
68- transfer = true ;
69- }
56+ // Force a reconnection to the websocket which will connect us
57+ // to the target node instead of the source node.
7058
7159 // Close the current websocket connection.
7260 socket . close ( ) ;
@@ -75,10 +63,10 @@ export default () => {
7563 setConnectionState ( false ) ;
7664 setInstance ( null ) ;
7765
78- connect ( uuid , transfer ) ;
66+ connect ( uuid ) ;
7967 } ) ;
8068
81- getWebsocketToken ( uuid , transfer )
69+ getWebsocketToken ( uuid )
8270 . then ( data => {
8371 // Connect and then set the authentication token.
8472 socket . setToken ( data . token ) . connect ( data . socket ) ;
@@ -93,7 +81,7 @@ export default () => {
9381 if ( updatingToken ) return ;
9482
9583 updatingToken = true ;
96- getWebsocketToken ( uuid , transfer )
84+ getWebsocketToken ( uuid )
9785 . then ( data => socket . setToken ( data . token , true ) )
9886 . catch ( error => console . error ( error ) )
9987 . then ( ( ) => {
0 commit comments