deepstreamIO / deepstream.io-client-java

The Java/Android Client for deepstream.io
Other
35 stars 37 forks source link

Android/Java client SDK : Blocks main thread for login error #140

Open irfaan008 opened 7 years ago

irfaan008 commented 7 years ago

I am using below code to login to deepstream

private static void loginToDeepStream() {
    try {
        client = new DeepstreamClient(Const.CONST_CHAT_HOST);
        client.setRuntimeErrorHandler(new DeepstreamRuntimeErrorHandler() {
            @Override
            public void onException(Topic topic, Event event, String s) {
                log("Error : via callback" + s);
                client.close();
            }
        });
        LoginResult result = client.login();
        if (result.loggedIn()) {
            log("realtime server ready");
        } else log("realtime server not ready");
    } catch (DeepstreamException ex) {
        log("error : " + ex.getStackTrace());
    } catch (URISyntaxException ex) {
        log("error : " + ex.getStackTrace());
    }
}

I tried to call this function from main thread and from background thread both, but whenever network goes offline, it calls setRuntimeErrorHandler and shows black screen on device (android). Seems it tries to reconnect again.

How can I force deepstream to make connections on background instead of main thread. Currently even I am calling this method from doInBackground method of AsyncTask class, it blocks UI when setRuntimeErrorHandler gets call .

Please assist me better way if any to perform login and reconnection code without blocking UI thread

kirankiru commented 7 years ago

Even i am Facing the same issue. is there any solution for this?

yasserf commented 7 years ago

Im terribly sorry about this, we have a few issues raised about threading.

We are generally going to do a small rewrite soon to reflect alot of lessons learnt and will introduce async methods to allow users to deal with threading themselves if desired.

irfaan008 commented 7 years ago

@yasserf It would be really good if this handling could be done easily at mobile end as mobile app loses network more frequently and those network exception must be handled internally at deepstream end. Along with that deepstream should also expose method to override the exception behaviour and should notify the activity/service of no network access

cdigiacinto commented 7 years ago

Same issue also for me, do you feel we are going to see a solution for this any time soon?

yasserf commented 7 years ago

Hey! We are working really hard to getting a new revamped JS and Java client out that addresses these problems. We will be looking at this next week and should have a beta out very soon.

irfaan008 commented 7 years ago

Thanks Yasser, for update. Let me know if I can help you in anyway. ᐧ

Irfan Raza mailTo: irfaan.aa@gmail.com New Delhi, India

On Thu, Nov 2, 2017 at 8:46 PM, Yasser Fadl notifications@github.com wrote:

Hey! We are working really hard to getting a new revamped JS and Java client out that addresses these problems. We will be looking at this next week and should have a beta out very soon.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/deepstreamIO/deepstream.io/issues/742#issuecomment-341454838, or mute the thread https://github.com/notifications/unsubscribe-auth/ADTJTsY_-nj0qR-yafaJJgC9eUZcEN9Jks5sydzYgaJpZM4OQNGp .