debug needed
This commit is contained in:
27
web/src/App.vue
Normal file
27
web/src/App.vue
Normal file
@@ -0,0 +1,27 @@
|
||||
<template>
|
||||
<n-message-provider placement="top-right">
|
||||
<main-app />
|
||||
</n-message-provider>
|
||||
</template>
|
||||
|
||||
|
||||
<script setup>
|
||||
import MainApp from "./components/MainApp.vue";
|
||||
import { NMessageProvider } from "naive-ui";
|
||||
import { onMounted } from "vue";
|
||||
import { store } from "./store";
|
||||
|
||||
const setTitle = async () => {
|
||||
document.title = await store.loadTitle();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
setTitle();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
body {
|
||||
background-color: black;
|
||||
}
|
||||
</style>
|
16
web/src/ajax/ajax.js
Normal file
16
web/src/ajax/ajax.js
Normal file
@@ -0,0 +1,16 @@
|
||||
export const ajax = async (url, options) => {
|
||||
try {
|
||||
const r = await fetch(url, options)
|
||||
if (r.status >= 400) {
|
||||
throw Error(`request error with status ${r.status}`)
|
||||
}
|
||||
return await r.json()
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
return {
|
||||
succeed: false,
|
||||
message: e,
|
||||
data: null
|
||||
}
|
||||
}
|
||||
}
|
23
web/src/ajax/index.js
Normal file
23
web/src/ajax/index.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import { ajax } from './ajax'
|
||||
|
||||
export default {
|
||||
getTitle: async () => {
|
||||
const j = await ajax('api/v1/name')
|
||||
return j.data
|
||||
},
|
||||
getInstruction: async () => {
|
||||
const j = await ajax('api/v1/instruction')
|
||||
return j.data
|
||||
},
|
||||
getICEUrl: async () => {
|
||||
const j = await ajax('api/v1/iceserver/url')
|
||||
return j.data
|
||||
},
|
||||
exchangeSDP: async offer => {
|
||||
const answer = ajax('api/v1/sdp', {
|
||||
method: "POST",
|
||||
body: JSON.stringify(offer)
|
||||
})
|
||||
return answer
|
||||
}
|
||||
}
|
155
web/src/components/AceScreen.vue
Normal file
155
web/src/components/AceScreen.vue
Normal file
@@ -0,0 +1,155 @@
|
||||
<template>
|
||||
<video autoplay muted id="video"></video>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, defineProps } from "vue";
|
||||
import { store } from "../store";
|
||||
import ajax from "../ajax";
|
||||
|
||||
const props = defineProps(["methods"]);
|
||||
|
||||
const eventTypes = {
|
||||
mouseMove: 0,
|
||||
mouseButton: 1,
|
||||
keyboard: 2,
|
||||
control: 3,
|
||||
};
|
||||
|
||||
const controlEventTypes = {
|
||||
restart: 0,
|
||||
};
|
||||
|
||||
const makeEvent = (evType, args) => {
|
||||
return {
|
||||
type: eventTypes[evType],
|
||||
args: args,
|
||||
};
|
||||
};
|
||||
|
||||
// eslint-disable-next-line
|
||||
const sendSpecialKey = (key) => {
|
||||
console.log(key);
|
||||
|
||||
const specialKey = "ctrl-alt-" + key;
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("keyboard", {
|
||||
key: specialKey,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line
|
||||
const resetVM = () => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("control", {
|
||||
cmd: controlEventTypes.restart,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
let dataChannel;
|
||||
|
||||
onMounted(() => {
|
||||
console.log(props.methods);
|
||||
// eslint-disable-next-line
|
||||
props.methods.sendSpecialKey = sendSpecialKey;
|
||||
// eslint-disable-next-line
|
||||
props.methods.resetVM = resetVM;
|
||||
|
||||
const video = document.querySelector("video#video");
|
||||
video.oncontextmenu = () => false;
|
||||
|
||||
store.getICEServers().then((servers) => {
|
||||
const pc = new RTCPeerConnection({
|
||||
iceServers: [
|
||||
{
|
||||
urls: servers,
|
||||
},
|
||||
],
|
||||
});
|
||||
pc.oniceconnectionstatechange = () => console.log(pc.iceConnectionState);
|
||||
pc.addTransceiver("video");
|
||||
//pc.addTransceiver('audio')
|
||||
dataChannel = pc.createDataChannel("control");
|
||||
dataChannel.onmessage = (e) => {
|
||||
const d = JSON.parse(e.data);
|
||||
store.delay = +new Date() - d.server_time;
|
||||
store.qemuStatus = d.qemu_status;
|
||||
};
|
||||
pc.ontrack = (ev) => {
|
||||
video.srcObject = ev.streams[0];
|
||||
video.autoplay = true;
|
||||
video.controls = false;
|
||||
};
|
||||
video.onmousemove = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseMove", {
|
||||
dx: ev.clientX,
|
||||
dy: ev.clientY,
|
||||
dz: 0,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
video.onmousedown = (ev) => {
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("mouseButton", {
|
||||
button: ev.button << 1,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
//video.onmousewheel = (ev) => {};
|
||||
window.onkeydown = (ev) => {
|
||||
let key = "";
|
||||
if (ev.ctrlKey && ev.which !== 17) key = "ctrl-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.shiftKey && ev.which !== 16) key = "shift-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.altKey && ev.which !== 18) key = "alt-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (ev.metaKey && ev.which !== 91 && ev.which !== 93)
|
||||
key = "meta-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
if (!ev.altKey && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey)
|
||||
key = "0x" + ev.which.toString(16);
|
||||
|
||||
dataChannel.send(
|
||||
JSON.stringify(
|
||||
makeEvent("keyboard", {
|
||||
key: key,
|
||||
})
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
pc.createOffer().then((offer) => {
|
||||
pc.setLocalDescription(offer);
|
||||
ajax
|
||||
.exchangeSDP(offer)
|
||||
.then((answer) =>
|
||||
pc.setRemoteDescription(new RTCSessionDescription(answer))
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
video#video {
|
||||
vertical-align: middle;
|
||||
top: 50%;
|
||||
transform: translateY(-50%) translateX(-50%);
|
||||
left: 50%;
|
||||
position: absolute;
|
||||
max-height: 100%;
|
||||
max-width: 100%;
|
||||
}
|
||||
</style>
|
176
web/src/components/MainApp.vue
Normal file
176
web/src/components/MainApp.vue
Normal file
@@ -0,0 +1,176 @@
|
||||
<template>
|
||||
<div @contextmenu="noContextMenu">
|
||||
<n-watermark
|
||||
cross
|
||||
fullscreen
|
||||
v-if="show"
|
||||
:content="'ACE-' + title"
|
||||
:font-size="16"
|
||||
:line-height="16"
|
||||
:width="384"
|
||||
:height="384"
|
||||
:x-offset="12"
|
||||
:y-offset="60"
|
||||
:rotate="-15"
|
||||
></n-watermark>
|
||||
<div @mouseenter="menu" id="showMenu"></div>
|
||||
<div id="screenArea"><ace-screen :methods="screenController" /></div>
|
||||
<!-- eslint-disable vue/no-v-model-argument -->
|
||||
<n-drawer :width="480" v-model:show="show" :native-scrollbar="true">
|
||||
<n-drawer-content :title="title">
|
||||
<n-collapse
|
||||
:default-expanded-names="['controlButtons', 'instructions']"
|
||||
>
|
||||
<n-collapse-item title="控制按钮" name="controlButtons">
|
||||
<n-grid :cols="1" :y-gap="8">
|
||||
<n-grid-item>
|
||||
<p>Ctrl+Alt+?</p>
|
||||
<n-button-group>
|
||||
<n-button type="error" strong @click="sendCtrlAltDelete">
|
||||
Delete
|
||||
</n-button>
|
||||
<n-button strong @click="sendCtrlAltF1">F1</n-button>
|
||||
<n-button strong @click="sendCtrlAltF2">F2</n-button>
|
||||
<n-button strong @click="sendCtrlAltF3">F3</n-button>
|
||||
<n-button strong @click="sendCtrlAltF4">F4</n-button>
|
||||
<n-button strong @click="sendCtrlAltF5">F5</n-button>
|
||||
<n-button strong @click="sendCtrlAltF6">F6</n-button>
|
||||
<n-button strong @click="sendCtrlAltF7">F7</n-button>
|
||||
</n-button-group>
|
||||
</n-grid-item>
|
||||
<n-grid-item>
|
||||
<n-button type="error" strong @click="resetVM">
|
||||
重置
|
||||
<template #icon>
|
||||
<n-icon>
|
||||
<reload-icon />
|
||||
</n-icon>
|
||||
</template>
|
||||
</n-button>
|
||||
</n-grid-item>
|
||||
</n-grid>
|
||||
</n-collapse-item>
|
||||
<n-collapse-item title="介绍" name="instructions">
|
||||
<n-card>
|
||||
<n-skeleton v-if="loading" text :repeat="10" />
|
||||
<n-skeleton v-if="loading" text style="width: 60%" />
|
||||
<div v-else v-html="renderMarkdown"></div>
|
||||
</n-card>
|
||||
</n-collapse-item>
|
||||
<n-collapse-item title="统计信息" name="stat">
|
||||
<n-card>
|
||||
<p>当前延迟:{{ store.delay }}ms</p>
|
||||
<p>云电脑状态:{{ store.qemuStatus }}</p>
|
||||
</n-card>
|
||||
</n-collapse-item>
|
||||
</n-collapse>
|
||||
</n-drawer-content>
|
||||
</n-drawer>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
NDrawer,
|
||||
NDrawerContent,
|
||||
NWatermark,
|
||||
NCollapse,
|
||||
NCollapseItem,
|
||||
NButtonGroup,
|
||||
NButton,
|
||||
NIcon,
|
||||
NGridItem,
|
||||
NGrid,
|
||||
//NSpace,
|
||||
useMessage,
|
||||
NCard,
|
||||
NSkeleton,
|
||||
} from "naive-ui";
|
||||
import { Reload as ReloadIcon } from "@vicons/ionicons5";
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import AceScreen from "./AceScreen.vue";
|
||||
import { store } from "../store";
|
||||
import { marked } from "marked";
|
||||
|
||||
const show = ref(false);
|
||||
const title = ref("test123");
|
||||
const loading = ref(true);
|
||||
const menu = () => {
|
||||
show.value = true;
|
||||
};
|
||||
const noContextMenu = () => false;
|
||||
const message = useMessage();
|
||||
const instruction = ref("");
|
||||
const renderMarkdown = computed(() => {
|
||||
return marked.parse(
|
||||
instruction.value ? instruction.value : "# To be continued..."
|
||||
);
|
||||
});
|
||||
|
||||
const screenController = {};
|
||||
|
||||
const sendCtrlAltDelete = () => {
|
||||
sendSpecialKey("del");
|
||||
};
|
||||
|
||||
const sendCtrlAltF1 = () => {
|
||||
sendSpecialKey("f1");
|
||||
};
|
||||
|
||||
const sendCtrlAltF2 = () => {
|
||||
sendSpecialKey("f2");
|
||||
};
|
||||
|
||||
const sendCtrlAltF3 = () => {
|
||||
sendSpecialKey("f3");
|
||||
};
|
||||
|
||||
const sendCtrlAltF4 = () => {
|
||||
sendSpecialKey("f4");
|
||||
};
|
||||
|
||||
const sendCtrlAltF5 = () => {
|
||||
sendSpecialKey("f5");
|
||||
};
|
||||
|
||||
const sendCtrlAltF6 = () => {
|
||||
sendSpecialKey("f6");
|
||||
};
|
||||
|
||||
const sendCtrlAltF7 = () => {
|
||||
sendSpecialKey("f7");
|
||||
};
|
||||
|
||||
const sendSpecialKey = (key) => {
|
||||
screenController.sendSpecialKey(key);
|
||||
};
|
||||
|
||||
const resetVM = () => {
|
||||
screenController.resetVM();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
message.info("鼠标移动到屏幕右侧可打开控制面板");
|
||||
store.getTitle().then((t) => (title.value = t));
|
||||
store.loadInstruction().then((i) => {
|
||||
loading.value = false;
|
||||
instruction.value = i;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
div#showMenu {
|
||||
float: right;
|
||||
color: white;
|
||||
height: 100vh;
|
||||
width: 1px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
div#screenArea {
|
||||
height: 100vh;
|
||||
width: 100vw;
|
||||
zoom: 1;
|
||||
}
|
||||
</style>
|
4
web/src/main.js
Normal file
4
web/src/main.js
Normal file
@@ -0,0 +1,4 @@
|
||||
import { createApp } from 'vue'
|
||||
import App from './App.vue'
|
||||
|
||||
createApp(App).mount('#app')
|
33
web/src/store/index.js
Normal file
33
web/src/store/index.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import { reactive } from 'vue'
|
||||
import ajax from '../ajax'
|
||||
|
||||
export const store = reactive({
|
||||
title: '',
|
||||
iceServers: [],
|
||||
instruction: "",
|
||||
delay: 0,
|
||||
qemuStatus: "",
|
||||
|
||||
async loadTitle() {
|
||||
this.title = await ajax.getTitle()
|
||||
return this.title
|
||||
},
|
||||
async loadICEServers() {
|
||||
this.iceServers = await ajax.getICEUrl()
|
||||
return this.iceServers
|
||||
},
|
||||
async loadInstruction() {
|
||||
this.instruction = await ajax.getInstruction()
|
||||
return this.instruction
|
||||
},
|
||||
|
||||
async getTitle() {
|
||||
return this.title
|
||||
},
|
||||
async getICEServers() {
|
||||
return this.iceServers
|
||||
},
|
||||
async getInstruction() {
|
||||
return this.instruction
|
||||
}
|
||||
})
|
Reference in New Issue
Block a user