Coder Social home page Coder Social logo

actioncable-client-java's People

Contributors

h0jezvgoxfepbq2c avatar hosopy avatar macbury avatar shobhitic avatar tpmullan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

actioncable-client-java's Issues

应用再后台久了会内存溢出

#20873 OkHttp Dispatcher
java.lang.OutOfMemoryError
pthread_create (1040KB stack) failed: Try again
解析原始
}
1 java.lang.Thread.nativeCreate(Native Method)
2 java.lang.Thread.start(Thread.java:1063)
3 java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
4 java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1327)
5 java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:583)
6 com.hosopy.concurrent.EventLoop.post(EventLoop.java:65)
7 com.hosopy.concurrent.EventLoop.execute(EventLoop.java:46)
8 com.hosopy.actioncable.Connection$4.onMessage(Connection.java:266)
9 com.squareup.okhttp.internal.ws.RealWebSocket$1.a(RealWebSocket.java:53)
10 com.squareup.okhttp.internal.ws.WebSocketReader.d(WebSocketReader.java:220)
11 com.squareup.okhttp.internal.ws.WebSocketReader.a(WebSocketReader.java:101)
12 com.squareup.okhttp.internal.ws.RealWebSocket.a(RealWebSocket.java:95)
13 com.squareup.okhttp.ws.WebSocketCall.a(WebSocketCall.java:171)
14 com.squareup.okhttp.ws.WebSocketCall.a(WebSocketCall.java:42)
15 com.squareup.okhttp.ws.WebSocketCall$1.a(WebSocketCall.java:102)
16 com.squareup.okhttp.Call$AsyncCall.f(Call.java:168)
17 com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33)
18 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
19 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
20 java.lang.Thread.run(Thread.java:818)

Failed to resolved "this dependency"

Hello I'm getting this error, and can't use any of the classes
I'm using
Android Gradle Plugin Version 7.0.4
Gradle Version 7.0.2

build.gradle(project)
buildscript {
repositories {
google()
mavenCentral()
maven { url "https://jitpack.io" }
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.4"
classpath "com.google.android.libraries.mapsplatform.secrets-gradle-plugin:secrets-gradle-plugin:2.0.0"
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

New Maintainer

Hi,

since there are many forks out there already I would be happy to help to merge things together in this repo? (Upgrade to okhttp 3, add isConnected-method to Connection,...).

Would you be interested in another maintainer for your repo?

Please let me know, thank you!

Crash on Android

10-02 18:37:26.946 3708-4058/com.company E/AndroidRuntime: FATAL EXCEPTION: EventLoop
Process: com.company, PID: 3708
java.lang.IllegalStateException: closed
at com.squareup.okhttp.internal.ws.RealWebSocket.sendMessage(RealWebSocket.java:109)
at com.hosopy.actioncable.Connection.doSend(Connection.java:221)
at com.hosopy.actioncable.Connection.access$500(Connection.java:22)
at com.hosopy.actioncable.Connection$3.run(Connection.java:165)
at com.hosopy.concurrent.EventLoop$2.run(EventLoop.java:69)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

It will create multiple connection with server when switch wifi

I use actionable to build a chat App, when I switch WIFI(eg. from wifi A to wifi B), it creates two connection to the server.

so when I send a message, the server will receive two messages.

After switching I will release all the connection, like set the consumer to null then recreate. but it did not work, it will create two connection to the server.

problem when trying to make a toast

.onFailed(new Subscription.FailedCallback() {
            @Override
            public void call(ActionCableException e) {
                Log.i("::CHECK", "onFailed");
                Log.i("::CHECK", e.getMessage());
                Toast.makeText(getApplicationContext(), "onFailed", Toast.LENGTH_SHORT).show(); //erro
            }
        }

When trying to change an imageview or make a Toast of not connected the app closes
Ex: above toast
What do I do?

Not building with gradle

Tried several times to build with Gradle but its not working Says its not found

compile 'com.github.hosopy:actioncable-client-java:0.1.1'

Socket cloesd after some Seconds

why the socket is closing after some time?
How can i Ping pong the server so socket wont get closed
my code is below

String wsuri = "ws://52.37.206.155/cable?" + "email=" + Constants.EMAIL
                + "&sessionToken=" + Constants.SESSION_TOKEN
                + "&client=" + Constants.CLIENT;
        URI uri = null;
        try {
            uri = new URI(wsuri);
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        Consumer.Options options = new Consumer.Options();
        options.reconnection = true;
        options.reconnectionMaxAttempts = 1000;
        options.reconnectionDelayMax = 10;
        consumer = ActionCable.createConsumer(uri, options);
        // 2. Create subscription
        Channel appearanceChannel = new Channel("ConversationsChannel");
        appearanceChannel.addParam("room", "conversations:" + conversation.getId());
        subscription = consumer.getSubscriptions().create(appearanceChannel);
        subscription
                .onConnected(new Subscription.ConnectedCallback() {
                    @Override
                    public void call() {
                        isConnected = true;
                        Log.v("onConnected", "subscription has been successfully completed");
                    }
                }).onRejected(new Subscription.RejectedCallback() {
            @Override
            public void call() {
                isConnected = false;
                Log.v("onRejected", "subscription is rejected by the server");
            }
        }).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() {
                // Called when the subscription has been closed
                Log.v("onDisconnected", "subscription has been closed");
            }
        }).onFailed(new Subscription.FailedCallback() {
            @Override
            public void call(final ActionCableException e) {
                isConnected = false;
                // Called when the subscription encounters any error
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(ConversationActivity.this, "Disconnected", Toast.LENGTH_SHORT).show();
                    }
                });
                Log.e("onFailed", "subscription encounters any error");
                e.printStackTrace();
            }
        });

        consumer.connect();

