diff --git a/Android/app/src/main/java/pub/doric/demo/MainActivity.java b/Android/app/src/main/java/pub/doric/demo/MainActivity.java index 86b86dba..cddc1909 100644 --- a/Android/app/src/main/java/pub/doric/demo/MainActivity.java +++ b/Android/app/src/main/java/pub/doric/demo/MainActivity.java @@ -15,29 +15,33 @@ */ package pub.doric.demo; -import androidx.appcompat.app.AppCompatActivity; - import android.os.Bundle; +import android.view.KeyEvent; import android.view.ViewGroup; import android.widget.FrameLayout; +import androidx.appcompat.app.AppCompatActivity; + +import java.io.IOException; + +import pub.doric.dev.DevPanel; import pub.doric.Doric; import pub.doric.DoricContext; import pub.doric.dev.LocalServer; import pub.doric.utils.DoricUtils; -import java.io.IOException; - public class MainActivity extends AppCompatActivity { + private DevPanel mDevPanel = new DevPanel(); + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); 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.callEntity("log"); doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root)); Doric.connectDevKit("ws://192.168.11.38:7777"); LocalServer localServer = new LocalServer(getApplicationContext(), 8910); @@ -47,4 +51,12 @@ public class MainActivity extends AppCompatActivity { e.printStackTrace(); } } + + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) { + mDevPanel.show(getSupportFragmentManager(), "DevPanel"); + } + return super.onKeyDown(keyCode, event); + } } diff --git a/Android/app/src/main/res/layout/activity_main.xml b/Android/app/src/main/res/layout/activity_main.xml index 1b859062..8e62fba9 100644 --- a/Android/app/src/main/res/layout/activity_main.xml +++ b/Android/app/src/main/res/layout/activity_main.xml @@ -3,7 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context="com.github.penfeizhou.doricdemo.pub.doric.demo.MainActivity"> + tools:context=".MainActivity"> callEntity(String methodName, Object... args) { diff --git a/Android/doric/src/main/java/pub/doric/dev/DevPanel.java b/Android/doric/src/main/java/pub/doric/dev/DevPanel.java new file mode 100644 index 00000000..e5aa2bba --- /dev/null +++ b/Android/doric/src/main/java/pub/doric/dev/DevPanel.java @@ -0,0 +1,30 @@ +package pub.doric.dev; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; + +import pub.doric.R; + +public class DevPanel extends BottomSheetDialogFragment { + + public DevPanel() { + + } + + @Nullable + @Override + public View onCreateView( + @NonNull LayoutInflater inflater, + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState + ) { + return inflater.inflate(R.layout.layout_dev, container, false); + } +} diff --git a/Android/doric/src/main/java/pub/doric/engine/remote/RemoteJSExecutor.java b/Android/doric/src/main/java/pub/doric/engine/remote/RemoteJSExecutor.java index c625ff1f..b8ff35f0 100644 --- a/Android/doric/src/main/java/pub/doric/engine/remote/RemoteJSExecutor.java +++ b/Android/doric/src/main/java/pub/doric/engine/remote/RemoteJSExecutor.java @@ -4,13 +4,18 @@ import com.github.pengfeizhou.jscore.JSDecoder; import com.github.pengfeizhou.jscore.JavaFunction; import com.github.pengfeizhou.jscore.JavaValue; import com.google.gson.Gson; +import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; import org.jetbrains.annotations.NotNull; +import org.json.JSONObject; import java.io.EOFException; import java.net.ConnectException; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; @@ -25,13 +30,17 @@ public class RemoteJSExecutor { private final WebSocket webSocket; private final Gson gson = new Gson(); + private final Map globalFunctions = new HashMap<>(); + + private JSDecoder temp; + public RemoteJSExecutor() { OkHttpClient okHttpClient = new OkHttpClient .Builder() .readTimeout(10, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) .build(); - Request request = new Request.Builder().url("ws://192.168.24.166:2080").build(); + final Request request = new Request.Builder().url("ws://192.168.24.221:2080").build(); final Thread current = Thread.currentThread(); webSocket = okHttpClient.newWebSocket(request, new WebSocketListener() { @@ -55,43 +64,109 @@ public class RemoteJSExecutor { @Override public void onMessage(@NotNull WebSocket webSocket, @NotNull String text) { JsonElement je = gson.fromJson(text, JsonElement.class); - System.out.println(je); - LockSupport.unpark(current); + if (je instanceof JsonObject) { + JsonObject jo = ((JsonObject) je); + String cmd = jo.get("cmd").getAsString(); + switch (cmd) { + case "injectGlobalJSFunction": { + String name = jo.get("name").getAsString(); + JsonArray arguments = jo.getAsJsonArray("arguments"); + JSDecoder[] decoders = new JSDecoder[arguments.size()]; + for (int i = 0; i < arguments.size(); i++) { + if (arguments.get(i).isJsonPrimitive()) { + JsonPrimitive jp = ((JsonPrimitive) arguments.get(i)); + if (jp.isNumber()) { + ValueBuilder vb = new ValueBuilder(jp.getAsNumber()); + JSDecoder decoder = new JSDecoder(vb.build()); + decoders[i] = decoder; + } else if (jp.isBoolean()) { + ValueBuilder vb = new ValueBuilder(jp.getAsBoolean()); + JSDecoder decoder = new JSDecoder(vb.build()); + decoders[i] = decoder; + } else if (jp.isString()) { + ValueBuilder vb = new ValueBuilder(jp.getAsString()); + JSDecoder decoder = new JSDecoder(vb.build()); + decoders[i] = decoder; + } + } else { + try { + ValueBuilder vb = new ValueBuilder(new JSONObject(gson.toJson(arguments.get(i)))); + JSDecoder decoder = new JSDecoder(vb.build()); + decoders[i] = decoder; + } catch (Exception ex) { + ex.printStackTrace(); + } + + } + } + + + globalFunctions.get(name).exec(decoders); + } + + break; + case "invokeMethod": { + try { + Object result = jo.get("result"); + ValueBuilder vb = new ValueBuilder(result); + JSDecoder decoder = new JSDecoder(vb.build()); + temp = decoder; + System.out.println(result); + } catch (Exception ex) { + ex.printStackTrace(); + } finally { + LockSupport.unpark(current); + } + } + break; + } + } } }); LockSupport.park(current); } public String loadJS(String script, String source) { - JsonObject jo = new JsonObject(); - jo.addProperty("cmd", "loadJS"); - jo.addProperty("script", script); - jo.addProperty("source", source); - webSocket.send(gson.toJson(jo)); - - LockSupport.park(Thread.currentThread()); return null; } public JSDecoder evaluateJS(String script, String source, boolean hashKey) { - JsonObject jo = new JsonObject(); - jo.addProperty("cmd", "evaluateJS"); - jo.addProperty("script", script); - jo.addProperty("source", source); - jo.addProperty("hashKey", hashKey); - webSocket.send(gson.toJson(jo)); return null; } public void injectGlobalJSFunction(String name, JavaFunction javaFunction) { + globalFunctions.put(name, javaFunction); + + JsonObject jo = new JsonObject(); + jo.addProperty("cmd", "injectGlobalJSFunction"); + jo.addProperty("name", name); + webSocket.send(gson.toJson(jo)); } public void injectGlobalJSObject(String name, JavaValue javaValue) { } public JSDecoder invokeMethod(String objectName, String functionName, JavaValue[] javaValues, boolean hashKey) { - return null; + JsonObject jo = new JsonObject(); + jo.addProperty("cmd", "invokeMethod"); + jo.addProperty("objectName", objectName); + jo.addProperty("functionName", functionName); + + JsonArray ja = new JsonArray(); + for (JavaValue javaValue : javaValues) { + JsonObject argument = new JsonObject(); + argument.addProperty("type", javaValue.getType()); + argument.addProperty("value", javaValue.getValue()); + ja.add(argument); + } + jo.add("javaValues", ja); + + jo.addProperty("hashKey", hashKey); + webSocket.send(gson.toJson(jo)); + + LockSupport.park(Thread.currentThread()); + return temp; } public void destroy() { diff --git a/Android/doric/src/main/java/pub/doric/engine/remote/ValueBuilder.java b/Android/doric/src/main/java/pub/doric/engine/remote/ValueBuilder.java new file mode 100644 index 00000000..34aa21f0 --- /dev/null +++ b/Android/doric/src/main/java/pub/doric/engine/remote/ValueBuilder.java @@ -0,0 +1,91 @@ +package pub.doric.engine.remote; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.io.ByteArrayOutputStream; +import java.util.Iterator; + +/** + * Created by pengfei.zhou on 2018/4/17. + */ +public class ValueBuilder { + private final Object val; + + private void writeBoolean(ByteArrayOutputStream output, boolean b) { + output.write((byte) (b ? 1 : 0)); + } + + private void writeInt(ByteArrayOutputStream output, int i) { + output.write((byte) (i >>> 24)); + output.write((byte) (i >>> 16)); + output.write((byte) (i >>> 8)); + output.write((byte) i); + } + + private void writeDouble(ByteArrayOutputStream output, double d) { + long l = Double.doubleToRawLongBits(d); + output.write((byte) (l >>> 56)); + output.write((byte) (l >>> 48)); + output.write((byte) (l >>> 40)); + output.write((byte) (l >>> 32)); + output.write((byte) (l >>> 24)); + output.write((byte) (l >>> 16)); + output.write((byte) (l >>> 8)); + output.write((byte) l); + } + + private void writeString(ByteArrayOutputStream output, String S) { + byte[] buf; + try { + buf = S.getBytes("UTF-8"); + } catch (Exception e) { + buf = new byte[0]; + } + int i = buf.length; + writeInt(output, i); + output.write(buf, 0, i); + } + + + private void write(ByteArrayOutputStream output, Object O) { + if (O instanceof Number) { + output.write((byte) 'D'); + writeDouble(output, Double.valueOf(String.valueOf(O))); + } else if (O instanceof String) { + output.write((byte) 'S'); + writeString(output, (String) O); + } else if (O instanceof Boolean) { + output.write((byte) 'B'); + writeBoolean(output, (Boolean) O); + } else if (O instanceof JSONObject) { + output.write((byte) 'O'); + //writeBoolean(output, (Boolean) O); + Iterator iterator = ((JSONObject) O).keys(); + while (iterator.hasNext()) { + String key = iterator.next(); + write(output, key); + write(output, ((JSONObject) O).opt(key)); + } + output.write((byte) 'N'); + } else if (O instanceof JSONArray) { + output.write((byte) 'A'); + writeInt(output, ((JSONArray) O).length()); + for (int i = 0; i < ((JSONArray) O).length(); i++) { + write(output, ((JSONArray) O).opt(i)); + } + } else { + output.write((byte) 'N'); + } + } + + public ValueBuilder(Object o) { + this.val = o; + } + + public byte[] build() { + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + write(outputStream, val); + return outputStream.toByteArray(); + } +} \ No newline at end of file diff --git a/Android/doric/src/main/res/layout/layout_dev.xml b/Android/doric/src/main/res/layout/layout_dev.xml new file mode 100644 index 00000000..73192065 --- /dev/null +++ b/Android/doric/src/main/res/layout/layout_dev.xml @@ -0,0 +1,34 @@ + + + + + + + + + \ No newline at end of file diff --git a/demo/.vscode/launch.json b/demo/.vscode/launch.json new file mode 100644 index 00000000..39c84064 --- /dev/null +++ b/demo/.vscode/launch.json @@ -0,0 +1,24 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "node", + "request": "launch", + "name": "Debug TS", + "program": "${workspaceFolder}/${relativeFile}", + "preLaunchTask": "Doric Build", + "sourceMaps": true, + "serverReadyAction": { + "pattern": "listening on port ([0-9]+)", + "uriFormat": "http://localhost:%s", + "action": "openExternally" + }, + "outFiles": [ + "${workspaceFolder}/bundle/**/*.js" + ] + } + ] +} \ No newline at end of file diff --git a/demo/.vscode/tasks.json b/demo/.vscode/tasks.json new file mode 100644 index 00000000..d51f6710 --- /dev/null +++ b/demo/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "Doric Build", + "type": "shell", + "command": "doric build", + "group": "build", + "problemMatcher": [] + }, + { + "label": "Doric Clean", + "type": "shell", + "command": "doric clean", + "group": "build", + "problemMatcher": [] + }, + { + "label": "Doric Dev", + "type": "shell", + "command": "doric dev", + "group": "build", + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/demo/package-lock.json b/demo/package-lock.json index d6dd2ebe..790eaf55 100644 --- a/demo/package-lock.json +++ b/demo/package-lock.json @@ -10,9 +10,9 @@ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, "@types/node": { - "version": "12.11.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.1.tgz", - "integrity": "sha512-TJtwsqZ39pqcljJpajeoofYRfeZ7/I/OMUQ5pR4q5wOKf2ocrUvBAZUMhWsOvKx3dVc/aaV5GluBivt0sWqA5A==" + "version": "12.11.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.5.tgz", + "integrity": "sha512-LC8ALj/24PhByn39nr5jnTvpE7MujK8y7LQmV74kHYF5iQ0odCPkMH4IZNZw+cobKfSXqaC8GgegcbIsQpffdA==" }, "@types/resolve": { "version": "0.0.8", @@ -306,12 +306,14 @@ "doric": { "version": "file:../js-framework", "requires": { + "@types/ws": "^6.0.3", "reflect-metadata": "^0.1.13", "rollup": "^1.17.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-watch": "^4.3.1", "tslib": "^1.10.0", - "typescript": "^3.5.3" + "typescript": "^3.5.3", + "ws": "^7.2.0" }, "dependencies": { "@types/estree": { @@ -320,9 +322,9 @@ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, "@types/node": { - "version": "12.11.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.1.tgz", - "integrity": "sha512-TJtwsqZ39pqcljJpajeoofYRfeZ7/I/OMUQ5pR4q5wOKf2ocrUvBAZUMhWsOvKx3dVc/aaV5GluBivt0sWqA5A==" + "version": "12.11.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.5.tgz", + "integrity": "sha512-LC8ALj/24PhByn39nr5jnTvpE7MujK8y7LQmV74kHYF5iQ0odCPkMH4IZNZw+cobKfSXqaC8GgegcbIsQpffdA==" }, "@types/resolve": { "version": "0.0.8", @@ -332,6 +334,14 @@ "@types/node": "*" } }, + "@types/ws": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.3.tgz", + "integrity": "sha512-yBTM0P05Tx9iXGq00BbJPo37ox68R5vaGTXivs6RGh/BQ6QP5zqZDGWdAO6JbRE/iR1l80xeGAwCQS2nMV9S/w==", + "requires": { + "@types/node": "*" + } + }, "acorn": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", @@ -379,6 +389,11 @@ "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==" }, + "async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -2041,9 +2056,9 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "rollup": { - "version": "1.25.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.1.tgz", - "integrity": "sha512-K8ytdEzMa6anHSnfTIs2BLB+NXlQ4qmWwdNHBpYQNWCbZAzj+DRVk7+ssbLSgddwpFW1nThr2GElR+jASF2NPA==", + "version": "1.25.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.2.tgz", + "integrity": "sha512-+7z6Wab/L45QCPcfpuTZKwKiB0tynj05s/+s2U3F2Bi7rOLPr9UcjUwO7/xpjlPNXA/hwnth6jBExFRGyf3tMg==", "requires": { "@types/estree": "*", "@types/node": "*", @@ -2382,6 +2397,14 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "ws": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", + "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", + "requires": { + "async-limiter": "^1.0.0" + } } } }, @@ -2483,26 +2506,22 @@ "dependencies": { "abbrev": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "bundled": true, "optional": true }, "ansi-regex": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "bundled": true, "optional": true }, "aproba": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "bundled": true, "optional": true }, "are-we-there-yet": { "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "bundled": true, "optional": true, "requires": { "delegates": "^1.0.0", @@ -2511,14 +2530,12 @@ }, "balanced-match": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "bundled": true, "optional": true }, "brace-expansion": { "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "bundled": true, "optional": true, "requires": { "balanced-match": "^1.0.0", @@ -2527,38 +2544,32 @@ }, "chownr": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", - "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", + "bundled": true, "optional": true }, "code-point-at": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "bundled": true, "optional": true }, "concat-map": { "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "bundled": true, "optional": true }, "console-control-strings": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "bundled": true, "optional": true }, "core-util-is": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "bundled": true, "optional": true }, "debug": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "bundled": true, "optional": true, "requires": { "ms": "^2.1.1" @@ -2566,26 +2577,22 @@ }, "deep-extend": { "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "bundled": true, "optional": true }, "delegates": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "bundled": true, "optional": true }, "detect-libc": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", + "bundled": true, "optional": true }, "fs-minipass": { "version": "1.2.5", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz", - "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", + "bundled": true, "optional": true, "requires": { "minipass": "^2.2.1" @@ -2593,14 +2600,12 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "bundled": true, "optional": true }, "gauge": { "version": "2.7.4", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", - "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "bundled": true, "optional": true, "requires": { "aproba": "^1.0.3", @@ -2615,8 +2620,7 @@ }, "glob": { "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "bundled": true, "optional": true, "requires": { "fs.realpath": "^1.0.0", @@ -2629,14 +2633,12 @@ }, "has-unicode": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "bundled": true, "optional": true }, "iconv-lite": { "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "bundled": true, "optional": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" @@ -2644,8 +2646,7 @@ }, "ignore-walk": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz", - "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", + "bundled": true, "optional": true, "requires": { "minimatch": "^3.0.4" @@ -2653,8 +2654,7 @@ }, "inflight": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "bundled": true, "optional": true, "requires": { "once": "^1.3.0", @@ -2663,20 +2663,17 @@ }, "inherits": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "bundled": true, "optional": true }, "ini": { "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "bundled": true, "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "bundled": true, "optional": true, "requires": { "number-is-nan": "^1.0.0" @@ -2684,14 +2681,12 @@ }, "isarray": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "bundled": true, "optional": true }, "minimatch": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "bundled": true, "optional": true, "requires": { "brace-expansion": "^1.1.7" @@ -2699,14 +2694,12 @@ }, "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "bundled": true, "optional": true }, "minipass": { "version": "2.3.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", - "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", + "bundled": true, "optional": true, "requires": { "safe-buffer": "^5.1.2", @@ -2715,8 +2708,7 @@ }, "minizlib": { "version": "1.2.1", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz", - "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", + "bundled": true, "optional": true, "requires": { "minipass": "^2.2.1" @@ -2724,8 +2716,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "bundled": true, "optional": true, "requires": { "minimist": "0.0.8" @@ -2733,14 +2724,12 @@ }, "ms": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "bundled": true, "optional": true }, "needle": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/needle/-/needle-2.3.0.tgz", - "integrity": "sha512-QBZu7aAFR0522EyaXZM0FZ9GLpq6lvQ3uq8gteiDUp7wKdy0lSd2hPlgFwVuW1CBkfEs9PfDQsQzZghLs/psdg==", + "bundled": true, "optional": true, "requires": { "debug": "^4.1.0", @@ -2750,8 +2739,7 @@ }, "node-pre-gyp": { "version": "0.12.0", - "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz", - "integrity": "sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A==", + "bundled": true, "optional": true, "requires": { "detect-libc": "^1.0.2", @@ -2768,8 +2756,7 @@ }, "nopt": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", - "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "bundled": true, "optional": true, "requires": { "abbrev": "1", @@ -2778,14 +2765,12 @@ }, "npm-bundled": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.6.tgz", - "integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==", + "bundled": true, "optional": true }, "npm-packlist": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.1.tgz", - "integrity": "sha512-+TcdO7HJJ8peiiYhvPxsEDhF3PJFGUGRcFsGve3vxvxdcpO2Z4Z7rkosRM0kWj6LfbK/P0gu3dzk5RU1ffvFcw==", + "bundled": true, "optional": true, "requires": { "ignore-walk": "^3.0.1", @@ -2794,8 +2779,7 @@ }, "npmlog": { "version": "4.1.2", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "bundled": true, "optional": true, "requires": { "are-we-there-yet": "~1.1.2", @@ -2806,20 +2790,17 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "bundled": true, "optional": true }, "object-assign": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "bundled": true, "optional": true }, "once": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "bundled": true, "optional": true, "requires": { "wrappy": "1" @@ -2827,20 +2808,17 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "bundled": true, "optional": true }, "os-tmpdir": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "bundled": true, "optional": true }, "osenv": { "version": "0.1.5", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", - "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "bundled": true, "optional": true, "requires": { "os-homedir": "^1.0.0", @@ -2849,20 +2827,17 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "bundled": true, "optional": true }, "process-nextick-args": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "bundled": true, "optional": true }, "rc": { "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "bundled": true, "optional": true, "requires": { "deep-extend": "^0.6.0", @@ -2873,16 +2848,14 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "bundled": true, "optional": true } } }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "bundled": true, "optional": true, "requires": { "core-util-is": "~1.0.0", @@ -2896,8 +2869,7 @@ }, "rimraf": { "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "bundled": true, "optional": true, "requires": { "glob": "^7.1.3" @@ -2905,44 +2877,37 @@ }, "safe-buffer": { "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "bundled": true, "optional": true }, "safer-buffer": { "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "bundled": true, "optional": true }, "sax": { "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "bundled": true, "optional": true }, "semver": { "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "bundled": true, "optional": true }, "set-blocking": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "bundled": true, "optional": true }, "signal-exit": { "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "bundled": true, "optional": true }, "string-width": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "bundled": true, "optional": true, "requires": { "code-point-at": "^1.0.0", @@ -2952,8 +2917,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "bundled": true, "optional": true, "requires": { "safe-buffer": "~5.1.0" @@ -2961,8 +2925,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "bundled": true, "optional": true, "requires": { "ansi-regex": "^2.0.0" @@ -2970,14 +2933,12 @@ }, "strip-json-comments": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "bundled": true, "optional": true }, "tar": { "version": "4.4.8", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.8.tgz", - "integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==", + "bundled": true, "optional": true, "requires": { "chownr": "^1.1.1", @@ -2991,14 +2952,12 @@ }, "util-deprecate": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "bundled": true, "optional": true }, "wide-align": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "bundled": true, "optional": true, "requires": { "string-width": "^1.0.2 || 2" @@ -3006,14 +2965,12 @@ }, "wrappy": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "bundled": true, "optional": true }, "yallist": { "version": "3.0.3", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", - "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", + "bundled": true, "optional": true } } @@ -3829,9 +3786,9 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "rollup": { - "version": "1.25.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.1.tgz", - "integrity": "sha512-K8ytdEzMa6anHSnfTIs2BLB+NXlQ4qmWwdNHBpYQNWCbZAzj+DRVk7+ssbLSgddwpFW1nThr2GElR+jASF2NPA==", + "version": "1.25.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.2.tgz", + "integrity": "sha512-+7z6Wab/L45QCPcfpuTZKwKiB0tynj05s/+s2U3F2Bi7rOLPr9UcjUwO7/xpjlPNXA/hwnth6jBExFRGyf3tMg==", "requires": { "@types/estree": "*", "@types/node": "*", diff --git a/demo/src/Counter.ts b/demo/src/Counter.ts index 725c2e38..9857dfa4 100644 --- a/demo/src/Counter.ts +++ b/demo/src/Counter.ts @@ -1,6 +1,5 @@ import { vlayout, Image, ViewHolder, VMPanel, ViewModel, Gravity, NativeCall, Text, Color, log, logw, loge, Group, LayoutSpec, } from "doric" - interface CountModel { count: number } diff --git a/iOS/Pod/Classes/DoricContextManager.m b/iOS/Pod/Classes/DoricContextManager.m index 5e0e4de9..a6ddc2cf 100644 --- a/iOS/Pod/Classes/DoricContextManager.m +++ b/iOS/Pod/Classes/DoricContextManager.m @@ -51,7 +51,7 @@ + (instancetype)instance { } - (void)createContext:(DoricContext *)context script:(NSString *)script source:(NSString *)source { - context.contextId = [NSString stringWithFormat:@"%ld", (long) self.counter++]; + context.contextId = [NSString stringWithFormat:@"%ld", (long) ++self.counter]; [context.driver createContext:context.contextId script:script source:source]; dispatch_sync(self.mapQueue, ^() { NSValue *value = [NSValue valueWithNonretainedObject:context]; diff --git a/iOS/Pod/Classes/Engine/DoricJSEngine.m b/iOS/Pod/Classes/Engine/DoricJSEngine.m index 146d6148..d5a9a25e 100644 --- a/iOS/Pod/Classes/Engine/DoricJSEngine.m +++ b/iOS/Pod/Classes/Engine/DoricJSEngine.m @@ -23,6 +23,7 @@ #import "DoricJSEngine.h" #import "DoricJSExecutorProtocal.h" #import "DoricJSCoreExecutor.h" +#import "DoricJSRemoteExecutor.h" #import "DoricConstant.h" #import "DoricUtil.h" #import "DoricBridgeExtension.h" @@ -41,7 +42,9 @@ - (instancetype)init { _bridgeExtension = [[DoricBridgeExtension alloc] init]; dispatch_async(_jsQueue, ^() { self.timers = [[NSMutableDictionary alloc] init]; - self.jsExecutor = [[DoricJSCoreExecutor alloc] init]; + // Debug: 切换 + // self.jsExecutor = [[DoricJSRemoteExecutor alloc] init]; + self.jsExecutor = [DoricJSCoreExecutor new]; self.registry = [[DoricRegistry alloc] init]; [self initJSExecutor]; [self initDoricEnvironment]; diff --git a/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.h b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.h new file mode 100644 index 00000000..b9145867 --- /dev/null +++ b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.h @@ -0,0 +1,35 @@ +/* +* Copyright [2019] [Doric.Pub] +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +// +// DoricJSRemoteExecutor.h +// Pods +// +// Created by 王劲鹏 on 2019/10/31. +// + +#import +#import "DoricJSExecutorProtocal.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface DoricJSRemoteExecutor : NSObject + +@property(nonatomic, strong) dispatch_semaphore_t semaphore; + +- (void)close; +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m new file mode 100644 index 00000000..4875126f --- /dev/null +++ b/iOS/Pod/Classes/Engine/DoricJSRemoteExecutor.m @@ -0,0 +1,193 @@ +/* +* Copyright [2019] [Doric.Pub] +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ +// +// DoricJSRemoteExecutor.m +// Doric +// +// Created by 王劲鹏 on 2019/10/31. +// +#import "DoricJSRemoteExecutor.h" +#import +#import "DoricUtil.h" +#import "DoricJSRemoteArgType.h" +#import "NSString+JsonString.h" + +static NSString * const kUrlStr = @"ws://192.168.24.240:2080"; + +typedef id (^Block0)(void); +typedef id (^Block1)(id arg0); +typedef id (^Block2)(id arg0, id arg1); +typedef id (^Block3)(id arg0, id arg1, id arg2); +typedef id (^Block4)(id arg0, id arg1, id arg2, id arg3); +typedef id (^Block5)(id arg0, id arg1, id arg2, id arg3, id arg4); + +@interface DoricJSRemoteExecutor () +@property(nonatomic, strong) SRWebSocket *srWebSocket; +@property(nonatomic, strong) NSMutableDictionary *blockMDic; +@property(nonatomic, strong) JSValue *temp; +@end + +@implementation DoricJSRemoteExecutor +- (instancetype)init { + if (self = [super init]) { + [self srWebSocket]; + _semaphore = dispatch_semaphore_create(0); + DC_LOCK(self.semaphore); + } + return self; +} + +- (void)webSocketDidOpen:(SRWebSocket *)webSocket { + DoricLog(@"debugger webSocketDidOpen"); + DC_UNLOCK(self.semaphore); +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceivePong:(NSData *)pongPayload { + DoricLog(@"debugger webSocketdidReceivePong"); +} + +- (void)webSocket:(SRWebSocket *)webSocket didReceiveMessage:(id)message { + NSData *jsonData = [message dataUsingEncoding:NSUTF8StringEncoding]; + NSError *err; + NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData + options:NSJSONReadingMutableContainers + error:&err]; + if (err) { + DoricLog(@"debugger webSocketdidReceiveMessage parse error:%@", err); + return; + } + NSString *cmd = [[dic valueForKey:@"cmd"] copy]; + + if ([cmd isEqualToString:@"injectGlobalJSFunction"]) { + NSString *name = [dic valueForKey:@"name"]; + NSArray *argsArr = [dic valueForKey:@"arguments"]; + NSMutableArray *argsMarr = [NSMutableArray new]; + for (NSUInteger i = 0; i < argsArr.count; i++) { + [argsMarr addObject:argsArr[i]]; + } + + id result; + id tmpBlk = self.blockMDic[name]; + if (argsArr.count == 0) { + result = ((Block0) tmpBlk)(); + } else if (argsArr.count == 1) { + result = ((Block1) tmpBlk)(argsArr[0]); + } else if (argsArr.count == 2) { + result = ((Block2)tmpBlk)(argsArr[0], argsArr[1]); + } else if (argsArr.count == 3) { + result = ((Block3)tmpBlk)(argsArr[0], argsArr[1], argsArr[2]); + } else if (argsArr.count == 4) { + result = ((Block4)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3]); + } else if (argsArr.count == 5) { + result = ((Block5)tmpBlk)(argsArr[0], argsArr[1], argsArr[2], argsArr[3], argsArr[4]); + } + + } else if ([cmd isEqualToString:@"invokeMethod"]) { + @try { + self.temp = [JSValue valueWithObject:[dic valueForKey:@"result"] inContext:nil]; + } @catch (NSException *exception) { + DoricLog(@"debugger ", NSStringFromSelector(_cmd), exception.reason); + } @finally { + DC_UNLOCK(self.semaphore); + } + } +} + +- (void)webSocket:(SRWebSocket *)webSocket didFailWithError:(NSError *)error { + DoricLog(@"debugger webSocketdidFailWithError"); + DC_UNLOCK(self.semaphore); +} + +- (void)webSocket:(SRWebSocket *)webSocket didCloseWithCode:(NSInteger)code reason:(NSString *)reason wasClean:(BOOL)wasClean { + DoricLog(@"debugger webSocketdidCloseWithCode"); +} + +- (NSString *)loadJSScript:(NSString *)script source:(NSString *)source { + + return nil; +} + +- (void)injectGlobalJSObject:(NSString *)name obj:(id)obj { + if ([obj isKindOfClass:NSClassFromString(@"NSBlock")]) { + self.blockMDic[name] = obj; + } + NSDictionary *jsonDic = @{ + @"cmd": @"injectGlobalJSFunction", + @"name": name + }; + + NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic]; + if (!jsonStr) { + return; + } + + [self.srWebSocket send:jsonStr]; +} + +- (JSValue *)invokeObject:(NSString *)objName method:(NSString *)funcName args:(NSArray *)args { + + NSMutableArray *argsMArr = [NSMutableArray new]; + for (id arg in args) { + NSDictionary *dic = @{ + @"type": @(DoricargTypeWithArg(arg)), + @"value": arg + }; + [argsMArr addObject:dic]; + } + + NSArray *argsArr = [argsMArr copy]; + + NSDictionary *jsonDic = @{ + @"cmd": @"invokeMethod", + @"objectName": objName, + @"functionName": funcName, + @"javaValues": argsArr + }; + + NSString *jsonStr = [NSString dc_convertToJsonWithDic:jsonDic]; + if (!jsonStr) { + return nil; + } + + [self.srWebSocket send:jsonStr]; + DC_LOCK(self.semaphore); + + return self.temp; +} + +- (void)close { + [self.srWebSocket close]; +} + +#pragma mark - Properties +- (SRWebSocket *)srWebSocket { + if (!_srWebSocket) { + NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:kUrlStr] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:10]; + _srWebSocket = [[SRWebSocket alloc] initWithURLRequest:request]; + _srWebSocket.delegate = self; + [_srWebSocket open]; + } + return _srWebSocket; +} + +- (NSMutableDictionary *)blockMDic { + if (!_blockMDic) { + _blockMDic = [NSMutableDictionary new]; + } + return _blockMDic; +} + +@end diff --git a/iOS/Pod/Classes/Util/Category/NSString+JsonString.h b/iOS/Pod/Classes/Util/Category/NSString+JsonString.h new file mode 100644 index 00000000..9581e9a3 --- /dev/null +++ b/iOS/Pod/Classes/Util/Category/NSString+JsonString.h @@ -0,0 +1,18 @@ +// +// NSString+JsonString.h +// Doric +// +// Created by Insomnia on 2019/11/7. +// + + + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface NSString (JsonString) ++ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic; +@end + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Util/Category/NSString+JsonString.m b/iOS/Pod/Classes/Util/Category/NSString+JsonString.m new file mode 100644 index 00000000..bcdd6437 --- /dev/null +++ b/iOS/Pod/Classes/Util/Category/NSString+JsonString.m @@ -0,0 +1,23 @@ +// +// NSString+JsonString.m +// Doric +// +// Created by Insomnia on 2019/11/7. +// + +#import "NSString+JsonString.h" +#import "DoricUtil.h" + +@implementation NSString (JsonString) ++ (NSString *)dc_convertToJsonWithDic:(NSDictionary *)dic { + NSError *err; + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&err]; + NSString *jsonStr = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; + + if (err) { + DoricLog(NSStringFromSelector(_cmd), @"Convert dictionary to json string failed."); + return nil; + } + return jsonStr; +} +@end diff --git a/iOS/Pod/Classes/Util/DoricJSRemoteArgType.h b/iOS/Pod/Classes/Util/DoricJSRemoteArgType.h new file mode 100644 index 00000000..f18ea41d --- /dev/null +++ b/iOS/Pod/Classes/Util/DoricJSRemoteArgType.h @@ -0,0 +1,23 @@ +// +// DoricJSRemoteArgType.h +// Doric +// +// Created by Insomnia on 2019/11/7. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +typedef NS_ENUM(NSUInteger, DoricJSRemoteArgType) { + DoricJSRemoteArgTypeNil = 0, + DoricJSRemoteArgTypeInteger, + DoricJSRemoteArgTypeBool, + DoricJSRemoteArgTypeString, + DoricJSRemoteArgTypeObject, + DoricJSRemoteArgTypeArray, +}; + +DoricJSRemoteArgType DoricargTypeWithArg(id arg); + +NS_ASSUME_NONNULL_END diff --git a/iOS/Pod/Classes/Util/DoricJSRemoteArgType.m b/iOS/Pod/Classes/Util/DoricJSRemoteArgType.m new file mode 100644 index 00000000..1b018109 --- /dev/null +++ b/iOS/Pod/Classes/Util/DoricJSRemoteArgType.m @@ -0,0 +1,12 @@ +// +// DoricJSRemoteArgType.m +// Doric +// +// Created by Insomnia on 2019/11/7. +// + +#import "DoricJSRemoteArgType.h" +DoricJSRemoteArgType DoricargTypeWithArg(id arg) { + // TODO: 类型缺失 + return DoricJSRemoteArgTypeString; +} diff --git a/iOS/Pod/Classes/Util/DoricUtil.h b/iOS/Pod/Classes/Util/DoricUtil.h index dba4e355..ae606cc9 100644 --- a/iOS/Pod/Classes/Util/DoricUtil.h +++ b/iOS/Pod/Classes/Util/DoricUtil.h @@ -27,3 +27,11 @@ void DoricLog(NSString *_Nonnull format, ...); UIColor *_Nonnull DoricColor(NSNumber *_Nonnull number); NSBundle *DoricBundle(); + +#ifndef DC_LOCK +#define DC_LOCK(lock) dispatch_semaphore_wait(lock, DISPATCH_TIME_FOREVER); +#endif + +#ifndef DC_UNLOCK +#define DC_UNLOCK(lock) dispatch_semaphore_signal(lock); +#endif diff --git a/js-framework/index.debug.ts b/js-framework/index.debug.ts new file mode 100644 index 00000000..9d9c2f20 --- /dev/null +++ b/js-framework/index.debug.ts @@ -0,0 +1,95 @@ +/* + * Copyright [2019] [Doric.Pub] + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import * as doric from './src/runtime/sandbox' +import * as WebSocket from 'ws' + +let global = new Function('return this')() +global.doric = doric +const contextId = "1" +global.context = doric.jsObtainContext(contextId) +global.Entry = doric.jsObtainEntry(contextId) + +const wss = new WebSocket.Server({ port: 2080 }) +wss.on('connection', function connection(ws) { + console.log('Connected') + ws.on('message', function incoming(message: string) { + let messageObject = JSON.parse(message) + switch (messageObject.cmd) { + case "injectGlobalJSFunction": + console.log(messageObject.name) + Reflect.set(global, messageObject.name, function () { + let args = [].slice.call(arguments) + console.log("===============================") + console.log(args) + console.log("===============================") + ws.send(JSON.stringify({ + cmd: 'injectGlobalJSFunction', + name: messageObject.name, + arguments: args + })) + }) + break + case "invokeMethod": + console.log(messageObject.objectName) + console.log(messageObject.functionName) + + let args = [] + for (let i = 0; i < messageObject.javaValues.length; i++) { + let javaValue = messageObject.javaValues[i] + if (javaValue.type === 0) { + args.push(null) + } else if (javaValue.type === 1) { + args.push(parseFloat(javaValue.value)) + } else if (javaValue.type === 2) { + args.push((javaValue.value == 'true')) + } else if (javaValue.type === 3) { + args.push(javaValue.value.toString()) + } else if (javaValue.type === 4) { + args.push(JSON.parse(javaValue.value)) + } else if (javaValue.type === 5) { + args.push(JSON.parse(javaValue.value)) + } + } + console.log(args) + console.log(messageObject.hashKey) + + let object = Reflect.get(global, messageObject.objectName) + let method = Reflect.get(object, messageObject.functionName) + let result = Reflect.apply(method, undefined, args) + + console.log(result) + ws.send(JSON.stringify({ + cmd: 'invokeMethod', + result: result + })) + break + } + }) +}) +console.log('Start Server') + +global.injectGlobal = (objName: string, obj: string) => { + Reflect.set(global, objName, JSON.parse(obj)) +} + +global.sendToNative = () => { + +} +global.receiveFromNative = () => { + +} + +export * from './index' \ No newline at end of file diff --git a/js-framework/package-lock.json b/js-framework/package-lock.json index 3a411d17..4a177594 100644 --- a/js-framework/package-lock.json +++ b/js-framework/package-lock.json @@ -10,9 +10,9 @@ "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==" }, "@types/node": { - "version": "12.11.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.1.tgz", - "integrity": "sha512-TJtwsqZ39pqcljJpajeoofYRfeZ7/I/OMUQ5pR4q5wOKf2ocrUvBAZUMhWsOvKx3dVc/aaV5GluBivt0sWqA5A==" + "version": "12.11.5", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.11.5.tgz", + "integrity": "sha512-LC8ALj/24PhByn39nr5jnTvpE7MujK8y7LQmV74kHYF5iQ0odCPkMH4IZNZw+cobKfSXqaC8GgegcbIsQpffdA==" }, "@types/resolve": { "version": "0.0.8", @@ -22,6 +22,14 @@ "@types/node": "*" } }, + "@types/ws": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/@types/ws/-/ws-6.0.3.tgz", + "integrity": "sha512-yBTM0P05Tx9iXGq00BbJPo37ox68R5vaGTXivs6RGh/BQ6QP5zqZDGWdAO6JbRE/iR1l80xeGAwCQS2nMV9S/w==", + "requires": { + "@types/node": "*" + } + }, "acorn": { "version": "7.1.0", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.0.tgz", @@ -69,6 +77,11 @@ "resolved": "https://registry.npmjs.org/async-each/-/async-each-1.0.3.tgz", "integrity": "sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==" }, + "async-limiter": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", + "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" + }, "atob": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/atob/-/atob-2.1.2.tgz", @@ -401,26 +414,22 @@ "dependencies": { "abbrev": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", - "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", + "bundled": true, "optional": true }, "ansi-regex": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", - "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "bundled": true, "optional": true }, "aproba": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-1.2.0.tgz", - "integrity": "sha512-Y9J6ZjXtoYh8RnXVCMOU/ttDmk1aBjunq9vO0ta5x85WDQiQfUF9sIPBITdbiiIVcBo03Hi3jMxigBtsddlXRw==", + "bundled": true, "optional": true }, "are-we-there-yet": { "version": "1.1.5", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-1.1.5.tgz", - "integrity": "sha512-5hYdAkZlcG8tOLujVDTgCT+uPX0VnpAH28gWsLfzpXYm7wP6mp5Q/gYyR7YQ0cKVJcXJnl3j2kpBan13PtQf6w==", + "bundled": true, "optional": true, "requires": { "delegates": "^1.0.0", @@ -429,14 +438,12 @@ }, "balanced-match": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", + "bundled": true, "optional": true }, "brace-expansion": { "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "bundled": true, "optional": true, "requires": { "balanced-match": "^1.0.0", @@ -445,38 +452,32 @@ }, "chownr": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/chownr/-/chownr-1.1.1.tgz", - "integrity": "sha512-j38EvO5+LHX84jlo6h4UzmOwi0UgW61WRyPtJz4qaadK5eY3BTS5TY/S1Stc3Uk2lIM6TPevAlULiEJwie860g==", + "bundled": true, "optional": true }, "code-point-at": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/code-point-at/-/code-point-at-1.1.0.tgz", - "integrity": "sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c=", + "bundled": true, "optional": true }, "concat-map": { "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", + "bundled": true, "optional": true }, "console-control-strings": { "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha1-PXz0Rk22RG6mRL9LOVB/mFEAjo4=", + "bundled": true, "optional": true }, "core-util-is": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", - "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=", + "bundled": true, "optional": true }, "debug": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", - "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", + "bundled": true, "optional": true, "requires": { "ms": "^2.1.1" @@ -484,26 +485,22 @@ }, "deep-extend": { "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "bundled": true, "optional": true }, "delegates": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", - "integrity": "sha1-hMbhWbgZBP3KWaDvRM2HDTElD5o=", + "bundled": true, "optional": true }, "detect-libc": { "version": "1.0.3", - "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-1.0.3.tgz", - "integrity": "sha1-+hN8S9aY7fVc1c0CrFWfkaTEups=", + "bundled": true, "optional": true }, "fs-minipass": { "version": "1.2.5", - "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-1.2.5.tgz", - "integrity": "sha512-JhBl0skXjUPCFH7x6x61gQxrKyXsxB5gcgePLZCwfyCGGsTISMoIeObbrvVeP6Xmyaudw4TT43qV2Gz+iyd2oQ==", + "bundled": true, "optional": true, "requires": { "minipass": "^2.2.1" @@ -511,14 +508,12 @@ }, "fs.realpath": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", + "bundled": true, "optional": true }, "gauge": { "version": "2.7.4", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-2.7.4.tgz", - "integrity": "sha1-LANAXHU4w51+s3sxcCLjJfsBi/c=", + "bundled": true, "optional": true, "requires": { "aproba": "^1.0.3", @@ -533,8 +528,7 @@ }, "glob": { "version": "7.1.3", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.3.tgz", - "integrity": "sha512-vcfuiIxogLV4DlGBHIUOwI0IbrJ8HWPc4MU7HzviGeNho/UJDfi6B5p3sHeWIQ0KGIU0Jpxi5ZHxemQfLkkAwQ==", + "bundled": true, "optional": true, "requires": { "fs.realpath": "^1.0.0", @@ -547,14 +541,12 @@ }, "has-unicode": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha1-4Ob+aijPUROIVeCG0Wkedx3iqLk=", + "bundled": true, "optional": true }, "iconv-lite": { "version": "0.4.24", - "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz", - "integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==", + "bundled": true, "optional": true, "requires": { "safer-buffer": ">= 2.1.2 < 3" @@ -562,8 +554,7 @@ }, "ignore-walk": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/ignore-walk/-/ignore-walk-3.0.1.tgz", - "integrity": "sha512-DTVlMx3IYPe0/JJcYP7Gxg7ttZZu3IInhuEhbchuqneY9wWe5Ojy2mXLBaQFUQmo0AW2r3qG7m1mg86js+gnlQ==", + "bundled": true, "optional": true, "requires": { "minimatch": "^3.0.4" @@ -571,8 +562,7 @@ }, "inflight": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "bundled": true, "optional": true, "requires": { "once": "^1.3.0", @@ -581,20 +571,17 @@ }, "inherits": { "version": "2.0.3", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", - "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=", + "bundled": true, "optional": true }, "ini": { "version": "1.3.5", - "resolved": "https://registry.npmjs.org/ini/-/ini-1.3.5.tgz", - "integrity": "sha512-RZY5huIKCMRWDUqZlEi72f/lmXKMvuszcMBduliQ3nnWbx9X/ZBQO7DijMEYS9EhHBb2qacRUMtC7svLwe0lcw==", + "bundled": true, "optional": true }, "is-fullwidth-code-point": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz", - "integrity": "sha1-754xOG8DGn8NZDr4L95QxFfvAMs=", + "bundled": true, "optional": true, "requires": { "number-is-nan": "^1.0.0" @@ -602,14 +589,12 @@ }, "isarray": { "version": "1.0.0", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", - "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", + "bundled": true, "optional": true }, "minimatch": { "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "bundled": true, "optional": true, "requires": { "brace-expansion": "^1.1.7" @@ -617,14 +602,12 @@ }, "minimist": { "version": "0.0.8", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", - "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=", + "bundled": true, "optional": true }, "minipass": { "version": "2.3.5", - "resolved": "https://registry.npmjs.org/minipass/-/minipass-2.3.5.tgz", - "integrity": "sha512-Gi1W4k059gyRbyVUZQ4mEqLm0YIUiGYfvxhF6SIlk3ui1WVxMTGfGdQ2SInh3PDrRTVvPKgULkpJtT4RH10+VA==", + "bundled": true, "optional": true, "requires": { "safe-buffer": "^5.1.2", @@ -633,8 +616,7 @@ }, "minizlib": { "version": "1.2.1", - "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-1.2.1.tgz", - "integrity": "sha512-7+4oTUOWKg7AuL3vloEWekXY2/D20cevzsrNT2kGWm+39J9hGTCBv8VI5Pm5lXZ/o3/mdR4f8rflAPhnQb8mPA==", + "bundled": true, "optional": true, "requires": { "minipass": "^2.2.1" @@ -642,8 +624,7 @@ }, "mkdirp": { "version": "0.5.1", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", - "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "bundled": true, "optional": true, "requires": { "minimist": "0.0.8" @@ -651,14 +632,12 @@ }, "ms": { "version": "2.1.1", - "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.1.tgz", - "integrity": "sha512-tgp+dl5cGk28utYktBsrFqA7HKgrhgPsg6Z/EfhWI4gl1Hwq8B/GmY/0oXZ6nF8hDVesS/FpnYaD/kOWhYQvyg==", + "bundled": true, "optional": true }, "needle": { "version": "2.3.0", - "resolved": "https://registry.npmjs.org/needle/-/needle-2.3.0.tgz", - "integrity": "sha512-QBZu7aAFR0522EyaXZM0FZ9GLpq6lvQ3uq8gteiDUp7wKdy0lSd2hPlgFwVuW1CBkfEs9PfDQsQzZghLs/psdg==", + "bundled": true, "optional": true, "requires": { "debug": "^4.1.0", @@ -668,8 +647,7 @@ }, "node-pre-gyp": { "version": "0.12.0", - "resolved": "https://registry.npmjs.org/node-pre-gyp/-/node-pre-gyp-0.12.0.tgz", - "integrity": "sha512-4KghwV8vH5k+g2ylT+sLTjy5wmUOb9vPhnM8NHvRf9dHmnW/CndrFXy2aRPaPST6dugXSdHXfeaHQm77PIz/1A==", + "bundled": true, "optional": true, "requires": { "detect-libc": "^1.0.2", @@ -686,8 +664,7 @@ }, "nopt": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/nopt/-/nopt-4.0.1.tgz", - "integrity": "sha1-0NRoWv1UFRk8jHUFYC0NF81kR00=", + "bundled": true, "optional": true, "requires": { "abbrev": "1", @@ -696,14 +673,12 @@ }, "npm-bundled": { "version": "1.0.6", - "resolved": "https://registry.npmjs.org/npm-bundled/-/npm-bundled-1.0.6.tgz", - "integrity": "sha512-8/JCaftHwbd//k6y2rEWp6k1wxVfpFzB6t1p825+cUb7Ym2XQfhwIC5KwhrvzZRJu+LtDE585zVaS32+CGtf0g==", + "bundled": true, "optional": true }, "npm-packlist": { "version": "1.4.1", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-1.4.1.tgz", - "integrity": "sha512-+TcdO7HJJ8peiiYhvPxsEDhF3PJFGUGRcFsGve3vxvxdcpO2Z4Z7rkosRM0kWj6LfbK/P0gu3dzk5RU1ffvFcw==", + "bundled": true, "optional": true, "requires": { "ignore-walk": "^3.0.1", @@ -712,8 +687,7 @@ }, "npmlog": { "version": "4.1.2", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz", - "integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==", + "bundled": true, "optional": true, "requires": { "are-we-there-yet": "~1.1.2", @@ -724,20 +698,17 @@ }, "number-is-nan": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz", - "integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0=", + "bundled": true, "optional": true }, "object-assign": { "version": "4.1.1", - "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", - "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=", + "bundled": true, "optional": true }, "once": { "version": "1.4.0", - "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", - "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "bundled": true, "optional": true, "requires": { "wrappy": "1" @@ -745,20 +716,17 @@ }, "os-homedir": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-homedir/-/os-homedir-1.0.2.tgz", - "integrity": "sha1-/7xJiDNuDoM94MFox+8VISGqf7M=", + "bundled": true, "optional": true }, "os-tmpdir": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/os-tmpdir/-/os-tmpdir-1.0.2.tgz", - "integrity": "sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ=", + "bundled": true, "optional": true }, "osenv": { "version": "0.1.5", - "resolved": "https://registry.npmjs.org/osenv/-/osenv-0.1.5.tgz", - "integrity": "sha512-0CWcCECdMVc2Rw3U5w9ZjqX6ga6ubk1xDVKxtBQPK7wis/0F2r9T6k4ydGYhecl7YUBxBVxhL5oisPsNxAPe2g==", + "bundled": true, "optional": true, "requires": { "os-homedir": "^1.0.0", @@ -767,20 +735,17 @@ }, "path-is-absolute": { "version": "1.0.1", - "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "bundled": true, "optional": true }, "process-nextick-args": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.0.tgz", - "integrity": "sha512-MtEC1TqN0EU5nephaJ4rAtThHtC86dNN9qCuEhtshvpVBkAW5ZO7BASN9REnF9eoXGcRub+pFuKEpOHE+HbEMw==", + "bundled": true, "optional": true }, "rc": { "version": "1.2.8", - "resolved": "https://registry.npmjs.org/rc/-/rc-1.2.8.tgz", - "integrity": "sha512-y3bGgqKj3QBdxLbLkomlohkvsA8gdAiUQlSBJnBhfn+BPxg4bc62d8TcBW15wavDfgexCgccckhcZvywyQYPOw==", + "bundled": true, "optional": true, "requires": { "deep-extend": "^0.6.0", @@ -791,16 +756,14 @@ "dependencies": { "minimist": { "version": "1.2.0", - "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", - "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", + "bundled": true, "optional": true } } }, "readable-stream": { "version": "2.3.6", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.6.tgz", - "integrity": "sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw==", + "bundled": true, "optional": true, "requires": { "core-util-is": "~1.0.0", @@ -814,8 +777,7 @@ }, "rimraf": { "version": "2.6.3", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.3.tgz", - "integrity": "sha512-mwqeW5XsA2qAejG46gYdENaxXjx9onRNCfn7L0duuP4hCuTIi/QO7PDK07KJfp1d+izWPrzEJDcSqBa0OZQriA==", + "bundled": true, "optional": true, "requires": { "glob": "^7.1.3" @@ -823,44 +785,37 @@ }, "safe-buffer": { "version": "5.1.2", - "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", - "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==", + "bundled": true, "optional": true }, "safer-buffer": { "version": "2.1.2", - "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", - "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "bundled": true, "optional": true }, "sax": { "version": "1.2.4", - "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", - "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "bundled": true, "optional": true }, "semver": { "version": "5.7.0", - "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.0.tgz", - "integrity": "sha512-Ya52jSX2u7QKghxeoFGpLwCtGlt7j0oY9DYb5apt9nPlJ42ID+ulTXESnt/qAQcoSERyZ5sl3LDIOw0nAn/5DA==", + "bundled": true, "optional": true }, "set-blocking": { "version": "2.0.0", - "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", - "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=", + "bundled": true, "optional": true }, "signal-exit": { "version": "3.0.2", - "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.2.tgz", - "integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=", + "bundled": true, "optional": true }, "string-width": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/string-width/-/string-width-1.0.2.tgz", - "integrity": "sha1-EYvfW4zcUaKn5w0hHgfisLmxB9M=", + "bundled": true, "optional": true, "requires": { "code-point-at": "^1.0.0", @@ -870,8 +825,7 @@ }, "string_decoder": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", - "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", + "bundled": true, "optional": true, "requires": { "safe-buffer": "~5.1.0" @@ -879,8 +833,7 @@ }, "strip-ansi": { "version": "3.0.1", - "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", - "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "bundled": true, "optional": true, "requires": { "ansi-regex": "^2.0.0" @@ -888,14 +841,12 @@ }, "strip-json-comments": { "version": "2.0.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-2.0.1.tgz", - "integrity": "sha1-PFMZQukIwml8DsNEhYwobHygpgo=", + "bundled": true, "optional": true }, "tar": { "version": "4.4.8", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.8.tgz", - "integrity": "sha512-LzHF64s5chPQQS0IYBn9IN5h3i98c12bo4NCO7e0sGM2llXQ3p2FGC5sdENN4cTW48O915Sh+x+EXx7XW96xYQ==", + "bundled": true, "optional": true, "requires": { "chownr": "^1.1.1", @@ -909,14 +860,12 @@ }, "util-deprecate": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=", + "bundled": true, "optional": true }, "wide-align": { "version": "1.1.3", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.3.tgz", - "integrity": "sha512-QGkOQc8XL6Bt5PwnsExKBPuMKBxnGxWWW3fU55Xt4feHozMUhdUMaBCk290qpm/wG5u/RSKzwdAC4i51YigihA==", + "bundled": true, "optional": true, "requires": { "string-width": "^1.0.2 || 2" @@ -924,14 +873,12 @@ }, "wrappy": { "version": "1.0.2", - "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", + "bundled": true, "optional": true }, "yallist": { "version": "3.0.3", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-3.0.3.tgz", - "integrity": "sha512-S+Zk8DEWE6oKpV+vI3qWkaK+jSbIK86pCwe2IF/xwIpQ8jEuxpw9NyaGjmp9+BoJv5FV2piqCDcoCtStppiq2A==", + "bundled": true, "optional": true } } @@ -1731,9 +1678,9 @@ "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "rollup": { - "version": "1.25.1", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.1.tgz", - "integrity": "sha512-K8ytdEzMa6anHSnfTIs2BLB+NXlQ4qmWwdNHBpYQNWCbZAzj+DRVk7+ssbLSgddwpFW1nThr2GElR+jASF2NPA==", + "version": "1.25.2", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.25.2.tgz", + "integrity": "sha512-+7z6Wab/L45QCPcfpuTZKwKiB0tynj05s/+s2U3F2Bi7rOLPr9UcjUwO7/xpjlPNXA/hwnth6jBExFRGyf3tMg==", "requires": { "@types/estree": "*", "@types/node": "*", @@ -2072,6 +2019,14 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "ws": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", + "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", + "requires": { + "async-limiter": "^1.0.0" + } } } } diff --git a/js-framework/package.json b/js-framework/package.json index 3e32bdd0..0ae78ff9 100644 --- a/js-framework/package.json +++ b/js-framework/package.json @@ -2,7 +2,7 @@ "name": "doric", "version": "0.1.0", "description": "The JS Framework of Doric", - "main": "build/index.js", + "main": "bundle/doric-vm.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "tsc -p .&& rollup -c", @@ -20,11 +20,13 @@ }, "homepage": "https://github.com/doric-pub/doric#readme", "dependencies": { + "@types/ws": "^6.0.3", "reflect-metadata": "^0.1.13", "rollup": "^1.17.0", "rollup-plugin-node-resolve": "^5.2.0", "rollup-watch": "^4.3.1", "tslib": "^1.10.0", - "typescript": "^3.5.3" + "typescript": "^3.5.3", + "ws": "^7.2.0" } } diff --git a/js-framework/rollup.config.js b/js-framework/rollup.config.js index 519ab4db..03957294 100644 --- a/js-framework/rollup.config.js +++ b/js-framework/rollup.config.js @@ -25,4 +25,15 @@ export default [ ], external: ['reflect-metadata'] }, + { + input: "build/index.debug.js", + output: { + format: "cjs", + file: "bundle/doric-vm.js", + }, + plugins: [ + resolve({ jsnext: true, main: true }), + ], + external: ['ws'] + }, ] \ No newline at end of file diff --git a/js-framework/src/runtime/sandbox.ts b/js-framework/src/runtime/sandbox.ts index 8db4c38a..4e2c74d9 100644 --- a/js-framework/src/runtime/sandbox.ts +++ b/js-framework/src/runtime/sandbox.ts @@ -21,17 +21,17 @@ import "reflect-metadata" * ``` TypeScript * // load script in global scope * Reflect.apply( - * function(hego,context,Entry,require){ + * function(doric,context,Entry,require){ * //Script content * REG() - * },hego.jsObtainContext(id),[ + * },doric.jsObtainContext(id),[ * undefined, - * hego.jsObtainContext(id), - * hego.jsObtainEntry(id), - * hego.__require__, + * doric.jsObtainContext(id), + * doric.jsObtainEntry(id), + * doric.__require__, * ]) * // load module in global scope - * Reflect.apply(hego.jsRegisterModule,this,[ + * Reflect.apply(doric.jsRegisterModule,this,[ * moduleName, * Reflect.apply(function(__module){ * (function(module,exports,require){ @@ -255,8 +255,18 @@ let __timerId__ = 0 const timerInfos: Map void, context?: Context }> = new Map +const _setTimeout = global.setTimeout -global.setTimeout = (handler: Function, timeout?: number | undefined, ...args: any[]) => { +const _setInterval = global.setInterval + +const _clearTimeout = global.clearTimeout + +const _clearInterval = global.clearInterval + +global.setTimeout = function (handler: Function, timeout?: number | undefined, ...args: any[]) { + if (global.nativeSetTimer === undefined) { + return Reflect.apply(_setTimeout, undefined, arguments) + } const id = __timerId__++ timerInfos.set(id, { callback: () => { @@ -268,7 +278,10 @@ global.setTimeout = (handler: Function, timeout?: number | undefined, ...args: a nativeSetTimer(id, timeout || 0, false) return id } -global.setInterval = (handler: Function, timeout?: number | undefined, ...args: any[]) => { +global.setInterval = function (handler: Function, timeout?: number | undefined, ...args: any[]) { + if (global.nativeSetTimer === undefined) { + return Reflect.apply(_setInterval, undefined, arguments) + } const id = __timerId__++ timerInfos.set(id, { callback: () => { @@ -280,12 +293,18 @@ global.setInterval = (handler: Function, timeout?: number | undefined, ...args: return id } -global.clearTimeout = (timerId: number) => { +global.clearTimeout = function (timerId: number) { + if (global.nativeClearTimer === undefined) { + return Reflect.apply(_clearTimeout, undefined, arguments) + } timerInfos.delete(timerId) nativeClearTimer(timerId) } -global.clearInterval = (timerId: number) => { +global.clearInterval = function (timerId: number) { + if (global.nativeClearTimer === undefined) { + return Reflect.apply(_clearInterval, undefined, arguments) + } timerInfos.delete(timerId) nativeClearTimer(timerId) } diff --git a/remote/.gitignore b/remote/.gitignore deleted file mode 100644 index 40b878db..00000000 --- a/remote/.gitignore +++ /dev/null @@ -1 +0,0 @@ -node_modules/ \ No newline at end of file diff --git a/remote/index.js b/remote/index.js deleted file mode 100644 index 78d2ee68..00000000 --- a/remote/index.js +++ /dev/null @@ -1,20 +0,0 @@ -const WebSocket = require('ws') -const vm = require("vm") - -const wss = new WebSocket.Server({ port: 2080 }) -var sandbox = {} -var context = vm.createContext(sandbox) - -wss.on('connection', function connection(ws) { - ws.on('message', function incoming(message) { - let messageObject = JSON.parse(message) - switch(messageObject.cmd) { - case "loadJS": - let result = vm.runInContext(messageObject.script, sandbox) - ws.send(JSON.stringify({cmd: 'loadJS', result: String(result)})) - break - case "evaluateJS": - break - } - }) -}) \ No newline at end of file diff --git a/remote/package-lock.json b/remote/package-lock.json deleted file mode 100644 index a0da7af1..00000000 --- a/remote/package-lock.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "remote", - "version": "0.1.0", - "lockfileVersion": 1, - "requires": true, - "dependencies": { - "async-limiter": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/async-limiter/-/async-limiter-1.0.1.tgz", - "integrity": "sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==" - }, - "ws": { - "version": "7.2.0", - "resolved": "https://registry.npmjs.org/ws/-/ws-7.2.0.tgz", - "integrity": "sha512-+SqNqFbwTm/0DC18KYzIsMTnEWpLwJsiasW/O17la4iDRRIO9uaHbvKiAS3AHgTiuuWerK/brj4O6MYZkei9xg==", - "requires": { - "async-limiter": "^1.0.0" - } - } - } -} diff --git a/remote/package.json b/remote/package.json deleted file mode 100644 index be9c1efa..00000000 --- a/remote/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "remote", - "version": "0.1.0", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "dependencies": { - "ws": "^7.2.0" - } -} diff --git a/setup.sh b/setup.sh index ae733f0b..3f06bc21 100755 --- a/setup.sh +++ b/setup.sh @@ -8,4 +8,4 @@ cd js-framework && npm install && npm run build && cd .. cd debugger && npm install && npm run build && cd .. cd demo && npm install && npm run build && cd .. -cd doric-cli && npm install && cd .. +cd doric-cli && npm install && npm link && cd ..