Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[Android] support for hot updates under specified ports
Browse files Browse the repository at this point in the history
  • Loading branch information
erha19 authored and zshshr committed Nov 27, 2018
1 parent 18fe480 commit 6e9edfc
Showing 1 changed file with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand All @@ -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() {

}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6e9edfc

Please sign in to comment.