Skip to content

Watson Unity SDK 2.8.0 #448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,4 @@ Docs/publishing-release.md.meta
**/.swagger-codegen
/Scripts/Editor/Help/
/Scripts/Editor/Help.meta
*/MRefBuilder.config.meta
2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "IBM Watson SDK for Unity"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = 2.7.0
PROJECT_NUMBER = 2.8.0

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
107 changes: 54 additions & 53 deletions Scripts/Connection/WSConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
using IBM.Watson.DeveloperCloud.Utilities;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
#if UNITY_2018_2_OR_NEWER
using System.Security.Authentication;
#endif

using System.Threading;
#if !NETFX_CORE
using UnitySDK.WebSocketSharp;
#else
Expand Down Expand Up @@ -193,6 +190,8 @@ public Dictionary<string, string> Headers {
private AutoResetEvent _receiveEvent = new AutoResetEvent(false);
private Queue<Message> _receiveQueue = new Queue<Message>();
private int _receiverRoutine = 0;
private static readonly string https = "https://";
private static readonly string wss = "wss://";
#endregion

/// <summary>
Expand All @@ -203,78 +202,76 @@ public Dictionary<string, string> Headers {
public static string FixupURL(string URL)
{
#if UNITY_2018_2_OR_NEWER
#if NET_4_6
// Use standard endpoints since 2018.2 supports TLS 1.2
if (URL.StartsWith("http://stream."))
{
URL = URL.Replace("http://stream.", "ws://stream.");
}
else if (URL.StartsWith("https://stream."))
if (URL.StartsWith("https://stream."))
{
URL = URL.Replace("https://stream.", "wss://stream.");
}

// TLS 1.0 endpoint
else if (URL.StartsWith("http://stream-tls10."))
{
URL = URL.Replace("http://stream-tls10.", "ws://stream.");
}
// TLS 1.0 endpoint - Do not change this to TLS 1.2 endpoint since
// users may need to use the TLS 1.0 endpoint because of different
// platforms.
else if (URL.StartsWith("https://stream-tls10."))
{
URL = URL.Replace("https://stream-tls10.", "wss://stream.");
URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
}

// Germany
else if (URL.StartsWith("http://gateway-fra."))
{
URL = URL.Replace("http://gateway-fra.", "ws://stream-fra.");
}
else if (URL.StartsWith("https://gateway-fra."))
{
URL = URL.Replace("https://gateway-fra.", "wss://stream-fra.");
}

// US East
else if (URL.StartsWith("http://gateway-wdc."))
{
URL = URL.Replace("http://gateway-wdc.", "ws://gateway-wdc.");
}
else if (URL.StartsWith("https://gateway-wdc."))
{
URL = URL.Replace("https://gateway-wdc.", "wss://gateway-wdc.");
}


// Sydney
else if (URL.StartsWith("http://gateway-syd."))
{
URL = URL.Replace("http://gateway-syd.", "ws://gateway-syd.");
}
else if (URL.StartsWith("https://gateway-syd."))
{
URL = URL.Replace("https://gateway-syd.", "wss://gateway-syd.");
}

else
{
Log.Warning("WSConnector", "No case for URL for wss://. Leaving URL unchanged.");
URL = URL.Replace(https, wss);
Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://.");
}
#else
// Use TLS 1.0 endpoint if user is on .NET 3.5. US South is the
// only region that supports this endpoint.
if (URL.StartsWith("https://stream."))
{
URL = URL.Replace("https://stream.", "wss://stream-tls10.");
}
else if (URL.StartsWith("https://stream-tls10."))
{
URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
}
else
{
URL = URL.Replace(https, wss);
Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://.");
Log.Warning("WSConnector", "Streaming with TLS 1.0 is only available in US South. Please create your Speech to Text instance in US South. Alternatviely, use Unity 2018.2 with .NET 4.x Scripting Runtime Version enabled (File > Build Settings > Player Settings > Other Settings > Scripting Runtime Version).");
}
#endif
#else
// Redirect to TLS 1.0 endpoints.
// Note frankfurt endpoint does not support TLS 1.0.
if (URL.StartsWith("http://stream."))
URL = URL.Replace("http://stream.", "ws://stream-tls10.");
else if (URL.StartsWith("https://stream."))
// Use TLS 1.0 endpoint if user is on .NET 3.5 or 4.6 if using Unity 2018.1 or older.
// US South is the only region that supports this endpoint.
if (URL.StartsWith("https://stream."))
{
URL = URL.Replace("https://stream.", "wss://stream-tls10.");
else if (URL.StartsWith("http://stream-tls10."))
URL = URL.Replace("http://stream-tls10.", "ws://stream-tls10.");
}
else if (URL.StartsWith("https://stream-tls10."))
{
URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
else if (URL.StartsWith("http://stream-fra."))
URL = URL.Replace("http://stream-fra.", "ws://stream-fra.");
else if (URL.StartsWith("https://stream-fra."))
URL = URL.Replace("https://stream-fra.", "wss://stream-fra.");
}
else
{
URL = URL.Replace(https, wss);
Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://.");
Log.Warning("WSConnector", "Streaming with TLS 1.0 is only available in US South. Please create your Speech to Text instance in US South. Alternatviely, use Unity 2018.2 with .NET 4.x Scripting Runtime Version enabled (File > Build Settings > Player Settings > Other Settings > Scripting Runtime Version).");
}
#endif

return URL;
}

Expand Down Expand Up @@ -307,7 +304,7 @@ public static WSConnector CreateConnector(Credentials credentials, string functi
return connector;
}

#region Public Functions
#region Public Functions
/// <summary>
/// This function sends the given message object.
/// </summary>
Expand Down Expand Up @@ -359,9 +356,9 @@ public void Close()
// setting the state to closed will make the SendThread automatically exit.
_connectionState = ConnectionState.CLOSED;
}
#endregion
#endregion

#region Private Functions
#region Private Functions
private IEnumerator ProcessReceiveQueue()
{
while (_connectionState == ConnectionState.CONNECTED
Expand Down Expand Up @@ -392,10 +389,10 @@ private IEnumerator ProcessReceiveQueue()
if (OnClose != null)
OnClose(this);
}
#endregion
#endregion

#region Threaded Functions
// NOTE: ALl functions in this region are operating in a background thread, do NOT call any Unity functions!
#region Threaded Functions
// NOTE: All functions in this region are operating in a background thread, do NOT call any Unity functions!
#if !NETFX_CORE
private void SendMessages()
{
Expand All @@ -412,8 +409,12 @@ private void SendMessages()
ws.OnClose += OnWSClose;
ws.OnError += OnWSError;
ws.OnMessage += OnWSMessage;
#if UNITY_2018_2_OR_NEWER
#if NET_4_6
// Enable TLS 1.1 and TLS 1.2 if we are on .NET 4.x
ws.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls;
#else
// .NET 3.x does not support TLS 1.1 or TLS 1.2
ws.SslConfiguration.EnabledSslProtocols = SslProtocols.Tls;
#endif
ws.Connect();

Expand Down Expand Up @@ -589,6 +590,6 @@ private void WebSocket_MessageReceived(MessageWebSocket sender, MessageWebSocket
}
}
#endif
#endregion
#endregion
}
}
8 changes: 0 additions & 8 deletions Scripts/Editor/Help/Working/MRefBuilder.config.meta

