Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
feat: reconnection. BRUTE FORCE
Browse files Browse the repository at this point in the history
  • Loading branch information
neko-para committed Aug 20, 2023
1 parent bffbef7 commit 8323da9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
10 changes: 7 additions & 3 deletions packages/client/src/components/framework/MonitorView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ async function tryConnect() {
}
socket = await api.controller()
socket.onclose = () => {
console.log('close!')
socket = null
setTimeout(() => {
tryConnect()
}, 100)
}
socket.onmessage = async ev => {
console.log('got image')
// console.log('got image')
fr += 1
const cur = fr
Expand All @@ -43,11 +47,11 @@ async function tryConnect() {
const image = new Image(1280, 720)
image.onload = () => {
if (cur < prefr) {
console.log('skip image')
// console.log('skip image')
return
}
prefr = cur
console.log('draw image')
// console.log('draw image')
ctx.drawImage(image, 0, 0, 1280, 720, 0, 0, props.width, props.height)
}
image.src = url
Expand Down
19 changes: 13 additions & 6 deletions packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,18 @@ async function main() {
let pending = false
let quit = false

let skipCount = 0

const timer = setInterval(async () => {
if (controller) {
console.log(`/api/controller ${id} start push`)
// console.log(`/api/controller ${id} start push`)
if (pending) {
console.log(`/api/controller ${id} skipped`)
// console.log(`/api/controller ${id} skipped`)
skipCount += 1
if (skipCount > 10) {
console.log(`/api/controller ${id} skip too much`)
ws.close()
}
return
}
pending = true
Expand All @@ -138,19 +145,19 @@ async function main() {
if (quit) {
return
}
console.log(`/api/controller ${id} get image`)
// console.log(`/api/controller ${id} get image`)
const buffer = controller.image()
pending = false
if (buffer) {
console.log(`/api/controller ${id} push image`)
// console.log(`/api/controller ${id} push image`)
ws.send(buffer)
}
} else {
console.log(`/api/controller ${id} screencap failed`)
// console.log(`/api/controller ${id} screencap failed`)
pending = false
}
}
}, 500)
}, 100)
ws.on('close', () => {
quit = true
console.log(`/api/controller ${id} closed`)
Expand Down

0 comments on commit 8323da9

Please sign in to comment.