Open mahmoudajawad opened 2 years ago
Use the following instead:
import 'package:web_socket_channel/web_socket_channel.dart';
// ...
channel = WebSocketChannel.connect(wsUrl);
@masus04, interesting! This definitely works, much thanks. I believe the examples need to be updated to use your snippet. I'll contribute that for the next person who faces the same issue as me.
Already created a PR: #223
//var channel = IOWebSocketChannel.connect(Uri.parse('ws://localhost:1234'));
final wsUrl = Uri.parse('ws://localhost:1234')
var channel = WebSocketChannel.connect(wsUrl);
How to get around this problem if custom headers are needed? The WebSocketChannel.connect
method does not have a parameter to pass headers as IOWebSocketChannel.connect does
.
IOWebSocketChannel.connect(
"ws://localhost:1234",
headers: {
'Authorization': "Bearer $token", // <-- here is it
},
pingInterval: const Duration(seconds: 10),
);
@xurc I have the same problem. Found anything?
@xurc I have the same problem. Found anything?
I began to transfer the token in the protocols, but this approach requires changes on the server side: in addition to taking the token from an unusual place, you also need to return the token in the Sec-Websocket-Protocol
header.
WebSocketChannel.connect(
Uri.parse("${_wsConfig['baseUrl']!}$url"),
protocols: [jwtToken],
)
Flutter: 3.0.2, 3.0.3 dart: 2.17.5 OS: windows, macos
With minimal project:
Update
pubspec.yaml
with:Adding the following snippet to
main
:The following error is reported when started application for web: