-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Expose ConnectionId on .NET Client #8668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ public partial class HubConnection | |
private long _nextActivationSendPing; | ||
private bool _disposed; | ||
private bool _hasInherentKeepAlive; | ||
private string _connectionId; | ||
|
||
private CancellationToken _uploadStreamToken; | ||
|
||
|
@@ -116,6 +117,13 @@ public partial class HubConnection | |
/// </summary> | ||
public TimeSpan HandshakeTimeout { get; set; } = DefaultHandshakeTimeout; | ||
|
||
/// <summary> | ||
/// Gets the connection's current Id. This value will be cleared when the connection is stopped and will have a new value every time the connection is (re)established. | ||
/// This value will be null if the negotiation step is skipped via HttpConnectionOptions or if the WebSockets transport is explicitly specified because the | ||
/// client skips negotiation in that case as well. | ||
/// </summary> | ||
public string ConnectionId => _connectionId; | ||
|
||
/// <summary> | ||
/// Indicates the state of the <see cref="HubConnection"/> to the server. | ||
/// </summary> | ||
|
@@ -338,6 +346,7 @@ private async Task StartAsyncCore(CancellationToken cancellationToken) | |
|
||
// Start the connection | ||
var connection = await _connectionFactory.ConnectAsync(_protocol.TransferFormat); | ||
_connectionId = connection.ConnectionId; | ||
var startingConnectionState = new ConnectionState(connection, this); | ||
_hasInherentKeepAlive = connection.Features.Get<IConnectionInherentKeepAliveFeature>()?.HasInherentKeepAlive ?? false; | ||
|
||
|
@@ -405,6 +414,8 @@ private async Task StopAsyncCore(bool disposing) | |
(_serviceProvider as IDisposable)?.Dispose(); | ||
_disposed = true; | ||
} | ||
|
||
_connectionId = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if we care about this, lets see what other people think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like nulling it out once the connection is stopped. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stopped or disposed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stopped. The ConnectionId isn't that useful after you've disconnected, and it can take on multiple values prior to being disposed. |
||
} | ||
finally | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. Negotiate is only skipped when Websockets AND
SkipNegotiate
are set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think SkipNegotiate is only possible when Websockets is set. Could simplify the comment to just meantion it.