|
22 | 22 | using IBM.Watson.DeveloperCloud.Utilities;
|
23 | 23 | using System.Collections;
|
24 | 24 | using System.Collections.Generic;
|
25 |
| -using System.Threading; |
26 |
| -#if UNITY_2018_2_OR_NEWER |
27 | 25 | using System.Security.Authentication;
|
28 |
| -#endif |
29 |
| - |
| 26 | +using System.Threading; |
30 | 27 | #if !NETFX_CORE
|
31 | 28 | using UnitySDK.WebSocketSharp;
|
32 | 29 | #else
|
@@ -205,99 +202,74 @@ public static string FixupURL(string URL)
|
205 | 202 | #if UNITY_2018_2_OR_NEWER
|
206 | 203 | #if NET_4_6
|
207 | 204 | // Use standard endpoints since 2018.2 supports TLS 1.2
|
208 |
| - if (URL.StartsWith("http://stream.")) |
209 |
| - { |
210 |
| - URL = URL.Replace("http://stream.", "ws://stream."); |
211 |
| - } |
212 |
| - else if (URL.StartsWith("https://stream.")) |
| 205 | + if (URL.StartsWith("https://stream.")) |
213 | 206 | {
|
214 | 207 | URL = URL.Replace("https://stream.", "wss://stream.");
|
215 | 208 | }
|
216 | 209 |
|
217 | 210 | // TLS 1.0 endpoint - Do not change this to TLS 1.2 endpoint since
|
218 | 211 | // users may need to use the TLS 1.0 endpoint because of different
|
219 | 212 | // platforms.
|
220 |
| - else if (URL.StartsWith("http://stream-tls10.")) |
221 |
| - { |
222 |
| - URL = URL.Replace("http://stream-tls10.", "ws://stream-tls10."); |
223 |
| - } |
224 | 213 | else if (URL.StartsWith("https://stream-tls10."))
|
225 | 214 | {
|
226 | 215 | URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
|
227 | 216 | }
|
228 |
| - |
229 | 217 | // Germany
|
230 |
| - else if (URL.StartsWith("http://gateway-fra.")) |
231 |
| - { |
232 |
| - URL = URL.Replace("http://gateway-fra.", "ws://stream-fra."); |
233 |
| - } |
234 | 218 | else if (URL.StartsWith("https://gateway-fra."))
|
235 | 219 | {
|
236 | 220 | URL = URL.Replace("https://gateway-fra.", "wss://stream-fra.");
|
237 | 221 | }
|
238 |
| - |
239 | 222 | // US East
|
240 |
| - else if (URL.StartsWith("http://gateway-wdc.")) |
241 |
| - { |
242 |
| - URL = URL.Replace("http://gateway-wdc.", "ws://gateway-wdc."); |
243 |
| - } |
244 | 223 | else if (URL.StartsWith("https://gateway-wdc."))
|
245 | 224 | {
|
246 | 225 | URL = URL.Replace("https://gateway-wdc.", "wss://gateway-wdc.");
|
247 | 226 | }
|
248 |
| - |
249 |
| - |
250 | 227 | // Sydney
|
251 |
| - else if (URL.StartsWith("http://gateway-syd.")) |
252 |
| - { |
253 |
| - URL = URL.Replace("http://gateway-syd.", "ws://gateway-syd."); |
254 |
| - } |
255 | 228 | else if (URL.StartsWith("https://gateway-syd."))
|
256 | 229 | {
|
257 | 230 | URL = URL.Replace("https://gateway-syd.", "wss://gateway-syd.");
|
258 | 231 | }
|
259 |
| - |
260 | 232 | else
|
261 | 233 | {
|
262 |
| - Log.Warning("WSConnector", "No case for URL for wss://. Leaving URL unchanged."); |
| 234 | + URL = URL.Replace("https://", "wss://"); |
| 235 | + Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://."); |
263 | 236 | }
|
264 | 237 | #else
|
265 | 238 | // Use TLS 1.0 endpoint if user is on .NET 3.5. US South is the
|
266 | 239 | // only region that supports this endpoint.
|
267 |
| - if (URL.StartsWith("http://stream.")) |
268 |
| - { |
269 |
| - URL = URL.Replace("http://stream.", "ws://stream-tls10."); |
270 |
| - } |
271 |
| - else if (URL.StartsWith("https://stream.")) |
| 240 | + if (URL.StartsWith("https://stream.")) |
272 | 241 | {
|
273 | 242 | URL = URL.Replace("https://stream.", "wss://stream-tls10.");
|
274 | 243 | }
|
275 |
| - else if (URL.StartsWith("http://stream-tls10.")) |
276 |
| - { |
277 |
| - URL = URL.Replace("http://stream-tls10.", "ws://stream-tls10."); |
278 |
| - } |
279 | 244 | else if (URL.StartsWith("https://stream-tls10."))
|
280 | 245 | {
|
281 | 246 | URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
|
282 | 247 | }
|
| 248 | + else |
| 249 | + { |
| 250 | + URL = URL.Replace("https://", "wss://"); |
| 251 | + Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://."); |
| 252 | + 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)."); |
| 253 | + } |
283 | 254 | #endif
|
284 | 255 | #else
|
285 |
| - // Redirect to TLS 1.0 endpoints. |
286 |
| - // Note frankfurt endpoint does not support TLS 1.0. |
287 |
| - if (URL.StartsWith("http://stream.")) |
288 |
| - URL = URL.Replace("http://stream.", "ws://stream-tls10."); |
289 |
| - else if (URL.StartsWith("https://stream.")) |
| 256 | + // Use TLS 1.0 endpoint if user is on .NET 3.5 or 4.6 if using Unity 2018.1 or older. |
| 257 | + // US South is the only region that supports this endpoint. |
| 258 | + if (URL.StartsWith("https://stream.")) |
| 259 | + { |
290 | 260 | URL = URL.Replace("https://stream.", "wss://stream-tls10.");
|
291 |
| - else if (URL.StartsWith("http://stream-tls10.")) |
292 |
| - URL = URL.Replace("http://stream-tls10.", "ws://stream-tls10."); |
| 261 | + } |
293 | 262 | else if (URL.StartsWith("https://stream-tls10."))
|
| 263 | + { |
294 | 264 | URL = URL.Replace("https://stream-tls10.", "wss://stream-tls10.");
|
295 |
| - else if (URL.StartsWith("http://stream-fra.")) |
296 |
| - URL = URL.Replace("http://stream-fra.", "ws://stream-fra."); |
297 |
| - else if (URL.StartsWith("https://stream-fra.")) |
298 |
| - URL = URL.Replace("https://stream-fra.", "wss://stream-fra."); |
| 265 | + } |
| 266 | + else |
| 267 | + { |
| 268 | + URL = URL.Replace("https://", "wss://"); |
| 269 | + Log.Warning("WSConnector", "No case for URL for wss://. Replacing https:// with wss://."); |
| 270 | + 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)."); |
| 271 | + } |
299 | 272 | #endif
|
300 |
| - |
301 | 273 | return URL;
|
302 | 274 | }
|
303 | 275 |
|
@@ -330,7 +302,7 @@ public static WSConnector CreateConnector(Credentials credentials, string functi
|
330 | 302 | return connector;
|
331 | 303 | }
|
332 | 304 |
|
333 |
| - #region Public Functions |
| 305 | +#region Public Functions |
334 | 306 | /// <summary>
|
335 | 307 | /// This function sends the given message object.
|
336 | 308 | /// </summary>
|
@@ -382,9 +354,9 @@ public void Close()
|
382 | 354 | // setting the state to closed will make the SendThread automatically exit.
|
383 | 355 | _connectionState = ConnectionState.CLOSED;
|
384 | 356 | }
|
385 |
| - #endregion |
| 357 | +#endregion |
386 | 358 |
|
387 |
| - #region Private Functions |
| 359 | +#region Private Functions |
388 | 360 | private IEnumerator ProcessReceiveQueue()
|
389 | 361 | {
|
390 | 362 | while (_connectionState == ConnectionState.CONNECTED
|
@@ -415,9 +387,9 @@ private IEnumerator ProcessReceiveQueue()
|
415 | 387 | if (OnClose != null)
|
416 | 388 | OnClose(this);
|
417 | 389 | }
|
418 |
| - #endregion |
| 390 | +#endregion |
419 | 391 |
|
420 |
| - #region Threaded Functions |
| 392 | +#region Threaded Functions |
421 | 393 | // NOTE: All functions in this region are operating in a background thread, do NOT call any Unity functions!
|
422 | 394 | #if !NETFX_CORE
|
423 | 395 | private void SendMessages()
|
@@ -616,6 +588,6 @@ private void WebSocket_MessageReceived(MessageWebSocket sender, MessageWebSocket
|
616 | 588 | }
|
617 | 589 | }
|
618 | 590 | #endif
|
619 |
| - #endregion |
| 591 | +#endregion |
620 | 592 | }
|
621 | 593 | }
|
0 commit comments