This file was deleted.

5 changes: 5 additions & 0 deletions Scripts/Services/Assistant/v1/Model/MessageResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ public class MessageResponse
/// <value>Output from the dialog, including the response to the user, the nodes that were triggered, and log messages.</value>
[fsProperty("output")]
public object Output { get; set; }
/// <summary>
/// An array of objects describing any actions requested by the dialog node.
/// </summary>
[fsProperty("actions")]
public object Actions { get; set; }
}

}
5 changes: 5 additions & 0 deletions Scripts/Services/Assistant/v1/Model/OutputData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class OutputData
/// <value>An array of objects containing detailed diagnostic information about the nodes that were triggered during processing of the input message. Included only if **nodes_visited_details** is set to `true` in the message request.</value>
[fsProperty("nodes_visited_details")]
public Dictionary<string, object> NodesVisitedDetails { get; set; }
// <summary>
/// An array of objects describing any actions requested by the dialog node.
/// </summary>
[fsProperty("actions")]
public Dictionary<string, object> Actions { get; set; }
}

}
6 changes: 3 additions & 3 deletions Scripts/UnitTests/TestAssistantCF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class TestAssistantCF : UnitTest
private fsSerializer _serializer = new fsSerializer();

private string _inputString = "Hello";
private string _conversationString0 = "unlock the door";
private string _conversationString1 = "turn on the ac";
private string _conversationString2 = "turn down the radio";
private string _conversationString0 = "Are you open on christmas?";
private string _conversationString1 = "Can you connect me to a real person?";
private string _conversationString2 = "goodbye";
private static string _lastIntent = null;

