✨ added reason of disconnect at callback
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023 Eduard Kargin <kargin.eduard@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public enum DisconnectReason
|
||||
{
|
||||
MANUAL,
|
||||
TIMEOUT,
|
||||
}
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface INetworkConnection: IRagonConnection
|
||||
@@ -23,7 +25,7 @@ public interface INetworkConnection: IRagonConnection
|
||||
public INetworkChannel Unreliable { get; }
|
||||
public Action<byte[]> OnData { get; set; }
|
||||
public Action OnConnected { get; set; }
|
||||
public Action<DisconnectReason> OnDisconnected { get; set; }
|
||||
public Action<RagonDisconnect> OnDisconnected { get; set; }
|
||||
public ulong BytesSent { get; }
|
||||
public ulong BytesReceived { get; }
|
||||
public int Ping { get; }
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client;
|
||||
|
||||
public interface IRagonConnectionListener
|
||||
{
|
||||
void OnConnected(RagonClient client);
|
||||
void OnDisconnected(RagonClient client);
|
||||
void OnDisconnected(RagonClient client, RagonDisconnect reason);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ namespace Ragon.Client
|
||||
_room.Cleanup();
|
||||
_connection.Disconnect();
|
||||
|
||||
OnDisconnected(DisconnectReason.MANUAL);
|
||||
OnDisconnected(RagonDisconnect.MANUAL);
|
||||
}
|
||||
|
||||
public void Update(float dt)
|
||||
@@ -181,11 +181,11 @@ namespace Ragon.Client
|
||||
_status = RagonStatus.CONNECTED;
|
||||
}
|
||||
|
||||
private void OnDisconnected(DisconnectReason reason)
|
||||
private void OnDisconnected(RagonDisconnect reason)
|
||||
{
|
||||
RagonLog.Trace($"Disconnected: {reason}");
|
||||
|
||||
_listenerList.OnDisconnected();
|
||||
_listenerList.OnDisconnected(reason);
|
||||
_status = RagonStatus.DISCONNECTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using Ragon.Protocol;
|
||||
|
||||
namespace Ragon.Client
|
||||
{
|
||||
internal class RagonListenerList
|
||||
@@ -210,10 +212,10 @@ namespace Ragon.Client
|
||||
listener.OnConnected(_client);
|
||||
}
|
||||
|
||||
public void OnDisconnected()
|
||||
public void OnDisconnected(RagonDisconnect disconnect)
|
||||
{
|
||||
foreach (var listener in _connectionListeners)
|
||||
listener.OnDisconnected(_client);
|
||||
listener.OnDisconnected(_client, disconnect);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user