Coder Social home page Coder Social logo

Comments (11)

konsultaner avatar konsultaner commented on June 19, 2024 1

I'll think about it. Seems like a good idea.

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024 1

@jiajun-ifanr could you try this:

options: ClientConnectOptions(

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024 1

Hi @konsultaner , I find that after the client is reconnected, it doesn't seem to auto resubscribe to what it has already subscribed to. That's to say, it doesn't listen to data changes again.

@jiajun-ifanr Yes this is totally expected behaviour. This feature is not implemented yet. You may open a new Issue for this feature if you want it. As soon as I get the time, I will implement it. There will be an additional subscribePermanently as soon as it is implemented. The same issue exists with registrations. They don't stay alive. For now, you may collect your subscriptions and resubscribe them manually in the reconnect event.

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024

@jiajun-ifanr I'm on it! Havn't had time to work on this yet. I hope you can wait a little longer

from connectanum-dart.

jiajun-ifanr avatar jiajun-ifanr commented on June 19, 2024

@jiajun-ifanr I'm on it! Havn't had time to work on this yet. I hope you can wait a little longer

No problem! Thank you!

from connectanum-dart.

jiajun-ifanr avatar jiajun-ifanr commented on June 19, 2024

@konsultaner I tried with the above example, but it seems like it will reconnect only when a session is being initialized. Also when a function is passed to _client.onNextTryToReconnect.listen, and while it is reconnecting, the function doesn't execute.

I want retries are made when a connection is ongoing and very suddenly the network is disconnected due to some network issues (e.g. connection lost / network change).

Is there any way to detect if the connection is lost and then retry connection?

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024

What transport do you use? Actually it should also work on connection loss.

unawaited(transport.onConnectionLost.future.then((_) async {

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024

No, you're right.. it does not push the event...

from connectanum-dart.

konsultaner avatar konsultaner commented on June 19, 2024

I added a quick fix. but I need to write some tests on it... Should work if you use the latest master

from connectanum-dart.

jiajun-ifanr avatar jiajun-ifanr commented on June 19, 2024

Looks like it works. Thanks again!

from connectanum-dart.

jiajun-ifanr avatar jiajun-ifanr commented on June 19, 2024

Hi @konsultaner , I find that after the client is reconnected, it doesn't seem to auto resubscribe to what it has already subscribed to. That's to say, it doesn't listen to data changes again.

Please take a glance at the below code as an example. It has a class called Wamp and it is first instantiated and connected to our server on page load. There's a Subscribe button and when you click on it, it will subscribe to a topic.

Here's a scenario where the network is suddenly disconnected (for e.g. 40 seconds). Then the network is back online, and the client begins to retry. Once it is successfully reconnected, it is supposed to listen data changes again. But it isn't.

Also when I click the Subscribe button again, a Bad state: No element exception is thrown. Any chance to get it worked?

import 'package:flutter/material.dart';
import 'package:connectanum/connectanum.dart';
import 'package:connectanum/json.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Home(),
    );
  }
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  Wamp wamp = new Wamp();

  @override
  void initState() {
    super.initState();
    wamp.connect();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Test App'),
      ),
      body: Center(
          child: RaisedButton(
        onPressed: () {
          wamp.subscribe();
        },
        child: Text('Subscribe'),
      )),
    );
  }
}

class Wamp {
  Client client;
  Session session;

  void connect() async {
    String url =
        'wss://a4d2d62965ddb57fa4d6.ws.myminapp.com/ws/hydrogen/?x-hydrogen-client-id=a4d2d62965ddb57fa4d6&x-hydrogen-env-id=f1eeb28c9552d4c83df1&authorization=Hydrogen-r1%204prp5lsv9ox8n8r4y6ux6hwuguf9r8fg';

    client = Client(
      realm: 'com.ifanrcloud',
      transport: WebSocketTransport(
        url,
        new Serializer(),
        WebSocketSerialization.SERIALIZATION_JSON,
      ),
    );

    try {
      session = await client
          .connect(
            options: ClientConnectOptions(
              reconnectCount: 10,
              reconnectTime: Duration(
                milliseconds: 200,
              ),
            ),
          )
          .first;

      client.onNextTryToReconnect.listen((passedOptions) {
        print('retrying...');
        passedOptions.reconnectTime = Duration(
          milliseconds: passedOptions.reconnectTime.inMilliseconds + 500,
        );
      });
    } on Abort catch (abort) {
      print(abort.message.message);
    }
  }

  void subscribe() async {
    String topic = 'com.ifanrcloud.schema_event.danmu_jiajun.on_create';

    var options = new SubscribeOptions();
    options.addCustomValue("where", (serializerType) => "{}");

    Subscribed subscription = await session.subscribe(topic, options: options);
    print('subscribed successfully...');

    // listen to data change
    // supposed to listen to changes again on reconnection. But it isn't.
    subscription.eventStream.listen(
      (event) {
        print(event.argumentsKeywords.toString());
      },
    );
  }
}

I have tested my JS application counterpart and it works. So it might not be a backend related issue.
Is there a workaround for this?

from connectanum-dart.

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.