|
|
@@ -26,7 +26,10 @@ import com.android.volley.VolleyError;
|
|
|
import com.ntels.kneet.v3.R;
|
|
|
import com.ntels.kneet.v3.common.AppConfig;
|
|
|
import com.ntels.kneet.v3.common.Constants;
|
|
|
+import com.ntels.kneet.v3.common.c_interface.OnDataSendToReslut;
|
|
|
+import com.ntels.kneet.v3.common.http.HttpSend;
|
|
|
import com.ntels.kneet.v3.common.netatmo.SampleHttpClient;
|
|
|
+import com.ntels.kneet.v3.common.util.Dlog;
|
|
|
import com.ntels.kneet.v3.common.util.LogUtil;
|
|
|
import com.ntels.kneet.v3.common.util.Util;
|
|
|
import com.ntels.kneet.v3.common.websocket.WebSocketService;
|
|
|
@@ -46,8 +49,9 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
|
|
|
/*통신 관련*/
|
|
|
private int iType = 0;
|
|
|
- private static final int MSG_COM_P_NETATMO_REFRESH_TOKEN = 1;
|
|
|
+ private static final int MSG_COM_P_NETATMO_REFRESH_TOKEN = 1;
|
|
|
private static final int MSG_COM_P_NETATMO_HOMEDATA = 2;
|
|
|
+ private static final int MSG_COM_G_NETATMO_COMMAND_PING = 3;
|
|
|
|
|
|
/*공통*/
|
|
|
private Activity act;
|
|
|
@@ -62,6 +66,8 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
private Animation loadingAnimation;
|
|
|
private String sCameraId = "";
|
|
|
private String sCameraUrl = "";
|
|
|
+ private String sLocalCameraUrl = "";
|
|
|
+ private boolean isLocalPing = false;
|
|
|
|
|
|
/**
|
|
|
* <PRE>
|
|
|
@@ -90,11 +96,14 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
sRefreshToken = getIntent().getStringExtra(Constants.EXTRA_REFRESH_TOKEN);
|
|
|
sCameraId = getIntent().getStringExtra(Constants.EXTRA_CAMERA_ID);
|
|
|
}
|
|
|
+ util.getView(act, R.id.btnClose).setOnClickListener(this);
|
|
|
startLoading();
|
|
|
}
|
|
|
|
|
|
private void setDisp() {
|
|
|
- util.getView(act, R.id.btnClose).setOnClickListener(this);
|
|
|
+ if (isLoading) {
|
|
|
+ loadingAnimation.cancel();
|
|
|
+ }
|
|
|
vvCameraView = (VideoView) findViewById(R.id.vvCameraView);
|
|
|
MediaController mc = new MediaController(this);
|
|
|
vvCameraView.setMediaController(mc);
|
|
|
@@ -172,6 +181,9 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
case MSG_COM_P_NETATMO_HOMEDATA:
|
|
|
netatmoHomeData();
|
|
|
break;
|
|
|
+ case MSG_COM_G_NETATMO_COMMAND_PING:
|
|
|
+ send_G_cloud_netatmo_command_ping();
|
|
|
+ break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
@@ -227,10 +239,6 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
ArrayList<HashMap<String, Object>> alCameraList =
|
|
|
sampleHttpClient.parseNetatmoCamera(jsonObject);
|
|
|
processCurrentCameraUrl(alCameraList);
|
|
|
- if (isLoading) {
|
|
|
- loadingAnimation.cancel();
|
|
|
- }
|
|
|
- setDisp();
|
|
|
} catch (JSONException e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
@@ -296,13 +304,97 @@ public class Things_Device_Netatmo_Camera_Detail extends CustomActivity implemen
|
|
|
private void processCurrentCameraUrl(ArrayList<HashMap<String, Object>> alCameraList) {
|
|
|
for (HashMap<String, Object> hmCamera : alCameraList) {
|
|
|
if (hmCamera.get("id").equals(sCameraId)) {
|
|
|
+ sCameraUrl = util.null2string(hmCamera.get("vpn_url"));
|
|
|
if (((Boolean) hmCamera.get("is_local")).booleanValue()) {
|
|
|
- sCameraUrl = util.null2string(hmCamera.get("vpn_url")) + "/live/index_local.m3u8";
|
|
|
+ ComHandler.sendEmptyMessageDelayed(MSG_COM_G_NETATMO_COMMAND_PING, 10);
|
|
|
} else {
|
|
|
- sCameraUrl = util.null2string(hmCamera.get("vpn_url")) + "/live/index.m3u8";
|
|
|
+ sCameraUrl += "/live/index.m3u8";
|
|
|
+ setDisp();
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <PRE>
|
|
|
+ * 1. MethodName: send_G_cloud_netatmo_command_ping
|
|
|
+ * 2. ClassName :
|
|
|
+ * 3. Comment : [Send][GET]네타모 카메라의 로컬 IP Address를 조회한다.
|
|
|
+ * 4. Developer : 정백호
|
|
|
+ * 5. Created : 2016. 09.
|
|
|
+ * </PRE>
|
|
|
+ */
|
|
|
+ private void send_G_cloud_netatmo_command_ping() {
|
|
|
+ String sHTTP_camera_url = "";
|
|
|
+ try {
|
|
|
+ HttpSend httpSend;
|
|
|
+
|
|
|
+ // httpSend = new HttpSend(act, !swipeRefreshLayout.isRefreshing());
|
|
|
+ httpSend = new HttpSend(act, !isLoading);
|
|
|
+
|
|
|
+ httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
|
|
|
+ @Override public void resultResponse(com.ntels.kneet.v3.common.http.Response result) {
|
|
|
+
|
|
|
+ result_G_cloud_netatmo_command_ping(result);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (isLocalPing) {
|
|
|
+ sHTTP_camera_url = sLocalCameraUrl;
|
|
|
+ } else {
|
|
|
+ sHTTP_camera_url = sCameraUrl;
|
|
|
+ }
|
|
|
+
|
|
|
+ httpSend.G_cloud_netatmo_command_ping(sHTTP_camera_url);
|
|
|
+ } catch (Exception ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * <PRE>
|
|
|
+ * 1. MethodName: result_G_cloud_netatmo_command_ping
|
|
|
+ * 2. ClassName :
|
|
|
+ * 3. Comment : [Result]네타모 카메라의 로컬 IP Address를 조회한다.
|
|
|
+ * 4. Developer : 정백호
|
|
|
+ * 5. Created : 2016. 09.
|
|
|
+ * </PRE>
|
|
|
+ */
|
|
|
+ private void result_G_cloud_netatmo_command_ping(com.ntels.kneet.v3.common.http.Response rpResult) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ if ( rpResult.getStatusCode() == 200 ) {
|
|
|
+ HashMap<String, Object> hmMap = util.jsonToMap(rpResult.getContent());
|
|
|
+ if ( hmMap.size() > 0 ) {
|
|
|
+ if (!isLocalPing) { // vpn_url로 ping을 날렸을때 local_url이 결과로 오면 다시 local_url로 ping을 날린다.
|
|
|
+ isLocalPing = true;
|
|
|
+ sLocalCameraUrl = util.null2string(hmMap.get(Constants.HTTP_local_url));
|
|
|
+ ComHandler.sendEmptyMessageDelayed(MSG_COM_G_NETATMO_COMMAND_PING, 10);
|
|
|
+ } else { // local_url로 ping을 날려 같은 local_url이 결과로 오는지 확인되면 vpn_url 뒤에 /live/index_local.m3u8를 붙인다.
|
|
|
+ isLocalPing = false;
|
|
|
+// LogUtil.i(TAG, "hmMap : " + hmMap.toString());
|
|
|
+ sCameraUrl += "/live/index_local.m3u8";
|
|
|
+ setDisp();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ JSONObject joResult = new JSONObject(rpResult.getContent());
|
|
|
+ Dlog.v(joResult.toString());
|
|
|
+ if (isLoading) {
|
|
|
+ loadingAnimation.cancel();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception ex) {
|
|
|
+ if (isLoading) {
|
|
|
+ loadingAnimation.cancel();
|
|
|
+ }
|
|
|
+ ex.printStackTrace();
|
|
|
+ // TODO : 에러 처리 추가
|
|
|
+ if (isLocalPing) { // 같은 local network에 있지 않을때는 vpn_url로 영상 플레이
|
|
|
+ isLocalPing = false;
|
|
|
+ sCameraUrl += "/live/index.m3u8";
|
|
|
+ setDisp();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|