API reference
API reference
Select your platform
No SDKs available
No versions available

WitWebSocketClient Class

An class for performing multi-threaded web socket communication to a Wit endpoint WitWebSocketClient is a wrapper for web socket communication that facilitates the safe upload and download of data between the Voice SDK and Wit.ai. The class handles connection, transmission and response handling for all socket communication. Three background threads are spawned by each WitWebSocketClient in order to handle encoding/uploading, downloading/decoding and response handling respectively. WitWebSocketClients contain a list of IWitWebSocketRequests which are used to facilitate upload and download of data. When sending a WitChunk the IWitWebSocketRequest’s request id will also be sent within the json data. When receiving a WitChunk, request id will be checked within the json data and the appropriate IWitWebSocketRequest will handle the response. If no matching request is found, the WitChunk’s topic id will be used to find the appropriate IWitWebSocketSubscriber which then will generate a request to handle the response.
Meta::Voice::Net::WebSockets::WitWebSocketClient extends Meta.Voice.Net.PubSub.IPubSubSubscriber.

Overview

Properties

The settings required to connect, authenticate and drive server/client communication.
Whether the web socket is disconnected, connecting, connected, or disconnecting.
bool
Whether authentication had completed successfully or not
int
Total amount of scripts that have called Connect() and have not yet called Disconnect(). Used to ensure WebSocketClient is only disconnected once no scripts are still referenced.
int
Total amount of failed connection attempts made
DateTime
The utc time of the last response from the server

Data Fields

bool
Whether there currently is data being encoded and/or queued to be sent from the web socket.
bool
Whether there currently is data being received and/or decoded from the web socket.
bool
Whether there currently are any scripts that have called Connect() and not yet requested a Disconnect().
bool
Whether will be reconnecting
Dictionary< string, IWitWebSocketRequest >
The requests currently being tracked by this client. Each access generates a new dictionary and should be cached.

Events

Callback on connection state change.
PubSubTopicSubscriptionDelegate
Callback when subscription state changes for a specific topic id
Action< string, IWitWebSocketRequest >
Callback when a tracked topic generates a request

Public Member Functions

Constructor with settings data
Constructor that takes in IWitRequestConfiguration and generates default settings use it
void
Connect ( )
Attempts to connect to the specified
void
Disconnects socket after checking state
bool
Send a request via this client if possible
bool
Safely adds a request to the current request list
bool
Safely removes a request from the current request list
bool
UntrackRequest
( string requestId )
Safely removes a request from the current request list by request id
GetTopicSubscriptionState
( string topicId )
Obtains the current subscription state for a specific topic
void
Subscribe
( string topicId )
Method to subscribe to a specific topic id
void
Unsubscribe
( string topicId )
Method to unsubscribe to a specific topic id
void
Unsubscribe
( string topicId,
bool ignoreRefCount )
Method to subscribe to a specific topic id with a parameter to ignore ref count for local unsubscribing following disconnect/error.

Details

Properties

WitWebSocketSettings Meta.Voice.Net.WebSockets.WitWebSocketClient.Settings
The settings required to connect, authenticate and drive server/client communication.
WitWebSocketConnectionState Meta.Voice.Net.WebSockets.WitWebSocketClient.ConnectionState
Whether the web socket is disconnected, connecting, connected, or disconnecting.
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.IsAuthenticated
Whether authentication had completed successfully or not
int Meta.Voice.Net.WebSockets.WitWebSocketClient.ReferenceCount
Total amount of scripts that have called Connect() and have not yet called Disconnect(). Used to ensure WebSocketClient is only disconnected once no scripts are still referenced.
int Meta.Voice.Net.WebSockets.WitWebSocketClient.FailedConnectionAttempts
Total amount of failed connection attempts made
DateTime Meta.Voice.Net.WebSockets.WitWebSocketClient.LastResponseTime
The utc time of the last response from the server

Fields

bool Meta.Voice.Net.WebSockets.WitWebSocketClient.IsUploading
Whether there currently is data being encoded and/or queued to be sent from the web socket.
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.IsDownloading
Whether there currently is data being received and/or decoded from the web socket.
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.IsReferenced
Whether there currently are any scripts that have called Connect() and not yet requested a Disconnect().
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.IsReconnecting
Whether will be reconnecting
Dictionary<string, IWitWebSocketRequest> Meta.Voice.Net.WebSockets.WitWebSocketClient.Requests
The requests currently being tracked by this client. Each access generates a new dictionary and should be cached.

Events

Action<WitWebSocketConnectionState> Meta.Voice.Net.WebSockets.WitWebSocketClient.OnConnectionStateChanged ( )
Callback on connection state change.
PubSubTopicSubscriptionDelegate Meta.Voice.Net.WebSockets.WitWebSocketClient.OnTopicSubscriptionStateChange ( )
Callback when subscription state changes for a specific topic id
Action<string, IWitWebSocketRequest> Meta.Voice.Net.WebSockets.WitWebSocketClient.OnTopicRequestTracked ( )
Callback when a tracked topic generates a request

Member Functions

Meta.Voice.Net.WebSockets.WitWebSocketClient.WitWebSocketClient
( WitWebSocketSettings settings )
Constructor with settings data
Meta.Voice.Net.WebSockets.WitWebSocketClient.WitWebSocketClient
( IWitRequestConfiguration configuration )
Constructor that takes in IWitRequestConfiguration and generates default settings use it
void Meta.Voice.Net.WebSockets.WitWebSocketClient.Connect ( )
Attempts to connect to the specified
void Meta.Voice.Net.WebSockets.WitWebSocketClient.Disconnect ( )
Disconnects socket after checking state
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.SendRequest
( IWitWebSocketRequest request )
Send a request via this client if possible
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.TrackRequest
( IWitWebSocketRequest request )
Safely adds a request to the current request list
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.UntrackRequest
( IWitWebSocketRequest request )
Safely removes a request from the current request list
bool Meta.Voice.Net.WebSockets.WitWebSocketClient.UntrackRequest
( string requestId )
Safely removes a request from the current request list by request id
PubSubSubscriptionState Meta.Voice.Net.WebSockets.WitWebSocketClient.GetTopicSubscriptionState
( string topicId )
Obtains the current subscription state for a specific topic
void Meta.Voice.Net.WebSockets.WitWebSocketClient.Subscribe
( string topicId )
Method to subscribe to a specific topic id
void Meta.Voice.Net.WebSockets.WitWebSocketClient.Unsubscribe
( string topicId )
Method to unsubscribe to a specific topic id
void Meta.Voice.Net.WebSockets.WitWebSocketClient.Unsubscribe
( string topicId,
bool ignoreRefCount )
Method to subscribe to a specific topic id with a parameter to ignore ref count for local unsubscribing following disconnect/error.
Did you find this page helpful?
Thumbs up icon
Thumbs down icon