socket miss data while sending and receiving. due to socket closing after some seconds.

Message {"type":"welcome"}

I found WebSocketListener receives a message {"type":"welcome"} before receiving {"type":"confirm_subscription"}.

According to the actioncable(5.1.4) implementation, the message {"type":"welcome"} should work as an alternative of WebSocketListener#onOpen

https://github.com/rails/rails/blob/v5.1.4/actioncable/app/assets/javascripts/action_cable/connection.coffee#L88

  events:
    message: (event) ->
      return unless @isProtocolSupported()
      {identifier, message, type} = JSON.parse(event.data)
      switch type
        when message_types.welcome
          @monitor.recordConnect()
          @subscriptions.reload()
        when message_types.ping
          @monitor.recordPing()
        when message_types.confirmation
          @subscriptions.notify(identifier, "connected")
        when message_types.rejection
          @subscriptions.reject(identifier)
        else
          @subscriptions.notify(identifier, "received", message)

java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again

Thanks for open-sourcing this library. I'm using this in one of my projects,
and I recently found a crash from com.hosopy.actioncable.ConnectionMonitor.poll method

  java.lang.OutOfMemoryError: pthread_create (1040KB stack) failed: Try again
      at java.lang.Thread.nativeCreate(Native Method)
      at java.lang.Thread.start(Thread.java:1063)
      at java.util.Timer$TimerImpl.<init>(Timer.java:192)
      at java.util.Timer.<init>(Timer.java:365)
      at java.util.Timer.<init>(Timer.java:384)
      at java.util.Timer.<init>(Timer.java:391)
      at com.hosopy.actioncable.ConnectionMonitor.poll(ConnectionMonitor.java:69)
      at com.hosopy.actioncable.ConnectionMonitor.access$200(ConnectionMonitor.java:6)
      at com.hosopy.actioncable.ConnectionMonitor$1.run(ConnectionMonitor.java:75)
      at java.util.Timer$TimerImpl.run(Timer.java:284)

I found a relevant issue here http://stackoverflow.com/questions/35701501/throwing-outofmemoryerror-pthread-create-1040kb-stack-failed-try-again-when

I guess it's probably because the timer variable is created repeatedly on
https://github.com/hosopy/actioncable-client-java/blob/master/src/main/java/com/hosopy/actioncable/ConnectionMonitor.java#L69
but I haven't tested the fix.

It is hard to reproduce the issue because it only happens after the app's running for a long time.
Do you think making the timer variable to an instance variable would fix the issue?

reconnection问题

设置reconnection为true之后,就算socket连接成功了,也依旧是一直不停的重新连接

java.lang.OutOfMemoryError

java.lang.VMThread.create(Native Method)
2 java.lang.Thread.start(Thread.java:1029)
3 java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:920)
4 java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1327)
5 java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:583)
6 com.hosopy.concurrent.EventLoop.post(EventLoop.java:65)
7 com.hosopy.concurrent.EventLoop.execute(EventLoop.java:46)
8 com.hosopy.actioncable.Connection$4.onMessage(Connection.java:266)
image

consumer.disconnect() is not unsubscribing the subscriptions

I just realized that consumer.disconnect() doesn't clear the subscriptions - and I receive onReceived-Callbacks, even after I told the consumer to disconnect.

We should remove all subscriptions on disconnect, or am I wrong @hosopy ?
I'm happy to provide a PR, if this is the case.

Connection to action cable is failed every time. Guide me where i am wrong

URI uri = new URI("ws://94.177.249.182:3000/cable");
Consumer consumer = ActionCable.createConsumer(uri);

