This commit is contained in:
Peli de Halleux 2021-11-19 23:33:43 +00:00 коммит произвёл GitHub
Родитель 8a6ad3ee03
Коммит 6c6f43aa82
4 изменённых файлов: 29 добавлений и 10 удалений

Просмотреть файл

@ -38,7 +38,9 @@ jacdac parse log.txt
### `jacdac devtools`
Starts a local websocket server that acts as a bridge between a web dashboard and a client implementation. This allows to test a native client using the latest version of the web developer tools.
Starts a websocket server that acts as a bridge between a web dashboard and a client implementation.
This allows to test a native client using the latest version of the web developer tools.
This command will work in [GitHub codespaces](https://github.com/features/codespaces).
```
jacdac devtools

Просмотреть файл

@ -2,14 +2,21 @@
var frame = document.getElementById("frame");
var sender = Math.random() + "";
frame.src = "https://microsoft.github.io/jacdac-docs/dashboard/#" + sender;
var location = window.location;
var secure = location.protocol === "https:";
var protocol = secure ? "wss:" : "ws:";
var hostname = location.hostname;
var port = secure ? 443 : 8081;
var wsurl = protocol + "//" + hostname + ":" + port + "/";
// node.js -> iframe dashboard
var ws = new WebSocket("ws://localhost:8081/");
var ws = new WebSocket(wsurl);
ws.binaryType = "arraybuffer";
console.debug("devtools: connecting to local server...");
console.debug("devtools: connecting " + wsurl + "...");
ws.addEventListener("open", function () {
console.debug("devtools: connected to local server");
console.debug("devtools: connected " + ws.url);
});
ws.addEventListener("message", function (msg) {
console.debug("msg", msg.data);
var data = new Uint8Array(msg.data);
var pktMsg = {
type: "messagepacket",
@ -22,6 +29,9 @@
ws.addEventListener("close", function () {
console.debug("devtools: connection closed");
});
ws.addEventListener("error", function (e) {
console.error("devtools: error " + (e + ""), e);
});
// iframe dashboard -> node.js
window.addEventListener("message", function (msg) {
var data = msg.data;

Просмотреть файл

@ -3,14 +3,21 @@
const sender = Math.random() + ""
frame.src = "https://microsoft.github.io/jacdac-docs/dashboard/#" + sender
const location = window.location
const secure = location.protocol === "https:"
const protocol = secure ? "wss:" : "ws:"
const hostname = location.hostname
const port = secure ? 443 : 8081
const wsurl = `${protocol}//${hostname}:${port}/`
// node.js -> iframe dashboard
const ws = new WebSocket("ws://localhost:8081/")
const ws = new WebSocket(wsurl)
ws.binaryType = "arraybuffer"
console.debug(`devtools: connecting to local server...`)
console.debug(`devtools: connecting ${wsurl}...`)
ws.addEventListener("open", () => {
console.debug(`devtools: connected to local server`)
console.debug(`devtools: connected ${ws.url}`)
})
ws.addEventListener("message", (msg) => {
console.debug(`msg`, msg.data)
const data = new Uint8Array(msg.data)
const pktMsg = {
type: "messagepacket",
@ -23,6 +30,9 @@
ws.addEventListener("close", () => {
console.debug(`devtools: connection closed`)
})
ws.addEventListener("error", (e: Event) => {
console.error(`devtools: error ${e + ""}`, e)
})
// iframe dashboard -> node.js
window.addEventListener("message", msg => {
const data = msg.data

Просмотреть файл

@ -54,9 +54,6 @@ export async function devToolsCommand(options?: { packets?: boolean }) {
return
}
// if is a directory search for index file matching the extension
//if (fs.statSync(fname).isDirectory()) fname += "index" + ext
// read file from file system
fs.readFile(fname, (err, data) => {
if (err) {