move debugger to doric

This commit is contained in:
pengfei.zhou 2019-08-09 16:32:38 +08:00
parent 73b9d97e6d
commit 7f8d579c0f
7 changed files with 86 additions and 42 deletions

View File

@ -23,7 +23,6 @@ dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3' implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':doric') implementation project(':doric')
implementation 'org.nanohttpd:nanohttpd:2.3.1'
implementation 'com.github.bumptech.glide:glide:4.8.0' implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'com.github.bumptech.glide:annotations:4.8.0' implementation 'com.github.bumptech.glide:annotations:4.8.0'
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1'

View File

@ -1,40 +0,0 @@
package com.github.penfeizhou.doricdemo;
import android.content.Context;
import android.content.res.AssetManager;
import java.io.IOException;
import java.io.InputStream;
import fi.iki.elonen.NanoHTTPD;
/**
* @Description: com.github.penfeizhou.doricdemo
* @Author: pengfei.zhou
* @CreateDate: 2019-08-03
*/
public class LocalServer extends NanoHTTPD {
private final Context context;
public LocalServer(Context context, int port) {
super(port);
this.context = context;
}
@Override
public Response serve(IHTTPSession session) {
String url = session.getUri();
if (url.startsWith("/assets/")) {
String fileName = url.substring("/assets/".length());
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open(fileName);
return newFixedLengthResponse(Response.Status.OK, "text/plain", inputStream, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
}
return newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld");
}
}

View File

@ -7,6 +7,7 @@ import android.widget.FrameLayout;
import com.github.penfeizhou.doric.Doric; import com.github.penfeizhou.doric.Doric;
import com.github.penfeizhou.doric.DoricContext; import com.github.penfeizhou.doric.DoricContext;
import com.github.penfeizhou.doric.dev.LocalServer;
import com.github.penfeizhou.doric.utils.DoricUtils; import com.github.penfeizhou.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSONBuilder; import com.github.pengfeizhou.jscore.JSONBuilder;
@ -33,5 +34,4 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }

View File

@ -42,4 +42,5 @@ dependencies {
api 'com.github.pengfeizhou:jsc4a:0.1.0' api 'com.github.pengfeizhou:jsc4a:0.1.0'
implementation "com.squareup.okhttp3:okhttp:3.11.0" implementation "com.squareup.okhttp3:okhttp:3.11.0"
implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1' implementation 'com.github.penfeizhou.android.animation:glide-plugin:1.0.1'
api 'org.nanohttpd:nanohttpd:2.3.1'
} }

View File

@ -0,0 +1 @@
../../../../../js-framework/debugger

View File

@ -0,0 +1,70 @@
package com.github.penfeizhou.doric.dev;
import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;
import android.webkit.MimeTypeMap;
import java.io.IOException;
import java.io.InputStream;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;
import fi.iki.elonen.NanoHTTPD;
/**
* @Description: com.github.penfeizhou.doricdemo
* @Author: pengfei.zhou
* @CreateDate: 2019-08-03
*/
public class LocalServer extends NanoHTTPD {
private final Context context;
public LocalServer(Context context, int port) {
super(port);
this.context = context;
}
private static String getIpAddressString() {
try {
for (Enumeration<NetworkInterface> enNetI = NetworkInterface
.getNetworkInterfaces(); enNetI.hasMoreElements(); ) {
NetworkInterface netI = enNetI.nextElement();
for (Enumeration<InetAddress> enumIpAddr = netI
.getInetAddresses(); enumIpAddr.hasMoreElements(); ) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (inetAddress instanceof Inet4Address && !inetAddress.isLoopbackAddress()) {
return inetAddress.getHostAddress();
}
}
}
} catch (SocketException e) {
e.printStackTrace();
}
return "0.0.0.0";
}
@Override
public void start() throws IOException {
super.start();
Log.d("Debugger", String.format("Open http://%s:8910/debugger.html to start debug", getIpAddressString()));
}
@Override
public Response serve(IHTTPSession session) {
String url = session.getUri();
String fileName = url.substring(1);
AssetManager assetManager = context.getAssets();
try {
InputStream inputStream = assetManager.open("debugger/" + fileName);
String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileName.substring(fileName.lastIndexOf(".") + 1));
return NanoHTTPD.newFixedLengthResponse(Response.Status.OK, mimeType, inputStream, inputStream.available());
} catch (IOException e) {
e.printStackTrace();
}
return NanoHTTPD.newFixedLengthResponse(NanoHTTPD.Response.Status.OK, "text/html", "HelloWorld");
}
}

View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Doric控制台</title>
</head>
<body>
<h1 style="text-align:center">Doric控制台</h1>
</body>
</html>