webSocketTaskWithURL method
Creates a URLSessionWebSocketTask that represents a connection to a WebSocket endpoint.
Implementation
URLSessionWebSocketTask webSocketTaskWithURL(Uri uri,
{Iterable<String>? protocols}) {
if (_isBackground) {
throw UnsupportedError(
'WebSocket tasks are not supported in background sessions');
}
final URLSessionWebSocketTask task;
if (protocols == null) {
task = URLSessionWebSocketTask._(
_nsObject.webSocketTaskWithURL_(uriToNSURL(uri)));
} else {
task = URLSessionWebSocketTask._(
_nsObject.webSocketTaskWithURL_protocols_(
uriToNSURL(uri), stringIterableToNSArray(protocols)));
}
_setupDelegation(_delegate, this, task,
onComplete: _onComplete,
onData: _onData,
onFinishedDownloading: _onFinishedDownloading,
onRedirect: _onRedirect,
onResponse: _onResponse,
onWebSocketTaskOpened: _onWebSocketTaskOpened,
onWebSocketTaskClosed: _onWebSocketTaskClosed);
return task;
}