Adding HubConnection State Enum (#2627)
This commit is contained in:
parent
a2942ce885
commit
3e53533db3
|
|
@ -15,8 +15,7 @@ public class HubConnection {
|
|||
private CallbackMap handlers = new CallbackMap();
|
||||
private HubProtocol protocol;
|
||||
private Gson gson = new Gson();
|
||||
|
||||
public Boolean connected = false;
|
||||
private HubConnectionState connectionState = HubConnectionState.DISCONNECTED;
|
||||
|
||||
public HubConnection(String url, Transport transport){
|
||||
this.url = url;
|
||||
|
|
@ -68,15 +67,19 @@ public class HubConnection {
|
|||
this(url, null);
|
||||
}
|
||||
|
||||
public HubConnectionState getConnectionState() {
|
||||
return connectionState;
|
||||
}
|
||||
|
||||
public void start() throws InterruptedException {
|
||||
transport.setOnReceive(this.callback);
|
||||
transport.start();
|
||||
connected = true;
|
||||
connectionState = HubConnectionState.CONNECTED;
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
transport.stop();
|
||||
connected = false;
|
||||
connectionState = HubConnectionState.DISCONNECTED;
|
||||
}
|
||||
|
||||
public void send(String method, Object... args) throws Exception {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright (c) .NET Foundation. All rights reserved.
|
||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||
|
||||
public enum HubConnectionState {
|
||||
CONNECTED,
|
||||
DISCONNECTED,
|
||||
}
|
||||
|
|
@ -13,10 +13,10 @@ public class HubConnectionTest {
|
|||
Transport mockTransport = new MockEchoTransport();
|
||||
HubConnection hubConnection = new HubConnection("http://example.com", mockTransport);
|
||||
hubConnection.start();
|
||||
assertTrue(hubConnection.connected);
|
||||
assertEquals(HubConnectionState.CONNECTED, hubConnection.getConnectionState());
|
||||
|
||||
hubConnection.stop();
|
||||
assertFalse(hubConnection.connected);
|
||||
assertEquals(HubConnectionState.DISCONNECTED, hubConnection.getConnectionState());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
Loading…
Reference in New Issue