diff --git a/lib/roles/app.js b/lib/roles/app.js index 5fb1767a..2ce54a93 100644 --- a/lib/roles/app.js +++ b/lib/roles/app.js @@ -8,6 +8,7 @@ var validator = require('express-validator') var socketio = require('socket.io') var zmq = require('zmq') var Promise = require('bluebird') +var adb = require('adbkit') var logger = require('../util/logger') var pathutil = require('../util/pathutil') @@ -240,9 +241,9 @@ module.exports = function(options) { }) function touchSender(klass) { - return function(data) { + return function(channel, data) { push.send([ - user.group + channel , wireutil.envelope(new klass( data.x , data.y @@ -252,9 +253,9 @@ module.exports = function(options) { } function keySender(klass) { - return function(data) { + return function(channel, data) { push.send([ - user.group + channel , wireutil.envelope(new klass( data.key )) @@ -271,19 +272,40 @@ module.exports = function(options) { socket.on('input.keyUp', keySender(wire.KeyUpMessage)) socket.on('input.keyPress', keySender(wire.KeyPressMessage)) - socket.on('input.type', function(data) { + socket.on('input.type', function(channel, data) { push.send([ - group + channel , wireutil.envelope(new wire.TypeMessage( data.text )) ]) }) - // @todo - socket.on('input.back', function(data) {}) - socket.on('input.home', function(data) {}) - socket.on('input.menu', function(data) {}) + function fixedKeySender(klass, key) { + return function(channel) { + push.send([ + channel + , wireutil.envelope(new klass( + key + )) + ]) + } + } + + socket.on('input.back', fixedKeySender( + wire.KeyPressMessage + , adb.Keycode.KEYCODE_BACK + )) + + socket.on('input.home', fixedKeySender( + wire.KeyPressMessage + , adb.Keycode.KEYCODE_HOME + )) + + socket.on('input.menu', fixedKeySender( + wire.KeyPressMessage + , adb.Keycode.KEYCODE_MENU + )) socket.on('flick', function(data) {}) socket.on('back', function(data) {}) diff --git a/lib/roles/device.js b/lib/roles/device.js index 720e4966..dce7afdd 100644 --- a/lib/roles/device.js +++ b/lib/roles/device.js @@ -366,16 +366,16 @@ module.exports = function(options) { services.input.tapAsync(message.x, message.y) }) .on(wire.TypeMessage, function(channel, message) { - services.input.typeAsync(message.text) + services.monkey.typeAsync(message.text) }) .on(wire.KeyDownMessage, function(channel, message) { - services.input.keyDownAsync(message.key) + services.monkey.keyDownAsync(message.key) }) .on(wire.KeyUpMessage, function(channel, message) { - services.input.keyUpAsync(message.key) + services.monkey.keyUpAsync(message.key) }) .on(wire.KeyPressMessage, function(channel, message) { - services.input.pressAsync(message.key) + services.monkey.pressAsync(message.key) }) .on(wire.ShellCommandMessage, function(channel, message) { log.info('Running shell command "%s"', message.command.join(' ')) diff --git a/res/app/scripts/controllers/DeviceControlCtrl.js b/res/app/scripts/controllers/DeviceControlCtrl.js index 0a2ba2d9..3d3278d5 100644 --- a/res/app/scripts/controllers/DeviceControlCtrl.js +++ b/res/app/scripts/controllers/DeviceControlCtrl.js @@ -1,10 +1,12 @@ define(['./_module'], function(controllers) { - function DeviceControlCtrl($scope, $routeParams, deviceService) { + function DeviceControlCtrl($scope, $routeParams, deviceService, controlService) { $scope.device = null + $scope.control = null deviceService.get($routeParams.serial) .then(function(device) { $scope.device = device + $scope.control = controlService.forChannel(device.channel) }) } @@ -12,6 +14,7 @@ define(['./_module'], function(controllers) { , [ '$scope' , '$routeParams' , 'DeviceService' + , 'ControlService' , DeviceControlCtrl ]) }) diff --git a/res/app/scripts/services/ControlService.js b/res/app/scripts/services/ControlService.js index 039804d4..441107ac 100644 --- a/res/app/scripts/services/ControlService.js +++ b/res/app/scripts/services/ControlService.js @@ -1,51 +1,56 @@ define(['./_module', 'lodash'], function(services, _) { function ControlServiceFactory($rootScope, socket) { var controlService = { - members: [] } - function touchSender(type) { - return function(x, y) { - socket.emit(type, { - x: x - , y: y + function ControlService(channel) { + function touchSender(type) { + return function(x, y) { + socket.emit(type, channel, { + x: x + , y: y + }) + } + } + + function keySender(type) { + return function(key) { + socket.emit(type, channel, { + key: key + }) + } + } + + this.touchDown = touchSender('input.touchDown') + this.touchMove = touchSender('input.touchMove') + this.touchUp = touchSender('input.touchUp') + this.tap = touchSender('input.tap') + + this.keyDown = keySender('input.keyDown') + this.keyUp = keySender('input.keyUp') + this.keyPress = keySender('input.keyPress') + + this.home = function() { + socket.emit('input.home', channel) + } + + this.menu = function() { + socket.emit('input.menu', channel) + } + + this.back = function() { + socket.emit('input.back', channel) + } + + this.type = function(text) { + socket.emit('input.type', channel, { + text: text }) } } - function keySender(type) { - return function(key) { - socket.emit(type, { - key: key - }) - } - } - - controlService.touchDown = touchSender('input.touchDown') - controlService.touchMove = touchSender('input.touchMove') - controlService.touchUp = touchSender('input.touchUp') - controlService.tap = touchSender('input.tap') - - controlService.keyDown = keySender('input.keyDown') - controlService.keyUp = keySender('input.keyUp') - controlService.keyPress = keySender('input.keyPress') - - controlService.home = function() { - socket.emit('input.home') - } - - controlService.menu = function() { - socket.emit('input.menu') - } - - controlService.back = function() { - socket.emit('input.back') - } - - controlService.type = function(text) { - socket.emit('input.type', { - text: text - }) + controlService.forChannel = function(channel) { + return new ControlService(channel) } return controlService diff --git a/res/app/views/partials/devices/control.jade b/res/app/views/partials/devices/control.jade index 43bc294e..1f2c4322 100644 --- a/res/app/views/partials/devices/control.jade +++ b/res/app/views/partials/devices/control.jade @@ -1 +1,5 @@ h1 {{ device.serial }} + +button(ng-click='control.menu()') Menu +button(ng-click='control.home()') Home +button(ng-click='control.back()') Back