声音部分的代码仍需调试,现在panic
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
<template>
|
||||
<video autoplay muted id="video"></video>
|
||||
<div>
|
||||
<canvas id="vnc" />
|
||||
<div id="data"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@@ -25,6 +28,8 @@ const makeEvent = (evType, args) => ({
|
||||
args: args,
|
||||
});
|
||||
|
||||
let dataChannel;
|
||||
|
||||
// eslint-disable-next-line
|
||||
const sendSpecialKey = (key) => {
|
||||
console.log(key);
|
||||
@@ -50,8 +55,6 @@ const resetVM = () => {
|
||||
);
|
||||
};
|
||||
|
||||
let dataChannel;
|
||||
|
||||
onMounted(() => {
|
||||
console.log(props.methods);
|
||||
// eslint-disable-next-line
|
||||
@@ -59,8 +62,7 @@ onMounted(() => {
|
||||
// eslint-disable-next-line
|
||||
props.methods.resetVM = resetVM;
|
||||
|
||||
const video = document.querySelector("video#video");
|
||||
video.oncontextmenu = () => false;
|
||||
const video = document.querySelector("canvas#vnc");
|
||||
|
||||
store.getICEServers().then((servers) => {
|
||||
const pc = new RTCPeerConnection({
|
||||
@@ -71,19 +73,29 @@ onMounted(() => {
|
||||
],
|
||||
});
|
||||
pc.oniceconnectionstatechange = () => console.log(pc.iceConnectionState);
|
||||
pc.addTransceiver("video");
|
||||
pc.addTransceiver("audio");
|
||||
pc.addTransceiver("video", {
|
||||
direction: "recvonly",
|
||||
});
|
||||
pc.addTransceiver("audio", {
|
||||
direction: "recvonly",
|
||||
});
|
||||
|
||||
const dataChannel = pc.createDataChannel("control");
|
||||
dataChannel = pc.createDataChannel("control");
|
||||
dataChannel.onmessage = (e) => {
|
||||
const d = JSON.parse(e.data);
|
||||
const enc = new TextDecoder("utf-8");
|
||||
const buf = new Uint8Array(e.data);
|
||||
const d = JSON.parse(enc.decode(buf));
|
||||
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;
|
||||
console.log(ev);
|
||||
const el = document.createElement(ev.track.kind);
|
||||
el.id = ev.track.kind;
|
||||
el.srcObject = ev.streams[0];
|
||||
el.autoplay = true;
|
||||
el.controls = true;
|
||||
document.getElementById("data").appendChild(el);
|
||||
};
|
||||
|
||||
dataChannel.onopen = () => {
|
||||
@@ -109,16 +121,12 @@ onMounted(() => {
|
||||
};
|
||||
//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);
|
||||
let key = ev.key;
|
||||
if (ev.ctrlKey && ev.which !== 17) key = "ctrl-" + key;
|
||||
if (ev.shiftKey && ev.which !== 16) key = "shift-" + key;
|
||||
if (ev.altKey && ev.which !== 18) key = "alt-" + key;
|
||||
if (ev.metaKey && ev.which !== 91 && ev.which !== 93)
|
||||
key = "meta-" + ev.key;
|
||||
else key = "0x" + ev.which.toString(16);
|
||||
key = "meta-" + key;
|
||||
if (!ev.altKey && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey)
|
||||
key = "0x" + ev.which.toString(16);
|
||||
|
||||
|
Reference in New Issue
Block a user