-
Notifications
You must be signed in to change notification settings - Fork 524
Open
Description
So errr this is an interesting one. I was testing a release build of my app on android and for some reason in release build, the PeerDisconnectedEvent does not trigger at all. In the debug build it works. I also target Windows and Linux with the exact same shared code and it works in release mode as well. So I'm not exactly sure if it's my build configuration or if something is being trimmed or if I'm being an idiot. I also apparently can't get the logcat to work in the release mode for some reason so I've just been trying to manually debug by removing bits of code and recompiling.
constructor
public VoiceCraftClient() : base(0, new VoiceCraftWorld())
{
_listener = new EventBasedNetListener();
_netManager = new NetManager(_listener)
{
AutoRecycle = true,
IPv6Enabled = false,
UnconnectedMessagesEnabled = true
};
_encoder = new OpusEncoder(Constants.SampleRate, Constants.Channels,
OpusPredefinedValues.OPUS_APPLICATION_VOIP);
_encoder.SetPacketLostPercent(20); //Expected packet loss, might make this change over time later.
_encoder.SetBitRate(32000);
//Setup Systems.
_audioSystem = new AudioSystem(this, World);
//Setup Listeners
_listener.PeerDisconnectedEvent += OnDisconnectedEvent;
_listener.ConnectionRequestEvent += OnConnectionRequestEvent;
_listener.NetworkReceiveEvent += OnNetworkReceiveEvent;
_listener.NetworkReceiveUnconnectedEvent += OnNetworkReceiveUnconnectedEvent;
//Internal Listeners
OnMuteUpdated += OnClientMuteUpdated;
OnDeafenUpdated += OnClientDeafenUpdated;
//Start
_netManager.Start();
}Connect Function
public async Task ConnectAsync(Guid userGuid, Guid serverUserGuid, string ip, int port, string locale)
{
ThrowIfDisposed();
if (ConnectionState != VcConnectionState.Disconnected)
throw new InvalidOperationException("This client is already connected or is connecting to a server!");
_speakingState = false;
_requestIds.Clear();
var loginPacket = PacketPool<VcLoginRequestPacket>.GetPacket();
loginPacket.Set(Guid.NewGuid(), userGuid, serverUserGuid, locale, Version);
try
{
lock (_dataWriter)
{
_dataWriter.Reset();
loginPacket.Serialize(_dataWriter);
ConnectionState = VcConnectionState.Connecting;
_serverPeer = _netManager.Connect(ip, port, _dataWriter) ??
throw new InvalidOperationException("A connection request is awaiting!");
}
_ = await GetResponseAsync<VcAcceptResponsePacket>(loginPacket.RequestId,
TimeSpan.FromSeconds(8));
ConnectionState = VcConnectionState.Connected;
OnConnected?.Invoke();
}
catch
{
Disconnect("VoiceCraft.DisconnectReason.Error");
}
finally
{
PacketPool<VcLoginRequestPacket>.Return(loginPacket);
}
}Disconnect Event Handling
private void OnDisconnectedEvent(NetPeer peer, DisconnectInfo info)
{
if (!Equals(peer, _serverPeer)) return;
try
{
World.ClearEntities();
VcPacketType packetId;
switch (info.Reason)
{
case DisconnectReason.ConnectionRejected when !info.AdditionalData.IsNull:
packetId = (VcPacketType)info.AdditionalData.GetByte();
if (packetId != VcPacketType.DenyResponse) break;
var denyPacket = PacketPool<VcDenyResponsePacket>.GetPacket();
OnDisconnected?.Invoke(denyPacket.Reason);
break;
case DisconnectReason.RemoteConnectionClose when !info.AdditionalData.IsNull:
packetId = (VcPacketType)info.AdditionalData.GetByte();
if (packetId != VcPacketType.LogoutRequest) break;
var logoutPacket = PacketPool<VcLogoutRequestPacket>.GetPacket();
OnDisconnected?.Invoke(logoutPacket.Reason);
break;
case DisconnectReason.DisconnectPeerCalled:
OnDisconnected?.Invoke("VoiceCraft.DisconnectReason.Manual");
return;
}
OnDisconnected?.Invoke(info.Reason.ToString());
}
catch
{
OnDisconnected?.Invoke(info.Reason.ToString());
}
finally
{
ConnectionState = VcConnectionState.Disconnected;
}
}Metadata
Metadata
Assignees
Labels
No labels