Search in sources :

Example 1 with EzyDisconnectionEvent

use of com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent in project ezyfox-server-android-client by youngmonkeys.

the class EzyDisconnectionHandler method handle.

@Override
public final void handle(EzyDisconnectionEvent event) {
    String reasonName = EzyDisconnectReasons.getDisconnectReasonName(event.getReason());
    EzyLogger.info("handle disconnection, reason: " + reasonName);
    preHandle(event);
    EzyClientConfig config = client.getConfig();
    EzyReconnectConfig reconnectConfig = config.getReconnect();
    boolean shouldReconnect = shouldReconnect(event);
    boolean mustReconnect = reconnectConfig.isEnable() && event.getReason() != EzyDisconnectReason.UNAUTHORIZED.getId() && event.getReason() != EzyDisconnectReason.CLOSE.getId() && shouldReconnect;
    boolean reconnecting = false;
    client.setStatus(EzyConnectionStatus.DISCONNECTED);
    if (mustReconnect)
        reconnecting = client.reconnect();
    if (reconnecting) {
        onReconnecting(event);
    } else {
        onDisconnected(event);
    }
    postHandle(event);
}
Also used : EzyClientConfig(com.tvd12.ezyfoxserver.client.config.EzyClientConfig) EzyReconnectConfig(com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)

Example 2 with EzyDisconnectionEvent

use of com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent in project ezyfox-server-android-client by youngmonkeys.

the class EzySocketClient method processStatuses.

protected void processStatuses() {
    socketStatuses.popAll(localSocketStatuses);
    for (int i = 0; i < localSocketStatuses.size(); ++i) {
        EzySocketStatus status = localSocketStatuses.get(i);
        if (status == EzySocketStatus.CONNECTED) {
            EzyEvent evt = new EzyConnectionSuccessEvent();
            socketEventQueue.addEvent(evt);
        } else if (status == EzySocketStatus.CONNECT_FAILED) {
            EzyEvent evt = new EzyConnectionFailureEvent(connectionFailedReason);
            socketEventQueue.addEvent(evt);
            break;
        } else if (status == EzySocketStatus.DISCONNECTED) {
            EzyEvent evt = new EzyDisconnectionEvent(disconnectReason);
            socketEventQueue.addEvent(evt);
            break;
        }
    }
    localSocketStatuses.clear();
}
Also used : EzyEvent(com.tvd12.ezyfoxserver.client.event.EzyEvent) EzyDisconnectionEvent(com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent) EzyConnectionFailureEvent(com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent) EzySocketStatus(com.tvd12.ezyfoxserver.client.constant.EzySocketStatus) EzyConnectionSuccessEvent(com.tvd12.ezyfoxserver.client.event.EzyConnectionSuccessEvent)

Aggregations

EzyClientConfig (com.tvd12.ezyfoxserver.client.config.EzyClientConfig)1 EzyReconnectConfig (com.tvd12.ezyfoxserver.client.config.EzyReconnectConfig)1 EzySocketStatus (com.tvd12.ezyfoxserver.client.constant.EzySocketStatus)1 EzyConnectionFailureEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionFailureEvent)1 EzyConnectionSuccessEvent (com.tvd12.ezyfoxserver.client.event.EzyConnectionSuccessEvent)1 EzyDisconnectionEvent (com.tvd12.ezyfoxserver.client.event.EzyDisconnectionEvent)1 EzyEvent (com.tvd12.ezyfoxserver.client.event.EzyEvent)1