Coder Social home page Coder Social logo

Comments (3)

macbury avatar macbury commented on June 11, 2024 1

In final version of rails 5 they did change few things to make more consistient in communication. I have fixed this issue with this pull request: #6

from actioncable-client-java.

hosopy avatar hosopy commented on June 11, 2024

Merge #6 and tagged as 0.1.1

from actioncable-client-java.

samkazmi avatar samkazmi commented on June 11, 2024

thanks for the replies
but i solved it by updating the okhttp library and options.reconnection = false; if reconnection is false then it doesn't disconnects so i did this for reconnecting

public void connect() {
        task = new TimerTask() {
            @Override
            public void run() {
                JsonObject jsonObject = new JsonObject();
                jsonObject.addProperty("channel", "ConversationsChannel");
                if (isConnected)
                    subscription.perform("subscribe", jsonObject);
            }};
        timer = new Timer();
        IntentFilter filter = new IntentFilter("com.pantera.thegrid.SOCKET_OPERATION");
        LocalBroadcastManager.getInstance(context).registerReceiver(receiver, filter);
        String wsuri = LINK + "email=" + Constants.EMAIL
                + "&sessionToken=" + Constants.SESSION_TOKEN
                + "&client=" + Constants.CLIENT;
        Log.v("connecting to", wsuri);
        URI uri = null;
        try {
            uri = new URI(wsuri);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        Consumer.Options options = new Consumer.Options();
        options.reconnection = false;
        options.reconnectionMaxAttempts = 5;
        options.reconnectionDelayMax = 1000 * 10;
        consumer = ActionCable.createConsumer(uri, options);
        Channel appearanceChannel = new Channel("ConversationsChannel");
        subscription = consumer.getSubscriptions().create(appearanceChannel);
        subscription
                .onConnected(new Subscription.ConnectedCallback() {
                    @Override
                    public void call() {
                        Log.v("onConnected", "subscription has been successfully completed");
                        isConnected = true;
                    }
                })
                .onRejected(new Subscription.RejectedCallback() {
                    @Override
                    public void call() {
                        Log.v("onRejected", "subscription is rejected by the server");
                        isConnected = false;
                    }
                })
                .onReceived(new Subscription.ReceivedCallback() {
                    @Override
                    public void call(final JsonElement data) {
                        Log.v("onReceived", "subscription receives data from the server " + data.toString());
                    }
                })
                .onDisconnected(new Subscription.DisconnectedCallback() {
                    @Override
                    public void call() {
                        isConnected = false;
                      //  disconnect();
                       // connect();
                    }
                })
                .onFailed(new Subscription.FailedCallback() {
                    @Override
                    public void call(final ActionCableException e) {
                        Log.e("onFailed", "subscription encounters any error " + e.toString());
                        isConnected = false;
                      //  disconnect();
                      //  connect();
                    }
                });
        consumer.connect();
        timer.schedule(task, 2000, 2000);
    }

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.