private static string _createdWorkspaceName = "unity-sdk-example-workspace-delete";
Expand Down
3 changes: 0 additions & 3 deletions Scripts/UnitTests/TestDiscovery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public class TestDiscovery : UnitTest
private bool _deleteConfigurationTested = false;
private bool _isEnvironmentReady = false;
private bool _deleteUserDataTested = false;
private bool _readyToContinue = false;

private bool _listCredentialsTested = false;
private bool _createCredentialsTested = false;
Expand Down Expand Up @@ -332,7 +331,6 @@ public override IEnumerator RunTest()
while (!_isEnvironmentReady)
yield return null;

_readyToContinue = false;
// Delete Collection
Log.Debug("TestDiscovery.RunTest()", "Attempting to delete collection {0}", _createdCollectionId);
if (!_discovery.DeleteCollection(OnDeleteCollection, OnFail, _environmentId, _createdCollectionId))
Expand All @@ -345,7 +343,6 @@ public override IEnumerator RunTest()
while (!_isEnvironmentReady)
yield return null;

_readyToContinue = false;
// Delete Configuration
Log.Debug("TestDiscovery.RunTest()", "Attempting to delete configuration {0}", _createdConfigurationID);
if (!_discovery.DeleteConfiguration(OnDeleteConfiguration, OnFail, _environmentId, _createdConfigurationID))
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Utilities/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static class Path
public static class String
{
/// <exclude />
public const string Version = "watson-apis-unity-sdk/2.7.0";
public const string Version = "watson-apis-unity-sdk/2.8.0";
/// <exclude />
public const string DebugDispalyQuality = "Quality: {0}";
/// <summary>
Expand Down
28 changes: 18 additions & 10 deletions Scripts/Utilities/Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class Credentials
private string _iamApiKey;
private string _userAcessToken;
private const string APIKEY_AS_USERNAME = "apikey";
private const string ICP_PREFIX = "icp-";
#endregion

#region Public Fields
Expand Down Expand Up @@ -146,7 +147,7 @@ public Credentials(TokenOptions iamTokenOptions, string serviceUrl = null)
#region SetCredentials
private void SetCredentials(string username, string password, string url = null)
{
if (username == APIKEY_AS_USERNAME)
if (username == APIKEY_AS_USERNAME && !password.StartsWith(ICP_PREFIX))
{
TokenOptions tokenOptions = new TokenOptions()
{
Expand All @@ -167,18 +168,25 @@ private void SetCredentials(string username, string password, string url = null)

private void SetCredentials(TokenOptions iamTokenOptions, string serviceUrl = null)
{
if (!string.IsNullOrEmpty(serviceUrl))
Url = serviceUrl;
_iamUrl = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
_iamTokenData = new IamTokenData();
if (iamTokenOptions.IamApiKey.StartsWith(ICP_PREFIX))
{
SetCredentials(APIKEY_AS_USERNAME, iamTokenOptions.IamApiKey, serviceUrl);
}
else
{
if (!string.IsNullOrEmpty(serviceUrl))
Url = serviceUrl;
_iamUrl = !string.IsNullOrEmpty(iamTokenOptions.IamUrl) ? iamTokenOptions.IamUrl : "https://iam.bluemix.net/identity/token";
_iamTokenData = new IamTokenData();

if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
_iamApiKey = iamTokenOptions.IamApiKey;
if (!string.IsNullOrEmpty(iamTokenOptions.IamApiKey))
_iamApiKey = iamTokenOptions.IamApiKey;

if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
this._userAcessToken = iamTokenOptions.IamAccessToken;
if (!string.IsNullOrEmpty(iamTokenOptions.IamAccessToken))
this._userAcessToken = iamTokenOptions.IamAccessToken;

GetToken();
GetToken();
}
}
#endregion

Expand Down