C# Class DeviceHive.Client.WebSocketChannel

Represents implementation of the persistent connection to the DeviceHive server using WebSocket API.
Inheritance: Channel
显示文件 Open project: devicehive/devicehive-.net

Public Methods

Method Description
CanConnectAsync ( ) : Task

Checks if current channel object can be used to eshtablish connection to the DeviceHive server. The method returns true only if the DeviceHive server deployment supports WebSocket protocol.

CloseAsync ( ) : Task

Closes the persistent connection to the DeviceHive server.

OpenAsync ( ) : Task

Opens a persistent connection to the DeviceHive server.

SendCommandAsync ( string deviceGuid, Command command, Action callback = null, CancellationToken token = null ) : Task

Sends a command to the device.

SendNotificationAsync ( string deviceGuid, Notification notification ) : Task

Sends a notification on behalf of device.

UpdateCommandAsync ( string deviceGuid, Command command ) : Task

Updates a command on behalf of the device.

WaitCommandResultAsync ( string deviceGuid, int commandId, CancellationToken token = null ) : Task

Waits until the command is completed and returns a Command object with filled Status and Result properties.

WebSocketChannel ( DeviceHive.Client.DeviceHiveConnectionInfo connectionInfo ) : Newtonsoft.Json.Linq

Default constructor.

WebSocketChannel ( DeviceHive.Client.DeviceHiveConnectionInfo connectionInfo, IRestClient restClient ) : Newtonsoft.Json.Linq

Constructor which allows to override IRestClient which makes HTTP requests to the DeviceHive server.

Protected Methods

Method Description
SubscriptionAdding ( ISubscription subscription ) : Task

Invoked before new subscription is added. The methods sends subscribe message to the DeviceHive server.

SubscriptionRemoving ( ISubscription subscription ) : Task

Invoked before an existing subscription is removed. The methods sends unsubscribe message to the DeviceHive server.

Private Methods

Method Description
AuthenticateAsync ( ) : Task
HandleConnectionClose ( ) : void
HandleMessage ( MessageWebSocketMessageReceivedEventArgs args ) : void
HandleMessage ( string message ) : void
OpenWebSocketAsync ( ) : Task
Reconnect ( ) : Task
SendRequestAsync ( string action ) : Task

Method Details

CanConnectAsync() public method

Checks if current channel object can be used to eshtablish connection to the DeviceHive server. The method returns true only if the DeviceHive server deployment supports WebSocket protocol.
public CanConnectAsync ( ) : Task
return Task

CloseAsync() public method

Closes the persistent connection to the DeviceHive server.
public CloseAsync ( ) : Task
return Task

OpenAsync() public method

Opens a persistent connection to the DeviceHive server.
public OpenAsync ( ) : Task
return Task

SendCommandAsync() public method

Sends a command to the device.
public SendCommandAsync ( string deviceGuid, Command command, Action callback = null, CancellationToken token = null ) : Task
deviceGuid string Device unique identifier.
command Command A object to be sent.
callback Action A callback action to invoke when the command is completed by the device.
token System.Threading.CancellationToken Cancellation token to cancel waiting for command result.
return Task

SendNotificationAsync() public method

Sends a notification on behalf of device.
public SendNotificationAsync ( string deviceGuid, Notification notification ) : Task
deviceGuid string Device unique identifier.
notification Notification A object to be sent.
return Task

SubscriptionAdding() protected method

Invoked before new subscription is added. The methods sends subscribe message to the DeviceHive server.
protected SubscriptionAdding ( ISubscription subscription ) : Task
subscription ISubscription A object representing a subscription.
return Task

SubscriptionRemoving() protected method

Invoked before an existing subscription is removed. The methods sends unsubscribe message to the DeviceHive server.
protected SubscriptionRemoving ( ISubscription subscription ) : Task
subscription ISubscription A object representing a subscription.
return Task

UpdateCommandAsync() public method

Updates a command on behalf of the device.
public UpdateCommandAsync ( string deviceGuid, Command command ) : Task
deviceGuid string Device unique identifier.
command Command A object to update.
return Task

WaitCommandResultAsync() public method

Waits until the command is completed and returns a Command object with filled Status and Result properties.
public WaitCommandResultAsync ( string deviceGuid, int commandId, CancellationToken token = null ) : Task
deviceGuid string Device unique identifier.
commandId int Command identifier.
token System.Threading.CancellationToken Cancellation token to cancel waiting for command result.
return Task

WebSocketChannel() public method

Default constructor.
public WebSocketChannel ( DeviceHive.Client.DeviceHiveConnectionInfo connectionInfo ) : Newtonsoft.Json.Linq
connectionInfo DeviceHive.Client.DeviceHiveConnectionInfo DeviceHive connection information.
return Newtonsoft.Json.Linq

WebSocketChannel() public method

Constructor which allows to override IRestClient which makes HTTP requests to the DeviceHive server.
public WebSocketChannel ( DeviceHive.Client.DeviceHiveConnectionInfo connectionInfo, IRestClient restClient ) : Newtonsoft.Json.Linq
connectionInfo DeviceHive.Client.DeviceHiveConnectionInfo DeviceHive connection information.
restClient IRestClient IRestClient implementation.
return Newtonsoft.Json.Linq