dart-lang / dart-lang/http

Get connection state after connect

Open
#1,530 2 comments 12 reactions 0 assignees View on GitHub
package:web_socket_channel
Dominant language
Dart
Stars
1.1k
Forks
419
Avg merge
4d 14h
Merged PRs (30d)
8

Description

A similar question was asked before but without a resolution. I want to get the connection state after I called HtmlWebSocketChannel.connect.
The reason is hat I want to display a successful connection in the statusbar and add the Url to a history list. Right now I can only get a callback if the connection failed. But that would only happen asynchronously after I connect.

channel = HtmlWebSocketChannel.connect('ws://' + url);
channel.stream.listen(
_receiveMessage,
onError: (e) {
print('Could not connect to: $url');
},
onDone: () {
print('Connection closed');
},
);
update_statusbar(url); // FIXME: here I do not know if the connection was successful or not!

Contributor guide

Open the contributing guide

Research direction

Start at HtmlWebSocketChannel.connect and inspect how channel.stream reports errors and completion. Compare the existing asynchronous callbacks with the requested successful-connect signal; done means callers can reliably distinguish a successful connection from a failed one before updating the status bar or history.

Written by the indexing model from the issue text.

Assessment

Tech stack
dart
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.