| 563 | } |
| 564 | |
| 565 | public void Disconnect() |
| 566 | { |
| 567 | isClosing = true; |
| 568 | connectionClosed = true; |
| 569 | FailPendingOperations(new OperationCanceledException("Connection closed.")); |
| 570 | |
| 571 | // Only try to close if the connection is active |
| 572 | if (webSocket.IsConnected) |
| 573 | { |
| 574 | webSocket.Close(); |
| 575 | } |
| 576 | #if UNITY_WEBGL && !UNITY_EDITOR |
| 577 | else if (webSocket.IsConnecting) |
| 578 | #else |
| 579 | else if (webSocket.IsConnecting || webSocket.IsNoneState) |
| 580 | #endif |
| 581 | { |
| 582 | webSocket.Abort(); // forceful during connecting |
| 583 | } |
| 584 | |
| 585 | _parseCancellationTokenSource.Cancel(); |
| 586 | } |
| 587 | |
| 588 | /// <summary> |
| 589 | /// Connect to a remote spacetime instance. |