Giter Site home page Giter Site logo

Comments (3)

umairali4433 avatar umairali4433 commented on August 16, 2024

i was facing the same issue no one helped so what i did was i just created listner for every 3 second if my hub is disconnected then do reconnect sample code:
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:signalr_core/signalr_core.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('HubConnection Status Checker'),
),
body: Center(
child: HubConnectionStatusChecker(),
),
),
);
}
}

class HubConnectionStatusChecker extends StatefulWidget {
@OverRide
_HubConnectionStatusCheckerState createState() => _HubConnectionStatusCheckerState();
}

class _HubConnectionStatusCheckerState extends State {
late HubConnection _hubConnection;
late Timer _timer;

@OverRide
void initState() {
super.initState();

// Initialize your HubConnection here
_hubConnection = HubConnectionBuilder()
  .withUrl('your_hub_connection_url')
  .build();

// Start checking the connection status every second
_timer = Timer.periodic(Duration(seconds: 1), (timer) {
  // Check the connection status
  if (_hubConnection.state == HubConnectionState.Connected) {
    print('HubConnection is connected');
  } else {
    print('HubConnection is not connected');
    // Optionally, try to start the connection again
    // _hubConnection.start();
  }
});

}

@OverRide
void dispose() {
// Cancel the timer and dispose the HubConnection
_timer.cancel();
_hubConnection.stop();
super.dispose();
}

@OverRide
Widget build(BuildContext context) {
return Text('Checking HubConnection status...');
}
}

and it worked perfectly now i am not facing this issue

from signalr_client.

os01ri avatar os01ri commented on August 16, 2024

facing the same issue in android devices

from signalr_client.

xaldarof avatar xaldarof commented on August 16, 2024

facing the same issue in android and iOS devices

from signalr_client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.