This commit is contained in:
giongto35 2019-04-14 01:21:14 +08:00
parent 3e5bc04019
commit e96b2a4072
3 changed files with 17 additions and 19 deletions

View file

@ -63,7 +63,6 @@ function chooseGame(idx, force=false) {
function setState(e, bo) {
if (e.keyCode in KEY_MAP) {
keyState[KEY_MAP[e.keyCode]] = bo;
stateUnchange = false;
unchangePacket = INPUT_STATE_PACKET;
}
}
@ -149,7 +148,7 @@ document.body.onkeydown = function (e) {
function sendInput() {
// prepare key
if (stateUnchange || unchangePacket > 0) {
if (unchangePacket > 0) {
st = "";
KEY_BIT.slice().reverse().forEach(elem => {
st += keyState[elem] ? 1 : 0;
@ -162,7 +161,6 @@ function sendInput() {
a[0] = ss;
inputChannel.send(a);
stateUnchange = false;
unchangePacket--;
}
}

View file

@ -32,7 +32,6 @@ keyState = {
quit: false
}
stateUnchange = true;
unchangePacket = INPUT_STATE_PACKET;
inputTimer = null;
@ -53,4 +52,4 @@ function log(msg) {
document.getElementById('div').innerHTML += msg + '<br>'
console.log(msg);
}
}
}

View file

@ -98,6 +98,21 @@ function startWebRTC() {
pc.createOffer({offerToReceiveVideo: true, offerToReceiveAudio: false}).then(d => {
pc.setLocalDescription(d).catch(log);
})
// input channel
inputChannel = pc.createDataChannel('foo')
inputChannel.onclose = () => {
log('inputChannel has closed');
}
inputChannel.onopen = () => {
log('inputChannel has opened');
}
inputChannel.onmessage = e => {
log(`Message from DataChannel '${inputChannel.label}' payload '${e.data}'`);
}
}
function startGame() {
@ -114,19 +129,5 @@ function startGame() {
}
// end clear
// input channel
inputChannel = pc.createDataChannel('foo')
inputChannel.onclose = () => {
log('inputChannel has closed');
}
inputChannel.onopen = () => {
log('inputChannel has opened');
}
inputChannel.onmessage = e => {
log(`Message from DataChannel '${inputChannel.label}' payload '${e.data}'`);
}
startInput();
}