websocket dev tool
This commit is contained in:
parent
76fe0f9044
commit
f46ac2ae73
2
.gitignore
vendored
2
.gitignore
vendored
@ -12,7 +12,7 @@
|
||||
bin/
|
||||
gen/
|
||||
out/
|
||||
|
||||
test/
|
||||
# Gradle files
|
||||
.gradle/
|
||||
build/
|
||||
|
@ -9,6 +9,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name="com.github.penfeizhou.doricdemo.MainActivity">
|
||||
<intent-filter>
|
||||
|
@ -20,13 +20,11 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "demo for test");
|
||||
doricContext.callEntity("__init__", new JSONBuilder()
|
||||
.put("width", ViewGroup.LayoutParams.MATCH_PARENT)
|
||||
.put("height", ViewGroup.LayoutParams.MATCH_PARENT));
|
||||
DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "test");
|
||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
doricContext.callEntity("log");
|
||||
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
|
||||
Doric.connectDevKit("wss://192.168.11.38:7777");
|
||||
Doric.connectDevKit("ws://192.168.11.38:7777");
|
||||
LocalServer localServer = new LocalServer(getApplicationContext(), 8910);
|
||||
try {
|
||||
localServer.start();
|
||||
|
4
Android/app/src/main/res/xml/network_security_config.xml
Normal file
4
Android/app/src/main/res/xml/network_security_config.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<network-security-config>
|
||||
<base-config cleartextTrafficPermitted="true" />
|
||||
</network-security-config>
|
@ -1,6 +1,7 @@
|
||||
package com.github.penfeizhou.doric;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.github.penfeizhou.doric.async.AsyncResult;
|
||||
import com.github.penfeizhou.doric.plugin.DoricJavaPlugin;
|
||||
@ -8,6 +9,9 @@ import com.github.penfeizhou.doric.utils.DoricConstant;
|
||||
import com.github.penfeizhou.doric.utils.DoricMetaInfo;
|
||||
import com.github.penfeizhou.doric.shader.RootNode;
|
||||
import com.github.pengfeizhou.jscore.JSDecoder;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -24,6 +28,7 @@ public class DoricContext {
|
||||
private RootNode mRootNode = new RootNode(this);
|
||||
private final String source;
|
||||
private String script;
|
||||
private JSONObject initParams;
|
||||
|
||||
DoricContext(Context context, String contextId, String source) {
|
||||
this.mContext = context;
|
||||
@ -46,6 +51,13 @@ public class DoricContext {
|
||||
return doricContext;
|
||||
}
|
||||
|
||||
public void init(int width, int height) {
|
||||
this.initParams = new JSONBuilder()
|
||||
.put("width", width)
|
||||
.put("height", height).toJSONObject();
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
}
|
||||
|
||||
public AsyncResult<JSDecoder> callEntity(String methodName, Object... args) {
|
||||
return getDriver().invokeContextEntityMethod(mContextId, methodName, args);
|
||||
}
|
||||
@ -97,6 +109,7 @@ public class DoricContext {
|
||||
|
||||
public void reload(String script) {
|
||||
getDriver().createContext(mContextId, script, source);
|
||||
callEntity(DoricConstant.DORIC_ENTITY_INIT, this.initParams);
|
||||
}
|
||||
|
||||
public void onShow() {
|
||||
|
@ -51,7 +51,7 @@ public class WSClient extends WebSocketListener {
|
||||
String source = jsonObject.optString("source");
|
||||
String script = jsonObject.optString("script");
|
||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||
if (source.equals(context.getSource())) {
|
||||
if (source.contains(context.getSource())) {
|
||||
context.reload(script);
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,9 @@ import com.github.pengfeizhou.jscore.JSArray;
|
||||
import com.github.pengfeizhou.jscore.JSObject;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -32,6 +34,7 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
case "children":
|
||||
JSArray jsArray = prop.asArray();
|
||||
int i;
|
||||
List<ViewNode> tobeRemoved = new ArrayList<>();
|
||||
for (i = 0; i < jsArray.size(); i++) {
|
||||
JSValue jsValue = jsArray.get(i);
|
||||
if (!jsValue.isObject()) {
|
||||
@ -47,11 +50,23 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
child.mParent = this;
|
||||
child.mId = id;
|
||||
mChildrenNode.put(id, child);
|
||||
} else if (i != child.index) {
|
||||
mIndexInfo.remove(i);
|
||||
child.index = i;
|
||||
mView.removeView(child.getView());
|
||||
} else {
|
||||
if (i != child.index) {
|
||||
mIndexInfo.remove(i);
|
||||
child.index = i;
|
||||
mView.removeView(child.getView());
|
||||
}
|
||||
tobeRemoved.remove(child);
|
||||
}
|
||||
|
||||
ViewNode node = mIndexInfo.get(i);
|
||||
|
||||
if (node != null && node != child) {
|
||||
mView.removeViewAt(i);
|
||||
mIndexInfo.remove(i);
|
||||
tobeRemoved.add(node);
|
||||
}
|
||||
|
||||
ViewGroup.LayoutParams params = child.getLayoutParams();
|
||||
if (params == null) {
|
||||
params = generateDefaultLayoutParams();
|
||||
@ -62,14 +77,20 @@ public abstract class GroupNode<F extends ViewGroup> extends ViewNode<F> {
|
||||
mIndexInfo.put(i, child);
|
||||
}
|
||||
}
|
||||
while (i < mView.getChildCount()) {
|
||||
mView.removeViewAt(mView.getChildCount() - 1);
|
||||
if (mIndexInfo.get(i) != null) {
|
||||
mChildrenNode.remove(mIndexInfo.get(i).getId());
|
||||
|
||||
while (i < mIndexInfo.size()) {
|
||||
ViewNode node = mIndexInfo.get(i);
|
||||
if (node != null) {
|
||||
mChildrenNode.remove(node.getId());
|
||||
mIndexInfo.remove(i);
|
||||
tobeRemoved.remove(node);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
for (ViewNode node : tobeRemoved) {
|
||||
mChildrenNode.remove(node.getId());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.blend(view, layoutParams, name, prop);
|
||||
|
@ -15,4 +15,3 @@ program
|
||||
require('./scripts/watcher')
|
||||
})
|
||||
program.parse(process.argv)
|
||||
console.log(process.cwd())
|
5
doric-cli/package-lock.json
generated
5
doric-cli/package-lock.json
generated
@ -211,6 +211,11 @@
|
||||
"resolved": "https://registry.npm.taobao.org/picomatch/download/picomatch-2.0.7.tgz",
|
||||
"integrity": "sha1-UUFp2MfNC9vuzIomCeNKcWPeafY="
|
||||
},
|
||||
"qrcode-terminal": {
|
||||
"version": "0.12.0",
|
||||
"resolved": "https://registry.npmjs.org/qrcode-terminal/-/qrcode-terminal-0.12.0.tgz",
|
||||
"integrity": "sha512-EXtzRZmC+YGmGlDFbXKxQiMZNwCLEO6BANKXG4iCtSIM0yqc/pappSx3RIKr4r0uh5JsBckOXeKrB3Iz7mdQpQ=="
|
||||
},
|
||||
"readdirp": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npm.taobao.org/readdirp/download/readdirp-3.1.1.tgz",
|
||||
|
@ -24,6 +24,7 @@
|
||||
"chokidar": "^3.0.2",
|
||||
"commander": "^2.20.0",
|
||||
"nodejs-websocket": "^1.7.2",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"rollup": "^1.18.0",
|
||||
"shelljs": "^0.8.3",
|
||||
"typescript": "^3.5.3"
|
||||
|
@ -4,19 +4,48 @@ const fs = require("fs")
|
||||
|
||||
require('shelljs/global')
|
||||
|
||||
exec('npm run dev', () => {
|
||||
})
|
||||
ws.listen(7777)
|
||||
chokidar.watch(process.cwd() + "/bundle", {
|
||||
ignored: /(^|[\/\\])\../,
|
||||
}).on('all', (event, path) => {
|
||||
console.log('path is ', path)
|
||||
if (event === 'add' || event === 'change') {
|
||||
exec('npm run dev >/dev/null 2>&1', { async: true })
|
||||
console.warn('Waiting ...')
|
||||
setTimeout(() => {
|
||||
console.warn('Start watching')
|
||||
ws.listen(7777)
|
||||
chokidar.watch(process.cwd() + "/bundle", {
|
||||
ignored: /(^|[\/\\])\../,
|
||||
}).on('change', (path) => {
|
||||
console.log('path is ', path)
|
||||
fs.readFile(path, 'utf-8', (error, data) => {
|
||||
console.log('send data ', data)
|
||||
ws.connections.forEach(e => {
|
||||
e.sendText(data)
|
||||
e.sendText(JSON.stringify({
|
||||
script: data,
|
||||
source: path.match(/[^/\\]*$/)[0],
|
||||
}))
|
||||
})
|
||||
})
|
||||
});
|
||||
}, 3000);
|
||||
const os = require('os');
|
||||
|
||||
function getIPAdress() {
|
||||
const ret = []
|
||||
var interfaces = os.networkInterfaces();
|
||||
for (var devName in interfaces) {
|
||||
var iface = interfaces[devName];
|
||||
for (var i = 0; i < iface.length; i++) {
|
||||
var alias = iface[i];
|
||||
if (alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal) {
|
||||
ret.push(alias.address);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
const qrcode = require('qrcode-terminal');
|
||||
const ips = getIPAdress()
|
||||
console.log(`本机IP是${ips}`)
|
||||
ips.forEach(e => {
|
||||
console.log(`IP:${e}`)
|
||||
qrcode.generate(e, { small: true });
|
||||
})
|
||||
|
Reference in New Issue
Block a user