(WebSocketCloseStatus code = WebSocketCloseStatus.NormalClosure)
| 402 | } |
| 403 | |
| 404 | public Task Close(WebSocketCloseStatus code = WebSocketCloseStatus.NormalClosure) |
| 405 | { |
| 406 | #if UNITY_WEBGL && !UNITY_EDITOR |
| 407 | if (_webglSocketId >= 0) |
| 408 | { |
| 409 | // If connected or connecting with a valid socket id, request a close. |
| 410 | WebSocket_Close(_webglSocketId, (int)code, "Disconnecting normally."); |
| 411 | _cancelConnectRequested = false; // graceful close intent |
| 412 | _isConnected = false; |
| 413 | } |
| 414 | else if (_isConnecting) |
| 415 | { |
| 416 | // We don't yet have a socket id; remember to cancel once it arrives/opens. |
| 417 | _cancelConnectRequested = true; |
| 418 | } |
| 419 | #else |
| 420 | if (Ws?.State == WebSocketState.Open) |
| 421 | { |
| 422 | return Ws.CloseAsync(code, "Disconnecting normally.", CancellationToken.None); |
| 423 | } |
| 424 | #endif |
| 425 | return Task.CompletedTask; |
| 426 | } |
| 427 | |
| 428 | /// <summary> |
| 429 | /// Forcefully abort the WebSocket connection. This terminates any in-flight connect/receive/send |
no outgoing calls
no test coverage detected