mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-08 04:15:25 +00:00
socket 调试
This commit is contained in:
56
electron-app/index.js
Normal file
56
electron-app/index.js
Normal file
@@ -0,0 +1,56 @@
|
||||
const WS = require("ws");
|
||||
let Server = null;
|
||||
new Vue({
|
||||
el: "#app",
|
||||
data: {
|
||||
status: "---",
|
||||
recvMsg: "",
|
||||
recvMsgError: false,
|
||||
sendCode: "console.log('hello')",
|
||||
webSocketInstance: null,
|
||||
},
|
||||
created() {
|
||||
Server = new WS.Server({port: 1109});
|
||||
Server.on("connection", (webSocket) => {
|
||||
this.status = "link";
|
||||
this.webSocketInstance = webSocket;
|
||||
webSocket.on("message", (msg) => {
|
||||
const {error, data} = JSON.parse(msg);
|
||||
this.recvMsgError = !!error;
|
||||
if (data) {
|
||||
this.recvMsg = data;
|
||||
} else {
|
||||
this.recvMsg = null;
|
||||
}
|
||||
});
|
||||
webSocket.on("close", () => {
|
||||
console.log("close");
|
||||
this.status = "close";
|
||||
this.webSocketInstance = null;
|
||||
});
|
||||
webSocket.on("open", () => {
|
||||
console.log("open");
|
||||
this.status = "open";
|
||||
});
|
||||
webSocket.on("error", () => {
|
||||
console.log("error");
|
||||
this.status = "error";
|
||||
this.webSocketInstance = null;
|
||||
});
|
||||
});
|
||||
},
|
||||
mounted() {
|
||||
|
||||
},
|
||||
methods: {
|
||||
onRunCmd() {
|
||||
if (this.webSocketInstance) {
|
||||
let str = {
|
||||
code: this.sendCode,
|
||||
};
|
||||
this.webSocketInstance.send(JSON.stringify(str));
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user