zshshr closed pull request #1820: [Android] support for hot updates under 
specified ports
URL: https://github.com/apache/incubator-weex/pull/1820
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java 
b/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
index 8a5408daf8..01f496de5b 100644
--- a/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
+++ b/android/playground/app/src/main/java/com/alibaba/weex/WXPageActivity.java
@@ -54,14 +54,18 @@
 import com.alibaba.weex.https.WXRequestListener;
 import com.taobao.weex.IWXRenderListener;
 import com.taobao.weex.RenderContainer;
+import com.taobao.weex.WXEnvironment;
 import com.taobao.weex.WXSDKEngine;
 import com.taobao.weex.WXSDKInstance;
 import com.taobao.weex.appfram.navigator.IActivityNavBarSetter;
+import com.taobao.weex.bridge.WXBridgeManager;
+import com.taobao.weex.common.IWXDebugProxy;
 import com.taobao.weex.common.WXRenderStrategy;
 import com.taobao.weex.ui.component.NestedContainer;
 import com.taobao.weex.ui.component.WXComponent;
 import com.taobao.weex.ui.component.WXVContainer;
 import com.taobao.weex.utils.WXFileUtils;
+import com.taobao.weex.utils.WXJsonUtils;
 import com.taobao.weex.utils.WXLogUtils;
 
 import java.io.File;
@@ -70,6 +74,8 @@
 import java.net.URL;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 
 public class WXPageActivity extends WXBaseActivity implements 
IWXRenderListener, Handler.Callback, WXSDKInstance.NestedInstanceInterceptor {
@@ -182,7 +188,7 @@ public void run() {
         ctx.getWindow().getDecorView().getWindowVisibleDisplayFrame(outRect);
         mConfigMap.put("bundleUrl", mUri.toString());
         String path = "file".equals(mUri.getScheme()) ? assembleFilePath(mUri) 
: mUri.toString();
-        mInstance.render(path, WXFileUtils.loadAsset(path, 
WXPageActivity.this),
+        mInstance.render(TAG, WXFileUtils.loadAsset(path, WXPageActivity.this),
             mConfigMap, null,
             WXRenderStrategy.APPEND_ASYNC);
       }
@@ -242,13 +248,8 @@ private void loadWXfromService(final String url) {
       public void onSuccess(WXHttpTask task) {
         Log.i(TAG, "into--[http:onSuccess] url:" + url);
         try {
-          Uri uri = Uri.parse(url);
           mConfigMap.put("bundleUrl", url);
-          if (uri.getPath().endsWith(".wlasm")){
-            mInstance.render(TAG, task.response.data, mConfigMap, null);
-          } else {
-            mInstance.render(TAG, new String(task.response.data, "utf-8"), 
mConfigMap, null, WXRenderStrategy.APPEND_ASYNC);
-          }
+          mInstance.render(TAG, new String(task.response.data, "utf-8"), 
mConfigMap, null, WXRenderStrategy.APPEND_ASYNC);
         } catch (UnsupportedEncodingException e) {
           e.printStackTrace();
         }
@@ -270,14 +271,28 @@ public void onError(WXHttpTask task) {
    */
   private void startHotRefresh() {
     try {
-      String host = new URL(mUri.toString()).getHost();
-      String wsUrl = "ws://" + host + ":8082";
+      URL url = new URL(mUri.toString());
+      String host = url.getHost();
+      String query = url.getQuery();
+      String wsport = getUrlParam("wsport", query);
+      String wsUrl = "ws://" + host + ":" + (wsport.equals("") ? "8082" : 
wsport) ;
       mWXHandler.obtainMessage(Constants.HOT_REFRESH_CONNECT, 0, 0, 
wsUrl).sendToTarget();
     } catch (MalformedURLException e) {
       e.printStackTrace();
     }
   }
 
+  private String getUrlParam(String key, String queryString) {
+    String regex = "[?|&]?" + key + "=([^&]+)";
+    Pattern p = Pattern.compile(regex);
+    Matcher matcher = p.matcher(queryString);
+    if (matcher.find()) {
+      return matcher.group(1);
+    } else {
+      return "";
+    }
+  }
+
   private void addOnListener() {
 
   }
@@ -517,8 +532,8 @@ protected void onStop() {
   private void registerBroadcastReceiver() {
     mReceiver = new RefreshBroadcastReceiver();
     IntentFilter filter = new IntentFilter();
-    filter.addAction(WXSDKInstance.ACTION_DEBUG_INSTANCE_REFRESH);
-    filter.addAction(WXSDKInstance.ACTION_INSTANCE_RELOAD);
+    filter.addAction(IWXDebugProxy.ACTION_DEBUG_INSTANCE_REFRESH);
+    filter.addAction(IWXDebugProxy.ACTION_INSTANCE_RELOAD);
 
     registerReceiver(mReceiver, filter);
   }
@@ -588,8 +603,8 @@ public boolean setNavBarTitle(String param) {
   public class RefreshBroadcastReceiver extends BroadcastReceiver {
     @Override
     public void onReceive(Context context, Intent intent) {
-      if (WXSDKInstance.ACTION_INSTANCE_RELOAD.equals(intent.getAction()) ||
-              
WXSDKInstance.ACTION_DEBUG_INSTANCE_REFRESH.equals(intent.getAction())) {
+      if (IWXDebugProxy.ACTION_INSTANCE_RELOAD.equals(intent.getAction()) ||
+              
IWXDebugProxy.ACTION_DEBUG_INSTANCE_REFRESH.equals(intent.getAction())) {
         // String myUrl = intent.getStringExtra("url");
         // Log.e("WXPageActivity", "RefreshBroadcastReceiver reload onReceive 
ACTION_DEBUG_INSTANCE_REFRESH mBundleUrl:" + myUrl + " mUri:" + mUri);
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to