Skip to content

Commit 7e105bf

Browse files
committed
expose ExpectedExceptions for xamarin to automatically reconnect
1 parent 317473b commit 7e105bf

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/SocketIOClient/SocketIO.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public Uri ServerUri
9696

9797
public Func<IClientWebSocket> ClientWebSocketProvider { get; set; }
9898

99+
public List<Type> ExpectedExceptions { get; private set; }
100+
99101
int _packetId;
100102
Dictionary<int, Action<SocketIOResponse>> _ackHandlers;
101103
List<OnAnyHandler> _onAnyHandlers;
@@ -151,6 +153,13 @@ private void Initialize()
151153
_connectionTokenSorce = new CancellationTokenSource();
152154
HttpClient = new HttpClient();
153155
ClientWebSocketProvider = () => new DefaultClientWebSocket();
156+
ExpectedExceptions = new List<Type>
157+
{
158+
typeof(TimeoutException),
159+
typeof(WebSocketException),
160+
typeof(HttpRequestException),
161+
typeof(OperationCanceledException)
162+
};
154163
}
155164

156165
internal static bool IsNamespaceDefault(string @namespace)
@@ -206,7 +215,7 @@ public async Task ConnectAsync()
206215
}
207216
catch (Exception e)
208217
{
209-
if (e is TimeoutException || e is WebSocketException || e is HttpRequestException || e is TimeoutException)
218+
if (ExpectedExceptions.Contains(e.GetType()))
210219
{
211220
if (!Options.Reconnection)
212221
{
@@ -645,7 +654,7 @@ private async void InvokeDisconnect(string reason)
645654
//In the this cases (explicit disconnection), the client will not try to reconnect and you need to manually call socket.connect().
646655
if (Options.Reconnection)
647656
{
648-
_ = ConnectAsync().ConfigureAwait(false);
657+
await ConnectAsync().ConfigureAwait(false);
649658
}
650659
}
651660
}

0 commit comments

Comments
 (0)