sacOO7 / socketcluster-client-java

Native java and android client for socketcluster framework in node.js
http://socketcluster.io/
Apache License 2.0
94 stars 42 forks source link

Socket Basic Listener does not receive messages in few phones. #43

Open aalap03 opened 5 years ago

aalap03 commented 5 years ago

I am using this code to listen to the socket messages from our server.

Issue is I am testing with 2 samsung galaxy S7Edge phones both API level 26 and it one phone the socket messages works and in other phone it does not. Another test phone I am working with is Samsung S5 Neo with API 24 and it works with that phone.

I have looked into the the phones notification settings but it looks good.

Please let me know what phone settings I need to look at or what is the issue in the below code on setting the SocketClusterService.

Library Version: 1.7.5

public class SocketClusterService extends IntentService implements BasicListener {

private static final String SERVER_URL = "url"
Socket socket;
Socket.Channel channel;
EventBus bus = EventBus.getDefault();

public SocketClusterService() {
    super("SocketClusterService");
}
@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "onCreate: socket:");
}

@Override
public void onDestroy() {
    super.onDestroy();
}

// Will be called asynchronously by Android
@Override
protected void onHandleIntent(Intent intent) {
    this.socket = new Socket(SERVER_URL + cobaltStore.getToken());
    socket.setListener(this);

    //This will set automatic-reconnection to server with delay of 2 seconds and repeating it for 30 times
    socket.setReconnection(new ReconnectStrategy().setDelay(2000).setMaxAttempts(30));
    socket.connect();

    channel = socket.createChannel("channelName");
    channel.subscribe((name, error, data) -> {
        Log.d(TAG, "onHandleIntent: name " + channel.getChannelName());
        Log.d(TAG, "onHandleIntent: error " + error);
        Log.d(TAG, "onHandleIntent: data " + data);
    });

    channel.onMessage((channelName, object) -> {
                 //use object data..!!
    });
}

@Subscribe
public void onEvent(CobaltStore.CobaltStoreChangeEvent event) {

    Log.e(TAG, "EVENT");

    if (channel != null) {
        channel.publish("We come in peace!");
    }
}

@Override
public void onConnected(Socket socket, Map<String, List<String>> headers) {
    Log.e(TAG, "onConnected");
    Log.d(TAG, "onConnected: " + headers);

}

@Override
public void onDisconnected(Socket socket, WebSocketFrame serverCloseFrame, WebSocketFrame clientCloseFrame, boolean closedByServer) {
    Log.e(TAG, "onDisconnected");
}

@Override
public void onConnectError(Socket socket, WebSocketException exception) {
    Log.e(TAG, "onConnectError ", exception);
}

@Override
public void onAuthentication(Socket socket, Boolean status) {
    Log.d(TAG, "onAuthentication: status " + status);
}

@Override
public void onSetAuthToken(String token, Socket socket) {  socket.setAuthToken(token);    }

}

sacOO7 commented 5 years ago

Hi @aalap03 , can you provide your exact problem? I need little more description... It will be helpful if you can provide me with little description about where exactly it get stuck.

aalap03 commented 5 years ago

I subscribe to the server channel to receive updates and I receive messages in onMessage method.

I use 3 Test phones for development purpose, The Issue is on one of my test phones (Galaxy S7 Edge API 26), I don't receive Socket Updates. The phones in which it works is another Galaxy s7Edge with API 26 and Galaxy s5 NEO API 24.

I checked the not working phone's notification settings and all looks fine. I am not able to figure out what can be the issue here.

sacOO7 commented 5 years ago

sorry @aalap03 , I am still looking into the issue. I am planning to use OkHTTP websockets instead of current websocket library.... Will push the code till end of this week.

SanderVeer commented 5 years ago

@sacOO7 Can you give us some more info on your estimated timeline for the OkHTTP socket integration? It's something we're definitely looking forward to to use in our app

sacOO7 commented 5 years ago

Hi @aalap03 @SanderGemoro expect update from me on this till tomorrow šŸ‘

aalap03 commented 5 years ago

ok. Will wait for it eagerly.

sacOO7 commented 5 years ago

Hi @aalap03 , I have created branch for the same here https://github.com/sacOO7/socketcluster-client-java/tree/feature/okHTTP. Sorry for the delay. It was more work than expected. I will release unofficial version of the library so that you can test it on your phones asap.

sacOO7 commented 5 years ago

Hi @aalap03 @SanderGemoro I have published beta version related to above code. You can include it in your code by using

compile 'io.github.sac:SocketclusterClientJava:2.0.0-beta'

There are some method signatures which got changed due to change in library. But, you should be able to fix it without any problem. Please let me know if you face any problems with this latest release.

yasirtahir commented 4 years ago

I'm facing the same issue. The socket is working fine on Emulator but it's not working on real device. Can someone please comment if the issue is fixed?

sacOO7 commented 4 years ago

Will you able to reproduce the issue? Or put log messages for the same here..

On Wed, Apr 22, 2020, 16:02 Yasir Tahir notifications@github.com wrote:

I'm facing the same issue. The socket is working fine on Emulator but it's not working on real device. Can someone please comment if the issue is fixed?

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/43#issuecomment-617694535, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7S6SN5N3IICO2Z2WCVDZLRN3BTJANCNFSM4F6PMLAA .

yasirtahir commented 4 years ago

I'm testing the latest implementation on Emulator and it's working fine. But when I'm sending the complied APK to testing team, the socket updates aren't coming. Unfortunately, I don't have any real device with me at the moment to inspect the issue in detail with logs.

sacOO7 commented 4 years ago

Ohh.. okay.. I will look into it... But if you get logs or detailed description of the error... It will be super useful to me šŸ™‚

On Wed, Apr 22, 2020, 16:22 Yasir Tahir notifications@github.com wrote:

I'm testing the latest implementation on Emulator and it's working fine. But when I'm sending the complied APK to testing team, the socket updates aren't coming. Unfortunately, I don't have any real device with me at the moment to inspect the issue in detail with logs.

ā€” You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sacOO7/socketcluster-client-java/issues/43#issuecomment-617704052, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD7S6SOU6A5LQYFNAPQU3XTRN3D57ANCNFSM4F6PMLAA .