File tree 3 files changed +16
-6
lines changed
3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,7 @@ public class HubConnection {
15
15
private CallbackMap handlers = new CallbackMap ();
16
16
private HubProtocol protocol ;
17
17
private Gson gson = new Gson ();
18
-
19
- public Boolean connected = false ;
18
+ private HubConnectionState connectionState = HubConnectionState .DISCONNECTED ;
20
19
21
20
public HubConnection (String url , Transport transport ){
22
21
this .url = url ;
@@ -68,15 +67,19 @@ public HubConnection(String url) {
68
67
this (url , null );
69
68
}
70
69
70
+ public HubConnectionState getConnectionState () {
71
+ return connectionState ;
72
+ }
73
+
71
74
public void start () throws InterruptedException {
72
75
transport .setOnReceive (this .callback );
73
76
transport .start ();
74
- connected = true ;
77
+ connectionState = HubConnectionState . CONNECTED ;
75
78
}
76
79
77
80
public void stop (){
78
81
transport .stop ();
79
- connected = false ;
82
+ connectionState = HubConnectionState . DISCONNECTED ;
80
83
}
81
84
82
85
public void send (String method , Object ... args ) throws Exception {
Original file line number Diff line number Diff line change
1
+ // Copyright (c) .NET Foundation. All rights reserved.
2
+ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
+
4
+ public enum HubConnectionState {
5
+ CONNECTED ,
6
+ DISCONNECTED ,
7
+ }
Original file line number Diff line number Diff line change @@ -13,10 +13,10 @@ public void checkHubConnectionState() throws InterruptedException {
13
13
Transport mockTransport = new MockEchoTransport ();
14
14
HubConnection hubConnection = new HubConnection ("http://example.com" , mockTransport );
15
15
hubConnection .start ();
16
- assertTrue ( hubConnection .connected );
16
+ assertEquals ( HubConnectionState . CONNECTED , hubConnection .getConnectionState () );
17
17
18
18
hubConnection .stop ();
19
- assertFalse ( hubConnection .connected );
19
+ assertEquals ( HubConnectionState . DISCONNECTED , hubConnection .getConnectionState () );
20
20
}
21
21
22
22
@ Test
You can’t perform that action at this time.
0 commit comments