Skip to content

Commit

Permalink
add more docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anikate-De committed Jul 7, 2024
1 parent bb68b2b commit 5cea12b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion pkgs/ok_http/lib/ok_http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// BSD-style license that can be found in the LICENSE file.

/// An Android Flutter plugin that provides access to the
/// [OkHttp](https://square.github.io/okhttp/) HTTP client.
/// [OkHttp](https://square.github.io/okhttp/) HTTP client, and the OkHttp
/// [WebSocket](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-web-socket/index.html)
/// API
///
/// ```
/// import 'package:ok_http/ok_http.dart';
Expand Down
16 changes: 14 additions & 2 deletions pkgs/ok_http/lib/src/ok_http_web_socket.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import 'package:web_socket/web_socket.dart';
import 'jni/bindings.dart' as bindings;
import 'ok_http_client.dart';

/// A [WebSocket] implemented using the OkHttp library's
/// [WebSocket](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-web-socket/index.html)
/// API.
class OkHttpWebSocket implements WebSocket {
late bindings.OkHttpClient _client;
late final bindings.WebSocket _webSocket;
Expand All @@ -25,6 +28,15 @@ class OkHttpWebSocket implements WebSocket {
.build();
}

/// Create a new WebSocket connection using `OkHttp`'s
/// [WebSocket](https://square.github.io/okhttp/5.x/okhttp/okhttp3/-web-socket/index.html)
/// API.
///
/// The URL supplied in [url] must use the scheme ws or wss.
///
/// If provided, the [protocols] argument indicates that subprotocols that
/// the peer is able to select. See
/// [RFC-6455 1.9](https://datatracker.ietf.org/doc/html/rfc6455#section-1.9).
static Future<WebSocket> connect(Uri url,
{Iterable<dynamic>? protocols}) async =>
OkHttpWebSocket._()._connect(url, protocols);
Expand Down Expand Up @@ -79,7 +91,7 @@ class OkHttpWebSocket implements WebSocket {
},
onClosing:
(bindings.WebSocket webSocket, int i, JString string) async {
okHttpClientClose();
_okHttpClientClose();

if (_events.isClosed) return;

Expand Down Expand Up @@ -166,7 +178,7 @@ class OkHttpWebSocket implements WebSocket {
}

/// Closes the OkHttpClient using the recommended shutdown procedure.
void okHttpClientClose() {
void _okHttpClientClose() {
_client.dispatcher().executorService().shutdown();
_client.connectionPool().evictAll();
var cache = _client.cache();
Expand Down

0 comments on commit 5cea12b

Please sign in to comment.