Get rid of WebSocketChannel.pingInterval.

This is now set as a constructor parameter for implementations that
support it.

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1759493002 .
diff --git a/README.md b/README.md
index 48b2d28..7e39a79 100644
--- a/README.md
+++ b/README.md
@@ -15,13 +15,10 @@
 interface for WebSocket stream channels across all implementations and all
 platforms. In addition to the base `StreamChannel` interface, it adds a
 [`protocol`][protocol] getter that returns the negotiated protocol for the
-socket; a [`pingInterval`][pingInterval] property that allows you to control the
-socket's keep-alive behavior; and [`closeCode`][closeCode] and
-[`closeReason`][closeReason] getters that provide information about why the
-socket closed.
+socket, as well as [`closeCode`][closeCode] and [`closeReason`][closeReason]
+getters that provide information about why the socket closed.
 
 [protocol]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/protocol.html
-[pingInterval]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/pingInterval.html
 [closeCode]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/closeCode.html
 [closeReason]: https://www.dartdocs.org/documentation/web_socket_channel/latest/web_socket_channel/WebSocketChannel/closeReason.html
 
diff --git a/lib/io.dart b/lib/io.dart
index 4c06c07..355e250 100644
--- a/lib/io.dart
+++ b/lib/io.dart
@@ -21,23 +21,6 @@
   /// `null` until the [WebSocket.connect] future completes.
   WebSocket _webSocket;
 
-  Duration get pingInterval =>
-      _webSocket == null ? _pingInterval : _webSocket.pingInterval;
-
-  set pingInterval(Duration value) {
-    if (_webSocket == null) {
-      _pingInterval = value;
-    } else {
-      _webSocket.pingInterval = value;
-    }
-  }
-
-  /// The ping interval set by the user.
-  ///
-  /// This is stored independently of [_webSocket] so that the user can set it
-  /// prior to [_webSocket] getting a value.
-  Duration _pingInterval;
-
   String get protocol => _webSocket?.protocol;
   int get closeCode => _webSocket?.closeCode;
   String get closeReason => _webSocket?.closeReason;
@@ -51,18 +34,26 @@
   ///
   /// Connects to [url] using [WebSocket.connect] and returns a channel that can
   /// be used to communicate over the resulting socket. The [url] may be either
-  /// a [String] or a [Uri]; otherwise, the parameters are the same as
-  /// [WebSocket.connect].
+  /// a [String] or a [Uri]. The [protocols] and [headers] parameters are the
+  /// same as [WebSocket.connect].
+  ///
+  /// [pingInterval] controls the interval for sending ping signals. If a ping
+  /// message is not answered by a pong message from the peer, the WebSocket is
+  /// assumed disconnected and the connection is closed with a
+  /// [WebSocketStatus.GOING_AWAY] close code. When a ping signal is sent, the
+  /// pong message must be received within [pingInterval]. It defaults to
+  /// `null`, indicating that ping messages are disabled.
   ///
   /// If there's an error connecting, the channel's stream emits a
   /// [WebSocketChannelException] wrapping that error and then closes.
   factory IOWebSocketChannel.connect(url, {Iterable<String> protocols,
-      Map<String, dynamic> headers}) {
+      Map<String, dynamic> headers, Duration pingInterval}) {
     var channel;
     var sinkCompleter = new WebSocketSinkCompleter();
     var stream = StreamCompleter.fromFuture(
         WebSocket.connect(url.toString(), headers: headers).then((webSocket) {
-      channel._setWebSocket(webSocket);
+      webSocket.pingInterval = pingInterval;
+      channel._webSocket = webSocket;
       sinkCompleter.setDestinationSink(new _IOWebSocketSink(webSocket));
       return webSocket;
     }).catchError((error) => throw new WebSocketChannelException.from(error)));
@@ -86,17 +77,6 @@
       : _webSocket = null,
         stream = stream.handleError((error) =>
             throw new WebSocketChannelException.from(error));
-
-  /// Sets the underlying web socket.
-  ///
-  /// This is called by [connect] once the [WebSocket.connect] future has
-  /// completed.
-  void _setWebSocket(WebSocket webSocket) {
-    assert(_webSocket == null);
-
-    _webSocket = webSocket;
-    if (_pingInterval != null) _webSocket.pingInterval = pingInterval;
-  }
 }
 
 /// A [WebSocketSink] that forwards [close] calls to a `dart:io` [WebSocket].
diff --git a/lib/src/channel.dart b/lib/src/channel.dart
index a4e3ed5..0f640de 100644
--- a/lib/src/channel.dart
+++ b/lib/src/channel.dart
@@ -25,21 +25,6 @@
   /// the IO-specific pieces factored out.
   final WebSocketImpl _webSocket;
 
-  /// The interval for sending ping signals.
-  ///
-  /// If a ping message is not answered by a pong message from the peer, the
-  /// `WebSocket` is assumed disconnected and the connection is closed with a
-  /// [WebSocketStatus.GOING_AWAY] close code. When a ping signal is sent, the
-  /// pong message must be received within [pingInterval].
-  ///
-  /// There are never two outstanding pings at any given time, and the next ping
-  /// timer starts when the pong is received.
-  ///
-  /// By default, the [pingInterval] is `null`, indicating that ping messages
-  /// are disabled. Some implementations may not support setting it.
-  Duration get pingInterval => _webSocket.pingInterval;
-  set pingInterval(Duration value) => _webSocket.pingInterval = value;
-
   /// The subprotocol selected by the server.
   ///
   /// For a client socket, this is initially `null`. After the WebSocket
@@ -93,14 +78,22 @@
   ///
   /// [protocol] should be the protocol negotiated by this handshake, if any.
   ///
+  /// [pingInterval] controls the interval for sending ping signals. If a ping
+  /// message is not answered by a pong message from the peer, the WebSocket is
+  /// assumed disconnected and the connection is closed with a
+  /// [WebSocketStatus.GOING_AWAY] close code. When a ping signal is sent, the
+  /// pong message must be received within [pingInterval]. It defaults to
+  /// `null`, indicating that ping messages are disabled.
+  ///
   /// If this is a WebSocket server, [serverSide] should be `true` (the
   /// default); if it's a client, [serverSide] should be `false`.
   ///
   /// [WebSocket handshake]: https://tools.ietf.org/html/rfc6455#section-4
   WebSocketChannel(StreamChannel<List<int>> channel,
-        {String protocol, bool serverSide: true})
+        {String protocol, Duration pingInterval, bool serverSide: true})
       : _webSocket = new WebSocketImpl.fromSocket(
-          channel.stream, channel.sink, protocol, serverSide);
+            channel.stream, channel.sink, protocol, serverSide)
+          ..pingInterval = pingInterval;
 }
 
 /// The sink exposed by a [WebSocketChannel].