Skip to content

Commit 1c85927

Browse files
committed
fix OnPing
1 parent 80018b7 commit 1c85927

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/SocketIOClient/SocketIO.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ public Uri ServerUri
101101
List<OnAnyHandler> _onAnyHandlers;
102102
Dictionary<string, Action<SocketIOResponse>> _eventHandlers;
103103
CancellationTokenSource _connectionTokenSorce;
104-
DateTime _pingTime;
105104
double _reconnectionDelay;
106105

107106

@@ -169,7 +168,8 @@ private void CreateRouterIfNull()
169168
Namespace = Namespace,
170169
Path = Options.Path,
171170
ServerUri = ServerUri,
172-
JsonSerializer = JsonSerializer
171+
JsonSerializer = JsonSerializer,
172+
ConnectionTimeout = Options.ConnectionTimeout
173173
};
174174
if (Options.Query != null)
175175
{
@@ -206,7 +206,7 @@ public async Task ConnectAsync()
206206
}
207207
catch (Exception e)
208208
{
209-
if (e is TimeoutException || e is WebSocketException || e is HttpRequestException)
209+
if (e is TimeoutException || e is WebSocketException || e is HttpRequestException || e is TimeoutException)
210210
{
211211
if (!Options.Reconnection)
212212
{
@@ -247,9 +247,10 @@ private async void PingHandler()
247247
{
248248
try
249249
{
250-
_pingTime = DateTime.Now;
250+
OnPing?.Invoke(this, EventArgs.Empty);
251+
DateTime pingTime = DateTime.Now;
251252
await Router.SendAsync(new PongMessage(), CancellationToken.None).ConfigureAwait(false);
252-
OnPong?.Invoke(this, DateTime.Now - _pingTime);
253+
OnPong?.Invoke(this, DateTime.Now - pingTime);
253254
}
254255
catch (Exception e)
255256
{
@@ -258,11 +259,6 @@ private async void PingHandler()
258259
}
259260
}
260261

261-
private void PongHandler()
262-
{
263-
OnPong?.Invoke(this, DateTime.Now - _pingTime);
264-
}
265-
266262
private void ConnectedHandler(ConnectedMessage msg)
267263
{
268264
Id = msg.Sid;
@@ -380,7 +376,7 @@ private void OnMessageReceived(IMessage msg)
380376
PingHandler();
381377
break;
382378
case MessageType.Pong:
383-
PongHandler();
379+
//PongHandler();
384380
break;
385381
case MessageType.Connected:
386382
ConnectedHandler(msg as ConnectedMessage);

src/SocketIOClient/SocketIOOptions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public sealed class SocketIOOptions
77
{
88
public SocketIOOptions()
99
{
10-
RandomizationFactor = new Random().NextDouble();
10+
RandomizationFactor = 0.5;
1111
ReconnectionDelay = 1000;
1212
ReconnectionDelayMax = 5000;
1313
ReconnectionAttempts = int.MaxValue;
@@ -21,7 +21,7 @@ public SocketIOOptions()
2121

2222
public TimeSpan ConnectionTimeout { get; set; }
2323

24-
public Dictionary<string, string> Query { get; set; }
24+
public IEnumerable<KeyValuePair<string, string>> Query { get; set; }
2525

2626
/// <summary>
2727
/// Whether to allow reconnection if accidentally disconnected

0 commit comments

Comments
 (0)