// 2. Create subscription
Channel appearanceChannel = new Channel("minutes");
Subscription subscription = consumer.getSubscriptions().create(appearanceChannel);

    subscription
            .onConnected(new Subscription.ConnectedCallback() {
                @Override
                public void call() {
                    Log.e("Cable","Connected");
                    // Called when the subscription has been successfully completed
                }
            }).onRejected(new Subscription.RejectedCallback() {
        @Override
        public void call() {
            // Called when the subscription is rejected by the server
            Log.e("Cable","Rejected");
        }
    }).onReceived(new Subscription.ReceivedCallback() {
        @Override
        public void call(JsonElement data) {
            // Called when the subscription receives data from the server
            Log.e("Data",data.getAsString());
        }
    }).onDisconnected(new Subscription.DisconnectedCallback() {
        @Override
        public void call() {
            // Called when the subscription has been closed
        }
    }).onFailed(new Subscription.FailedCallback() {
        @Override
        public void call(ActionCableException e) {
            // Called when the subscription encounters any error
            Log.e("Cable","Error occurred");
        }
    });

// 3. Establish connection
consumer.connect();

Calling onFailed callback method

Error message : java.net.ProtocolException: Expected HTTP 101 response but was '200 OK'

Web side it's working fine with local and global IP address, mobile side unable to make connection establishment.

Code reference:
`// 1. Setup
URI uri = null;
try {
uri = new URI("ws://192.168.2.10:3000");
} catch (URISyntaxException e) {
e.printStackTrace();
}

    Consumer.Options options = new Consumer.Options();
    options.reconnection = true;

    options.reconnectionMaxAttempts = 30;
    options.reconnectionDelay = 3;
    options.reconnectionDelayMax = 30;
    options.okHttpClientFactory = new Connection.Options.OkHttpClientFactory() {
        @Override
        public OkHttpClient createOkHttpClient() {
            final OkHttpClient client = new OkHttpClient();
            client.setRetryOnConnectionFailure(true);
            client.setConnectTimeout(5, TimeUnit.MINUTES);
            client.networkInterceptors().add(new Interceptor() {
                @Override
                public Response intercept(Chain chain) throws IOException {
                    return null;
                }
            });
            return client;
        }
    };

    consumer = ActionCable.createConsumer(uri,options);

    subscriptions = consumer.getSubscriptions();

    // 2. Create subscription
    Channel roomChannel = new Channel("RoomChannel");
    subscription = subscriptions.create(roomChannel);

    subscription
            .onConnected(new Subscription.ConnectedCallback() {
                @Override
                public void call() {
                    // Called when the subscription has been successfully completed
                    Log.i("CHAT", "onConnected ");
                    subscription.perform("Hi");
                }
            }).onRejected(new Subscription.RejectedCallback() {
        @Override
        public void call() {
            // Called when the subscription is rejected by the server
            Log.i("CHAT", "onRejected ");
        }
    }).onReceived(new Subscription.ReceivedCallback() {
        @Override
        public void call(JsonElement data) {
            // Called when the subscription receives data from the server
            Log.i("CHAT", "onReceived " + data.toString());
        }
    }).onDisconnected(new Subscription.DisconnectedCallback() {
        @Override
        public void call() {
            // Called when the subscription has been closed
            Log.i("CHAT", "onDisconnected ");
        }
    }).onFailed(new Subscription.FailedCallback() {
        @Override
        public void call(ActionCableException e) {
            // Called when the subscription encounters any error
            Log.i("CHAT", "onFailed " + e.getMessage());
        }
    });

    // 3. Establish connection
    consumer.connect();

// 4. Perform any action
subscription.perform("take_turn");`

Thanks in advance,
Vamsi

Readme change request: Origin header

Hello,
thank you very much for the awesome library. We had an issue to connect to server and we resolved that by seting Origin header. I think this should be documented in the README too: #21

Thanks,

David

problem when sending data

as sending parameters in perfom, I tried everything and do not send from android to rails, but if I can receive data from rails to android, is it some server-side configuration? or is there a method to send from android? Can colleagues help me?

Proguard rules

Which proguard rules I need to add for proper work when obfuscation enabled?

Upgrade of okhttp-ws from 2.5.0 to 2.7.5

The latest version of okhttp-ws 2.X is 2.7.5.
But current build.gradle uses 2.5.0.

dependencies {
    compile 'com.squareup.okhttp:okhttp-ws:2.5.0'
    compile 'com.google.code.gson:gson:2.3.1'

    testCompile 'junit:junit:4.11'
    testCompile 'org.hamcrest:hamcrest-all:1.3'
    testCompile 'com.squareup.okhttp:mockwebserver:2.5.0'
}

Try to upgrade and test.

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.