Search in sources :

Example 1 with DefaultWebSocketAdapter

use of com.benmu.framework.adapter.ws.DefaultWebSocketAdapter in project WeexErosFramework by bmfe.

the class LightlyWebSocketAdapter method connect.

public void connect(String url, String protocol, EventListener listener, String instanceId) {
    if (TextUtils.isEmpty(instanceId)) {
        // invalidate instanceId
        listener.onError(BMWSCode.INVALID_INSTANCEID.getReason());
        return;
    }
    DefaultWebSocketAdapter defaultWebSocketAdapter = mAdapters.get(instanceId);
    if (defaultWebSocketAdapter != null) {
        // mutli adapter for this instanceId
        // destory adapter
        defaultWebSocketAdapter.destroy(BMWSCode.REPEAT_WEBSOCKET.getCode(), BMWSCode.REPEAT_WEBSOCKET.getReason());
        newInstance(instanceId, url, protocol, listener);
    // create
    } else {
        // create
        newInstance(instanceId, url, protocol, listener);
    }
}
Also used : DefaultWebSocketAdapter(com.benmu.framework.adapter.ws.DefaultWebSocketAdapter)

Example 2 with DefaultWebSocketAdapter

use of com.benmu.framework.adapter.ws.DefaultWebSocketAdapter in project WeexErosFramework by bmfe.

the class LightlyWebSocketAdapter method newInstance.

private void newInstance(String instanceId, String url, String protocol, EventListener listener) {
    DefaultWebSocketAdapter webSocketInstance = new DefaultWebSocketAdapter();
    webSocketInstance.connect(url, protocol, listener, null);
    mAdapters.put(instanceId, webSocketInstance);
}
Also used : DefaultWebSocketAdapter(com.benmu.framework.adapter.ws.DefaultWebSocketAdapter)

Example 3 with DefaultWebSocketAdapter

use of com.benmu.framework.adapter.ws.DefaultWebSocketAdapter in project WeexErosFramework by bmfe.

the class LightlyWebSocketAdapter method onEvent.

@Subscribe
public void onEvent(Intent intent) {
    if (WXConstant.ACTION_WEEX_REFRESH.equals(intent.getAction())) {
        // refresh check mediator
        String instanceId = intent.getStringExtra("instanceId");
        if (!TextUtils.isEmpty(instanceId)) {
            DefaultWebSocketAdapter defaultWebSocketAdapter = mAdapters.get(instanceId);
            if (defaultWebSocketAdapter != null) {
                // instance has destroy
                defaultWebSocketAdapter.destroy(BMWSCode.INVALID_INSTANCEID.getCode(), BMWSCode.INVALID_INSTANCEID.getReason());
                mAdapters.remove(instanceId);
            }
        }
    }
}
Also used : DefaultWebSocketAdapter(com.benmu.framework.adapter.ws.DefaultWebSocketAdapter) Subscribe(com.squareup.otto.Subscribe)

Example 4 with DefaultWebSocketAdapter

use of com.benmu.framework.adapter.ws.DefaultWebSocketAdapter in project WeexErosFramework by bmfe.

the class DebuggerWebSocket method connect.

private void connect(String url) {
    // connect when interceptor close
    if (!Constant.INTERCEPTOR_ACTIVE.equals(SharePreferenceUtil.getInterceptorActive(BMWXEnvironment.mApplicationContext))) {
        Log.e(TAG, "connecting");
        mActice = true;
        // create new instance when webSocketInstance has connected
        if (webSocketInstance.isConnected()) {
            webSocketInstance = new DefaultWebSocketAdapter();
        }
        webSocketInstance.connect(url, "", eventListent, new WSConfig(true, 10));
        webSocketInstance.setConnected(true);
    } else {
        close();
        mActice = false;
    }
}
Also used : WSConfig(com.benmu.framework.adapter.ws.WSConfig) DefaultWebSocketAdapter(com.benmu.framework.adapter.ws.DefaultWebSocketAdapter)

Aggregations

DefaultWebSocketAdapter (com.benmu.framework.adapter.ws.DefaultWebSocketAdapter)4 WSConfig (com.benmu.framework.adapter.ws.WSConfig)1 Subscribe (com.squareup.otto.Subscribe)1