webSocketTaskWithRequest method

URLSessionWebSocketTask webSocketTaskWithRequest(
  1. URLRequest request
)

Creates a URLSessionWebSocketTask that represents a connection to a WebSocket endpoint.

To add custom protocols, add a "Sec-WebSocket-Protocol" header with a list of protocols to request.

See NSURLSession webSocketTaskWithRequest:

Implementation

URLSessionWebSocketTask webSocketTaskWithRequest(URLRequest request) {
  if (_isBackground) {
    throw UnsupportedError(
        'WebSocket tasks are not supported in background sessions');
  }
  final task = URLSessionWebSocketTask._(
      _nsObject.webSocketTaskWithRequest_(request._nsObject));
  _setupDelegation(_delegate, this, task,
      onComplete: _onComplete,
      onData: _onData,
      onFinishedDownloading: _onFinishedDownloading,
      onRedirect: _onRedirect,
      onResponse: _onResponse,
      onWebSocketTaskOpened: _onWebSocketTaskOpened,
      onWebSocketTaskClosed: _onWebSocketTaskClosed);
  return task;
}