sefidgaran / signalr_client

A Flutter SignalR Client for ASP.NET Core
https://pub.dev/packages/signalr_netcore
MIT License
71 stars 111 forks source link

was not upgraded to websocket version 1.5.7 #83

Open waulite-786 opened 5 months ago

waulite-786 commented 5 months ago

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketException: Connection to 'https://xyz.net:0/signalr-eventHub?id=_LjiDUXe_3sCYmvD-mNJ1g#' was not upgraded to websocket

0 _WebSocketImpl.connect (dart:_http/websocket_impl.dart:1011:41)

1 WebSocket.connect (dart:_http/websocket.dart:320:22)

abdalazeezalyosfi commented 4 months ago

same here when i try to connect to hub is give this error

be care its add port 0 after base url when its send head check

this is log

`message: Starting HubConnection. message: null

[2024-04-30 16:26:37.151692 SignalR LatLng] error: null message: Starting connection with transfer format 'TransferFormat.Text'. message: null

[2024-04-30 16:26:37.202843 SignalR LatLng] error: null message: Sending negotiation request: https://realtime.********.net/hub/negotiate?negotiateVersion=1 message: null

[2024-04-30 16:26:37.229015 SignalR LatLng] error: null message: HTTP send: url 'https://realtime.*********.net/hub/negotiate?negotiateVersion=1', method: 'POST' content: '' content length = '0' headers: '{ content-type: text/plain;charset=UTF-8 }, { X-Requested-With: FlutterHttpClient }, { authorization: Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImY3NTZjNmJjLTEwYTQtNGE0Ny1jM2IwLTA4ZGM1Yzc2Y2Q1OCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkRyaXZlciIsImV4cCI6MTcxNDQ5ODM2MywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzA4Ny8iLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo3MDg3LyJ9.fuxYpVypm3nzA15qMwbO9wrmszNV48cpKlHom--o6A8 }, { Authorization: Bearer eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImY3NTZjNmJjLTEwYTQtNGE0Ny1jM2IwLTA4ZGM1Yzc2Y2Q1OCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkRyaXZlciIsImV4cCI6MTcxNDQ5ODM2MywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzA4Ny8iLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo3MDg3LyJ9.fuxYpVypm3nzA15qMwbO9wrmszNV48cpKlHom--o6A8 }' message: null

E/gralloc4(10329): Empty SMPTE 2094-40 data E/gralloc4(10329): Empty SMPTE 2094-40 data E/gralloc4(10329): Empty SMPTE 2094-40 data [2024-04-30 16:26:38.186607 SignalR LatLng] error: null message: Selecting transport 'HttpTransportType.WebSockets'. message: null

[2024-04-30 16:26:38.195162 SignalR LatLng] error: null message: (WebSockets transport) Connecting message: null

[2024-04-30 16:26:38.205808 SignalR LatLng] error: null message: WebSocket try connecting to 'wss://realtime.***.net/hub?id=5eftxqkWA1EFz7jv6lDMtQ&access_token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImY3NTZjNmJjLTEwYTQtNGE0Ny1jM2IwLTA4ZGM1Yzc2Y2Q1OCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkRyaXZlciIsImV4cCI6MTcxNDQ5ODM2MywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzA4Ny8iLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo3MDg3LyJ9.fuxYpVypm3nzA15qMwbO9wrmszNV48cpKlHom--o6A8'. message: null

[2024-04-30 16:26:38.228177 SignalR LatLng] error: null message: WebSocket connected to 'wss://realtime.****.net/hub?id=5eftxqkWA1EFz7jv6lDMtQ&access_token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImY3NTZjNmJjLTEwYTQtNGE0Ny1jM2IwLTA4ZGM1Yzc2Y2Q1OCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkRyaXZlciIsImV4cCI6MTcxNDQ5ODM2MywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzA4Ny8iLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo3MDg3LyJ9.fuxYpVypm3nzA15qMwbO9wrmszNV48cpKlHom--o6A8'. message: null

[2024-04-30 16:26:38.230771 SignalR LatLng] error: null message: The HttpConnection connected successfully. message: null

[2024-04-30 16:26:38.231496 SignalR LatLng] error: null message: Sending handshake request. message: null

[2024-04-30 16:26:38.239084 SignalR LatLng] error: null message: (WebSockets transport) sending data. String data of length 32. Content: '{"protocol":"json","version":1}'. message: null

[2024-04-30 16:26:38.240471 SignalR LatLng] error: null message: Using HubProtocol 'json'. message: null

E/flutter (10329): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: WebSocketException: Connection to 'https://realtime.*******.net:0/hub?id=5eftxqkWA1EFz7jv6lDMtQ&access_token=eyJhbGciOiJodHRwOi8vd3d3LnczLm9yZy8yMDAxLzA0L3htbGRzaWctbW9yZSNobWFjLXNoYTI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImY3NTZjNmJjLTEwYTQtNGE0Ny1jM2IwLTA4ZGM1Yzc2Y2Q1OCIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6IkRyaXZlciIsImV4cCI6MTcxNDQ5ODM2MywiaXNzIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6NzA4Ny8iLCJhdWQiOiJodHRwczovL2xvY2FsaG9zdDo3MDg3LyJ9.fuxYpVypm3nzA15qMwbO9wrmszNV48cpKlHom--o6A8#' was not upgraded to websocket E/flutter (10329): #0 _WebSocketImpl.connect (dart:_http/websocket_impl.dart:1011:41) E/flutter (10329): #1 WebSocket.connect (dart:_http/websocket.dart:320:22) E/flutter (10329): #2 new IOWebSocketChannel.connect (package:web_socket_channel/io.dart:81:28) E/flutter (10329): #3 connect (package:web_socket_channel/src/_connect_io.dart:15:24) E/flutter (10329): #4 new WebSocketChannel.connect (package:web_socket_channel/src/channel.dart:144:16) E/flutter (10329): #5 WebSocketTransport.connect (package:signalr_netcore/web_socket_transport.dart:53:35) E/flutter (10329): E/flutter (10329): #6 HttpConnection._createTransport (package:signalr_netcore/http_connection.dart:529:9) E/flutter (10329): E/flutter (10329): #7 HttpConnection._startInternal (package:signalr_netcore/http_connection.dart:409:9) E/flutter (10329): E/flutter (10329): #8 HttpConnection.start (package:signalr_netcore/http_connection.dart:255:5) E/flutter (10329): E/flutter (10329): #9 HubConnection._startInternal (package:signalr_netcore/hub_connection.dart:222:5) E/flutter (10329): E/flutter (10329): #10 HubConnection._startWithStateTransitions (package:signalr_netcore/hub_connection.dart:204:7) E/flutter (10329): E/flutter (10329): #11 SignalRClientService._openConnection (package:humydrivermobile/services/signalr/signalr_service.dart:117:9) E/flutter (10329): E/flutter (10329): #12 SignalRClientService._initConnection (package:humydrivermobile/services/signalr/signalr_service.dart:80:5) E/flutter (10329): E/flutter (10329): [2024-04-30 16:26:38.922895 SignalR LatLng] error: null message: HttpConnection.stopConnection(Unknown) called while in state ConnectionState.Connected. message: null

[2024-04-30 16:26:38.923305 SignalR LatLng] error: null message: Connection disconnected. message: null

[2024-04-30 16:26:38.924468 SignalR LatLng] error: null message: HubConnection.connectionClosed(null) called while in state HubConnectionState.Connecting. message: null

[2024-04-30 16:26:38.925441 SignalR LatLng] error: null message: Hub handshake failed with error 'The underlying connection was closed before the hub handshake could complete.' during start(). Stopping HubConnection. message: null

[2024-04-30 16:26:38.926642 SignalR LatLng] error: null message: Call to HttpConnection.stop(Exception: The underlying connection was closed before the hub handshake could complete.) ignored because the connection is already in the disconnected state. message: null `

