Explorar el Código

有socket连接再打招呼

tags/A.2.3.0.0
李俊才 hace 2 años
padre
commit
d6364543e4
Se han modificado 3 ficheros con 30 adiciones y 10 borrados
  1. +17
    -9
      app/src/main/java/com/aispeech/nativedemo/face/FaceChatGreetingQueueMode.java
  2. +6
    -1
      app/src/main/java/com/aispeech/nativedemo/network/ws/DigiWebSocketServer.java
  3. +7
    -0
      app/src/main/java/com/aispeech/nativedemo/network/ws/WebSocketManager.java

+ 17
- 9
app/src/main/java/com/aispeech/nativedemo/face/FaceChatGreetingQueueMode.java Ver fichero

@@ -6,6 +6,7 @@ import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Log;

import com.aispeech.nativedemo.DuiApplication;
import com.aispeech.nativedemo.MainActivity;
import com.aispeech.nativedemo.asr.observer.DuiMessageObserver;
import com.aispeech.nativedemo.config.Config;
@@ -21,6 +22,7 @@ import com.aispeech.nativedemo.entity.Skill;
import com.aispeech.nativedemo.entity.Stranger;
import com.aispeech.nativedemo.log.Logger;
import com.aispeech.nativedemo.network.ws.MessageUtils;
import com.aispeech.nativedemo.network.ws.WebSocketManager;
import com.aispeech.nativedemo.utils.BmpCompressUtils;
import com.aispeech.nativedemo.utils.HttpUtil;
import com.aispeech.nativedemo.utils.StatusUtils;
@@ -719,13 +721,14 @@ public class FaceChatGreetingQueueMode implements ChatMode {
continue;
}
if (!value.hasBeenGreeted && type > 0) {
value.last_greet_time = time;
value.hasBeenGreeted = true;
if (type != NEED_LEAVE_GREETING_CUSTOM) {
greetingResp = null;
}
Log.e("testtrack", "type " + greetingType+ " greetingResp " + greetingResp + " skill " + skill + " greeting emp eid " + value + " greeting duration " + (System.currentTimeMillis() - value.last_in_time));
sendGreeting(value, skill, greetingResp);
if (sendGreeting(value, skill, greetingResp)) {
value.last_greet_time = time;
value.hasBeenGreeted = true;
Log.e("testtrack", "type " + greetingType+ " greetingResp " + greetingResp + " skill " + skill + " greeting emp eid " + value + " greeting duration " + (System.currentTimeMillis() - value.last_in_time));
}
return;
}
}
@@ -743,19 +746,23 @@ public class FaceChatGreetingQueueMode implements ChatMode {
}
if (!value.hasBeenGreeted && (((time - value.last_in_time) >= UNKNOWN_GREETING_DURATION) || value.hasBeenIdentify)
&& type > 0) {
value.last_greet_time = time;
value.hasBeenGreeted = true;
Log.e("testtrack", "greeting trackId " + value.trackId + " old value " + value + " greeting duration " + (System.currentTimeMillis() - value.last_in_time));
if (type != NEED_LEAVE_GREETING_CUSTOM) {
greetingResp = null;
}
sendGreeting(value, skill, greetingResp);
if (sendGreeting(value, skill, greetingResp)) {
value.last_greet_time = time;
value.hasBeenGreeted = true;
Log.e("testtrack", "greeting trackId " + value.trackId + " old value " + value + " greeting duration " + (System.currentTimeMillis() - value.last_in_time));
}
break;
}
}
}

public void sendGreeting(PersonInfo message, Skill skill, String greetingLeaveResp) {
public boolean sendGreeting(PersonInfo message, Skill skill, String greetingLeaveResp) {
if (!WebSocketManager.getInstance(DuiApplication.getContext()).isSocketOpen()) {
return false;
}
try {
JSONObject obj = new JSONObject();
obj.put("type", "greeting");
@@ -814,6 +821,7 @@ public class FaceChatGreetingQueueMode implements ChatMode {
} catch (JSONException e) {
e.printStackTrace();
}
return true;
}

public void sendStrangerToServer() {


+ 6
- 1
app/src/main/java/com/aispeech/nativedemo/network/ws/DigiWebSocketServer.java Ver fichero

@@ -50,6 +50,7 @@ public class DigiWebSocketServer extends WebSocketServer {
private static final String TAG = "DigiWebSocketServer";
public Long heartbeatTime = 0l;
public Context context;
public boolean isOpen = false;
public List<WebSocket> mConns = new ArrayList<>();

public DigiWebSocketServer(InetSocketAddress host, Context context) {
@@ -76,14 +77,18 @@ public class DigiWebSocketServer extends WebSocketServer {
if (MainActivity.instance != null) {
MainActivity.instance.onSocketOpen(InitView.INIT_SUCCESS);
}
isOpen = true;
}

@Override
public void onClose(WebSocket conn, int code, String reason, boolean remote) {
Logger.e(conn.getRemoteSocketAddress() + "onClose()服务器关闭");
Logger.e(conn.getRemoteSocketAddress() + "onClose()服务器关闭 " + mConns.size());
Utils.websocketList.remove(conn.getRemoteSocketAddress().toString());
mConns.remove(conn);
removeConnection(conn);
if (mConns.size() == 0) {
isOpen = false;
}
MqttManager.getInstance(MainActivity.instance).getFileUploadPath(Config.ErrorEvent.ERROR_UPLOAD_WARNING, Config.ErrorEvent.ERROR_LEVEL_2, "socket_status", "onClose");
}



+ 7
- 0
app/src/main/java/com/aispeech/nativedemo/network/ws/WebSocketManager.java Ver fichero

@@ -121,4 +121,11 @@ public class WebSocketManager {
wsServer.removeAllConn();
}
}

public boolean isSocketOpen() {
if (wsServer == null) {
return false;
}
return wsServer.isOpen;
}
}

Cargando…
Cancelar
Guardar