package com.allfootball.news.net;
import com.taobao.weex.devtools.debug.IWebSocketClient;
import com.taobao.weex.devtools.websocket.CloseCodes;
import java.util.concurrent.TimeUnit;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import okio.ByteString;
public class CustomWebSocketClient implements IWebSocketClient {
private WebSocket ws;
@Override
public boolean isOpen() {
return ws != null;
}
@Override
public void connect(String wsAddress, final WSListener listener) {
OkHttpClient okHttpClient = new OkHttpClient
.Builder()
//设置读取超时时间
.readTimeout(5, TimeUnit.SECONDS)
// 设置写的超时时间
.writeTimeout(5, TimeUnit.SECONDS)
//设置连接超时时间
.connectTimeout(5, TimeUnit.SECONDS)
.build();
Request request = new Request.Builder().url(wsAddress).build();
ws = okHttpClient.newWebSocket(request, new WebSocketListener() {
@Override
public void onOpen(WebSocket webSocket, Response response) {
ws = webSocket;
listener.onOpen();
}
@Override
public void onMessage(WebSocket webSocket, String text) {
listener.onMessage(text);
}
@Override
public void onMessage(WebSocket webSocket, ByteString bytes) {
listener.onMessage(bytes.utf8());
}
@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
listener.onClose();
}
@Override
public void onFailure(WebSocket webSocket, Throwable t, Response response) {
listener.onFailure(t);
}
});
}
@Override
public void close() {
if (ws != null) {
ws.close(CloseCodes.NORMAL_CLOSURE, "Normal closure");
}
}
@Override
public void sendMessage(int requestId, String message) {
if (ws != null) {
ws.send(message);
}
}
}
error
E/weex: WxDebug-new >>>> reload=null
E/weex: No implementation found for void com.taobao.weex.bridge.WXJsFunctions.initWxBridge(java.lang.Object, java.lang.String) (tried Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge and Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge__Ljava_lang_Object_2Ljava_lang_String_2)
E/weex: [WXBridgeManager] invokeInitFramework java.lang.UnsatisfiedLinkError: No implementation found for void com.taobao.weex.bridge.WXJsFunctions.initWxBridge(java.lang.Object, java.lang.String) (tried Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge and Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge__Ljava_lang_Object_2Ljava_lang_String_2)
at com.taobao.weex.bridge.WXJsFunctions.initWxBridge(Native Method)
at com.taobao.weex.devtools.debug.DebugBridge.initFramework(DebugBridge.java:70)
at com.taobao.weex.devtools.debug.DebugBridge.initFrameworkEnv(DebugBridge.java:76)
at com.taobao.weex.bridge.WXBridgeManager.initFramework(WXBridgeManager.java:1659)
at com.taobao.weex.bridge.WXBridgeManager.invokeInitFramework(WXBridgeManager.java:1615)
at com.taobao.weex.bridge.WXBridgeManager.handleMessage(WXBridgeManager.java:1488)
at com.taobao.weex.common.WXThread$SafeCallback.handleMessage(WXThread.java:73)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.os.HandlerThread.run(HandlerThread.java:61)
D/CLog: [WXBridgeManager] invokeInitFramework java.lang.UnsatisfiedLinkError: No implementation found for void com.taobao.weex.bridge.WXJsFunctions.initWxBridge(java.lang.Object, java.lang.String) (tried Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge and Java_com_taobao_weex_bridge_WXJsFunctions_initWxBridge__Ljava_lang_Object_2Ljava_lang_String_2)
at com.taobao.weex.bridge.WXJsFunctions.initWxBridge(Native Method)
at com.taobao.weex.devtools.debug.DebugBridge.initFramework(DebugBridge.java:70)
at com.taobao.weex.devtools.debug.DebugBridge.initFrameworkEnv(DebugBridge.java:76)
at com.taobao.weex.bridge.WXBridgeManager.initFramework(WXBridgeManager.java:1659)
at com.taobao.weex.bridge.WXBridgeManager.invokeInitFramework(WXBridgeManager.java:1615)
at com.taobao.weex.bridge.WXBridgeManager.handleMessage(WXBridgeManager.java:1488)
at com.taobao.weex.common.WXThread$SafeCallback.handleMessage(WXThread.java:73)
at android.os.Handler.dispatchMessage(Handler.java:107)
at android.os.Looper.loop(Looper.java:194)
at android.os.HandlerThread.run(HandlerThread.java:61)
build.grade
rewrite socket
error