thudaohd commented 1 week ago

@abdalazeezalyosfi i have the same issue. have you had the solution for this?

frosterlolz commented 1 week ago

If u need to send authorization token in headers (it works only with IOWebSocketChannel)- u may declare ur own transport (class implements ITransport), copy authors implementation, but replace block with injecting token in queryParams, then use ur own IOWebSocketChannel override method result like this:

@override
  Future<void> connect(String? url, TransferFormat transferFormat) async {
    assert(url != null);

    _logger?.finest('(WebSockets transport) Connecting');

    final websocketCompleter = Completer();
    var opened = false;
    url = url!.replaceFirst('http', 'ws');
    _logger?.finest("WebSocket try connecting to '$url'.");
    final token = await _accessTokenFactory?.call();
    _webSocket = IOWebSocketChannel.connect(
      Uri.parse(url),
      headers:
          token?.isEmpty ?? true ? null : {'Authorization': 'Bearer $token'},
    );
    opened = true;
    if (!websocketCompleter.isCompleted) websocketCompleter.complete();
    _logger?.info("WebSocket connected to '$url'.");
    _webSocketListenSub = _webSocket!.stream.listen(
      // onData
      (message) {
        if (_logMessageContent && message is String) {
          _logger?.finest(
            '(WebSockets transport) data received. message ${getDataDetail(message, _logMessageContent)}.',
          );
        } else {
          _logger?.finest('(WebSockets transport) data received.');
        }
        if (onReceive != null) {
          try {
            onReceive!(message);
          } catch (error) {
            _logger?.severe(
              '(WebSockets transport) error calling onReceive, error: $error',
            );
            _close();
          }
        }
      },

      // onError
      onError: (Object? error) {
        final e = error ?? 'Unknown websocket error';
        if (!websocketCompleter.isCompleted) {
          websocketCompleter.completeError(e);
        }
      },

      // onDone
      onDone: () {
        // Don't call close handler if connection was never established
        // We'll reject the connect call instead
        if (opened) {
          if (onClose != null) {
            onClose!();
          }
        } else {
          if (!websocketCompleter.isCompleted) {
            websocketCompleter
                .completeError('There was an error with the transport.');
          }
        }
      },
    );

    return websocketCompleter.future;
  }