Coder Social home page Coder Social logo

Comments (5)

h0jeZvgoxFepBQ2C avatar h0jeZvgoxFepBQ2C commented on June 2, 2024 1

Maybe you only tried the release 0.2.RC1 - the unsubscribeAndDisconnect() method was implemented later, I was just referring to the corresponding git commit.

But you can try the 0.2.RC2 release, which I published right now: https://github.com/hosopy/actioncable-client-java/releases/tag/0.2.RC2

If there is any isses, I will reopen this ticket again - right now it works pretty fine for my company in production.

from actioncable-client-java.

h0jeZvgoxFepBQ2C avatar h0jeZvgoxFepBQ2C commented on June 2, 2024

I've added a method called consumer.unsubscribeAndDisconnect(), would be fine if someone could give feedback on this, see commit 69c519e

After using this method, I also don't get the invalid/unrequested callback calls again.
Unfortunately my test is broken, I don't know why right now...

from actioncable-client-java.

fabiantorresm avatar fabiantorresm commented on June 2, 2024

He agregado un método llamado consumer.unsubscribeAndDisconnect(), estaría bien si alguien pudiera dar su opinión sobre esto, vea cometer 69c519e

Después de usar este método, tampoco recibo nuevamente las llamadas de devolución de llamada no válidas / no solicitadas.
Desafortunadamente mi examen está roto, no sé por qué en este momento ...

I tried this change and it did not work, update to version 0.2 and it does not recognize the method. Thank you.

from actioncable-client-java.

fabiantorresm avatar fabiantorresm commented on June 2, 2024

It is now, I updated to version 0.2.RC2. A question this configuration is correct?

public static void connectToActionCable() throws URISyntaxException {

    String domain = "192.168.0.103:3000";
    // 1. Setup
    URI uri = null;
    try {
        uri = new URI("ws://".concat(domain).concat("/cable"));
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }

    Consumer.Options options = new Consumer.Options();
    options.reconnection = true;
    options.headers = new ArrayMap<>();
    options.headers.put("Origin", "http://".concat(domain));
    options.headers.put("Content-Type", "application/json");

    final Consumer consumer = ActionCable.createConsumer(uri, options);

    if (consumer.isConnected()){
        // 2. Create subscription
        Channel appearanceChannel = new Channel("BookChannel");
        final BookSubscription subscription = consumer.getSubscriptions().create(appearanceChannel, BookSubscription.class);
        Log.d("cableDebug", ""+subscription.getIdentifier().toString());
        subscription
                .onConnected(new Subscription.ConnectedCallback() {
                    @Override
                    public void call() {
                        Log.d("cableDebug", "onConnected");
                        subscription.join();
                    }
                })
                .onRejected(new Subscription.RejectedCallback() {
                    @Override
                    public void call() {
                        Log.d("cableDebug", "onRejected");
                        // Called when the subscription is rejected by the server
                    }
                })
                .onReceived(new Subscription.ReceivedCallback() {
                    @Override
                    public void call(JsonElement data) {
                        Gson gson = new Gson();
                        Log.d(TAG, "Datos recibidos: " + data);
                        //notification();
                    }
                })
                .onDisconnected(new Subscription.DisconnectedCallback() {
                    @Override
                    public void call() {
                        Log.d("cableDebug", "onDisconnected");
                        // Called when the subscription has been closed
                        consumer.unsubscribeAndDisconnect();
                    }
                }).onFailed(new Subscription.FailedCallback() {
            @Override
            public void call(ActionCableException e) {
                Log.d("cableDebug", "onFailed: " + e.getMessage());
                e.printStackTrace();
                // Called when the subscription encounters any error
                consumer.unsubscribeAndDisconnect();
            }
        });
        // 3. Establish connection

        consumer.connect();
    }else{
        consumer.connect();
    }

from actioncable-client-java.

fabiantorresm avatar fabiantorresm commented on June 2, 2024

Hi, sorry for the inconvenience. Will you have an example of this code in production? I am using evernote job Android for background work and every time this code is executed I create a new subscription.

from actioncable-client-java.

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.