11using Microsoft . AspNetCore . Authorization ;
2+ using Microsoft . AspNetCore . Http . Connections . Features ;
23using Microsoft . AspNetCore . SignalR ;
34using System ;
45using System . Threading . Tasks ;
@@ -15,25 +16,29 @@ public override Task OnConnectedAsync()
1516
1617 public async Task SendMessage ( string message )
1718 {
19+ var transportType = Context . Features . Get < IHttpTransportFeature > ( ) . TransportType . ToString ( ) ;
1820 var connectionId = Context . ConnectionId ;
19- await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "Data Received from SendMessage method: { message } ") ;
21+ await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "TransportType- { transportType } :: Data Received from SendMessage method: { message } ") ;
2022 }
2123
2224 public async Task SendMessageWithId ( string message , int id )
2325 {
26+ var transportType = Context . Features . Get < IHttpTransportFeature > ( ) . TransportType . ToString ( ) ;
2427 var connectionId = Context . ConnectionId ;
25- await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "Data Received from TestCall method: { message } - { id } ") ;
28+ await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "TransportType- { transportType } :: Data Received from SendMessageWithId method: { message } - { id } ") ;
2629 }
2730
2831 public async Task NotifyAllClient ( string message )
2932 {
30- await Clients . All . SendAsync ( "Response" , $ "Data Received: { message } ") ;
33+ var transportType = Context . Features . Get < IHttpTransportFeature > ( ) . TransportType . ToString ( ) ;
34+ await Clients . All . SendAsync ( "Response" , $ "TransportType-{ transportType } :: Data Received: { message } ") ;
3135 }
3236
3337 public async Task ComplexData ( User user )
3438 {
39+ var transportType = Context . Features . Get < IHttpTransportFeature > ( ) . TransportType . ToString ( ) ;
3540 var connectionId = Context . ConnectionId ;
36- await Clients . Client ( connectionId ) . SendAsync ( "Response" , new { Msg = " Complex Data Received", User = user } ) ;
41+ await Clients . Client ( connectionId ) . SendAsync ( "Response" , new { Msg = $ "TransportType- { transportType } :: Complex Data Received", User = user } ) ;
3742 }
3843
3944 public override Task OnDisconnectedAsync ( Exception exception )
@@ -45,8 +50,9 @@ public override Task OnDisconnectedAsync(Exception exception)
4550 [ Authorize ]
4651 public async Task SendMessageWithAuth ( string message )
4752 {
53+ var transportType = Context . Features . Get < IHttpTransportFeature > ( ) . TransportType . ToString ( ) ;
4854 var connectionId = Context . ConnectionId ;
49- await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "Data Received from SendMessageWithAuth method: { message } ") ;
55+ await Clients . Client ( connectionId ) . SendAsync ( "Response" , $ "TransportType- { transportType } :: Data Received from SendMessageWithAuth method: { message } ") ;
5056 }
5157 }
5258}
0 commit comments