Skip to content

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

Merged
merged 6 commits into from
Mar 28, 2019

Conversation

mikaelm12
Copy link
Contributor

@mikaelm12 mikaelm12 commented Mar 20, 2019

Exposing the ConnectionId on the .NET Client.

Part of: #8681

@mikaelm12 mikaelm12 added the area-signalr Includes: SignalR clients and servers label Mar 20, 2019
@mikaelm12
Copy link
Contributor Author

Looks like I need to do the GenerateReferenceSource step. Adding public API

@mikaelm12 mikaelm12 requested a review from davidfowl March 21, 2019 23:21
@@ -405,6 +420,8 @@ private async Task StopAsyncCore(bool disposing)
(_serviceProvider as IDisposable)?.Dispose();
_disposed = true;
}

_connectionId = null;
Copy link
Member

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like nulling it out once the connection is stopped.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stopped or disposed?

Copy link
Member

Choose a reason for hiding this comment

The 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.

@mikaelm12 mikaelm12 requested a review from analogrelay as a code owner March 25, 2019 23:28
@analogrelay analogrelay added this to the 3.0.0-preview4 milestone Mar 26, 2019
@@ -116,6 +117,14 @@ public partial class HubConnection
/// </summary>
public TimeSpan HandshakeTimeout { get; set; } = DefaultHandshakeTimeout;

/// <summary>
/// Get the connections current connection Id.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

connection's

Copy link
Member

@JamesNK JamesNK Mar 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gets the connection's current Id. reads better IMO

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will ConnectionId be null in some cases or has that changed?

A null connection ID for an active connection will confuse some people. It should be mentioned in the comments.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should document when this can be null. Is this only when the client is disconnected? Or is it also possible to establish a connection without negotiating using HubConnection?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe a HubConnection with the transport explicitly specified as WebSockets will skip negotiation and never have the connection ID sent to the client.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, when negotiation is skipped the client connection Id will be null as well as when the client is disconnected. I can file a docs issue so that we follow up once we get this change in across the clients.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whether or not we decide this is worth mentioning in a doc article, I think we should also mention this in the doc comments. Something similar to what you have for the Java client should be fine. E.g.

/// Gets the connections 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 WebSockets transport is explicitly specified because the client skips negotiation in that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that wording. We should also note that this will always be null when the SkipNegotiation flag is set to true.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good coverage w.r.t. docs. thanks!

Copy link
Member

@halter73 halter73 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will be good to go once we update the doc comment to discuss when ConnectionId can be null.

@mikaelm12 mikaelm12 merged commit 017f409 into master Mar 28, 2019
@BrennanConroy BrennanConroy deleted the mikaelm12/ExposeConnectionIdDotNet branch March 28, 2019 01:11
@@ -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
Copy link
Member

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants