Skip to content

Commit

Permalink
try and remove lag in robotjs
Browse files Browse the repository at this point in the history
  • Loading branch information
max-mapper committed Oct 29, 2015
1 parent e3fcd4f commit 7c40772
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var connect = require('./connect.js')

var peer
var peerConnection = createPeerConnection()
window.pc = peerConnection

peerConnection.on('connected', function connected (newPeer, remote) {
peer = newPeer
Expand Down
6 changes: 5 additions & 1 deletion electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var mb = menubar({
icon: 'file://' + path.join(__dirname, 'img', 'Icon.png')
})

var win

mb.app.commandLine.appendSwitch('disable-renderer-backgrounding')

mb.on('ready', function ready () {
console.log('ready')
})
Expand All @@ -25,7 +29,7 @@ ipc.on('resize', function resize (ev, data) {
ipc.on('create-window', function (ev, config) {
console.log('create-window', [config])
mb.app.dock.show()
var win = new BrowserWindow({width: 720, height: 445})
win = new BrowserWindow({width: 720, height: 445})
win.loadUrl('file://' + path.join(__dirname, 'screen.html'))

win.on('closed', function () {
Expand Down
25 changes: 4 additions & 21 deletions peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function create (opts) {
var remoteConfigUrl = 'https://instant.io/rtcConfig'
if (process.browser) remoteConfigUrl = 'http://cors.maxogden.com/' + remoteConfigUrl

var video, videoSize
var videoSize

var constraints = {
audio: false,
Expand Down Expand Up @@ -203,7 +203,6 @@ module.exports = function create (opts) {

function onConnect (peer, remote) {
pc.emit('connected', peer, remote)
var queue = []

if (remote) {
window.addEventListener('mousedown', mousedownListener)
Expand All @@ -212,8 +211,9 @@ module.exports = function create (opts) {

if (!remote) {
peer.on('data', function (data) {
queue.push(data)
if (queue.length === 1) startQueue()
if (!pc.robot) return
console.log(data)
pc.robot(data)
})
return
}
Expand Down Expand Up @@ -259,23 +259,6 @@ module.exports = function create (opts) {

return data
}

// magic queue that helps prevent weird key drop issues on the c++ side
function startQueue () {
if (queue.started) return
queue.started = true
queue.id = setInterval(function () {
var next = queue.shift()
if (!next) {
clearInterval(queue.id)
queue.started = false
return
}
if (pc.robot) {
pc.robot(next)
}
}, 0)
}
}

function videoElement (stream) {
Expand Down
9 changes: 3 additions & 6 deletions robot.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* global screen */
var robot = require('robotjs')
window.robot = robot
var vkey = require('vkey')

module.exports = function createEvents (data) {
Expand All @@ -8,12 +9,8 @@ module.exports = function createEvents (data) {
var y = scale(data.clientY, 0, data.canvasHeight, 0, screen.height)
var pos = robot.getMousePos() // hosts current x/y
robot.moveMouse(x, y) // move to remotes pos
setTimeout(function () {
robot.mouseClick() // click on remote click spot
setTimeout(function () {
robot.moveMouse(pos.x, pos.y) // go back to hosts position
}, 20)
}, 20)
robot.mouseClick() // click on remote click spot
robot.moveMouse(pos.x, pos.y) // go back to hosts position
}

if (data.keyCode) {
Expand Down

0 comments on commit 7c40772

Please sign in to comment.