debug needed

This commit is contained in:
TonyChyi
2022-09-26 16:07:25 +08:00
parent bd0812cc42
commit 821c0cffb8
12 changed files with 148 additions and 171 deletions

View File

@@ -74,8 +74,9 @@ onMounted(() => {
});
pc.oniceconnectionstatechange = () => console.log(pc.iceConnectionState);
pc.addTransceiver("video");
//pc.addTransceiver('audio')
dataChannel = pc.createDataChannel("control");
pc.addTransceiver("audio");
const dataChannel = pc.createDataChannel("control");
dataChannel.onmessage = (e) => {
const d = JSON.parse(e.data);
store.delay = +new Date() - d.server_time;
@@ -86,48 +87,51 @@ onMounted(() => {
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,
})
)
);
dataChannel.onopen = () => {
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) => {