Skip to content

Commit

Permalink
Merge pull request #988 from zebrunner/develop
Browse files Browse the repository at this point in the history
2.7.2 rc
  • Loading branch information
dhreben authored Aug 12, 2024
2 parents 3379432 + 7c9734b commit 605a7ef
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 87 deletions.
47 changes: 20 additions & 27 deletions lib/units/ios-device/plugins/screen/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const wire = require('../../../../wire')

const logger = require('../../../../util/logger')
const iosutil = require('../util/iosutil')
const { Transform } = require('stream')

module.exports = syrup.serial()
.dependency(require('../solo'))
Expand Down Expand Up @@ -63,18 +64,28 @@ module.exports = syrup.serial()
chain
.then(() => handleSocketError({message: 'Connection failed to WDA MJPEG port'}, 'Consumer error'))
.catch(result => {
if(result) {
result.response.pipe(consumer).pipe(stream)
if (result) {
const transformStream = new Transform({
transform(chunk, encoding, callback) {
if (WdaClient.isSwiping) {
ws.send(JSON.stringify({ type: 'swiping', message: 'Swiping detected' }));
}
callback(null, chunk);
}
});

result.response.pipe(consumer).pipe(transformStream).pipe(stream);
//[VD] We can't launch homeBtn otherwise opening in STF corrupt test automation run. Also no sense to execute connect
WdaClient.startSession()

WdaClient.startSession();
//WdaClient.homeBtn() //no existing session detected so we can press home button to wake up device automatically

// override already existing error handler
result.frameStream.on('error', function(err) {
handleSocketError(err, 'frameStream error ')
})
handleSocketError(err, 'frameStream error');
});
}
})
});
}

consumer.on('error', err => {
Expand All @@ -93,27 +104,9 @@ module.exports = syrup.serial()
ws.on('close', function() {
// @TODO handle close event
// stream.socket.onclose()
const orientation = WdaClient.orientation

const stoppingSession = () => {
WdaClient.stopSession()
isConnectionAlive = false
log.important('ws on close event')
}

if (WdaClient.deviceType === 'Apple TV' || orientation === 'PORTRAIT') {
return stoppingSession()
}

// #770: Reset rotation to Portrait when closing device

const rotationPromise = new Promise((resolve, reject) => {
// Ensure that rotation is done, then stop session
WdaClient.rotation({orientation: 'PORTRAIT'})
resolve()
})

rotationPromise.delay(2000).then(() => stoppingSession())
WdaClient.stopSession()
isConnectionAlive = false
log.important('ws on close event')
})
ws.on('error', function() {
// @TODO handle error event
Expand Down
8 changes: 4 additions & 4 deletions lib/units/ios-device/plugins/util/iosutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ let iosutil = {
}
case 'LANDSCAPE':
return {
fromX: params.fromX * deviceSize.width,
fromY: params.fromY * deviceSize.height,
toX: params.toX * deviceSize.width,
toY: params.toY * deviceSize.height,
fromX: params.fromY * deviceSize.height,
fromY: params.fromX * deviceSize.width,
toX: params.toY * deviceSize.height,
toY: params.toX * deviceSize.width,
duration: params.duration
}
default:
Expand Down
28 changes: 14 additions & 14 deletions lib/units/ios-device/plugins/wda/WdaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,20 +334,20 @@ module.exports = syrup.serial()

if(((new Date()).getTime() - this.tapStartAt) <= 1000 || !this.tapStartAt) {

const body = {
actions: [
{
type: 'pointer',
id: 'finger1',
parameters: {pointerType: 'touch'},
actions: [
{type: 'pointerMove', duration: 0, x, y},
{type: 'pointerMove', duration: 0, x, y},
{type: 'pointerUp'},
],
},
],
}
let body = {
actions: [
{
type: 'pointer',
id: 'finger1',
parameters: {pointerType: 'touch'},
actions: [
{type: 'pointerMove', duration: 0, x: this.orientation === 'PORTRAIT' ? x : y, y: this.orientation === 'PORTRAIT' ? y : x},
{type: 'pointerMove', duration: 0, x: this.orientation === 'PORTRAIT' ? x : y, y: this.orientation === 'PORTRAIT' ? y : x},
{type: 'pointerUp'},
],
},
],
}

if (this.deviceType !== 'Apple TV') {
log.info(options.deviceName)
Expand Down
4 changes: 2 additions & 2 deletions lib/units/websocket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,8 @@ module.exports = function(options) {
})
.on('user.keys.accessToken.remove', function(data) {
return dbapi
.removeUserAccessToken(user.email, data.title)
.then(function() {
.removeAccessToken(data.id)
.then(function() {
socket.emit('user.keys.accessToken.updated')
})
})
Expand Down
7 changes: 0 additions & 7 deletions res/app/components/stf/screen/scaling/scaling-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,6 @@ module.exports = function ScalingServiceFactory() {
w = scaledValue
}

if (rotation === 90 && isIosDevice) {
return {
xP: y / h,
yP: x / w
}
}

return {
xP: x / w
, yP: y / h
Expand Down
28 changes: 27 additions & 1 deletion res/app/components/stf/screen/screen-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ module.exports = function DeviceScreenDirective(
let wsReconnectionTimeoutID = null
let wsReconnecting = false
let tempUnavailableModalInstance = null
let swipeMessage = false

$scope.screen = screen
ScreenLoaderService.show()
Expand Down Expand Up @@ -220,6 +221,31 @@ module.exports = function DeviceScreenDirective(

function messageListener(message) {
screen.rotation = $scope.device.display.rotation
let swipeTimeout;


if (typeof message.data === 'string') {
const data = JSON.parse(message.data);
if (data.type === 'swiping') {
swipeMessage = true;
const loadingScreen = document.getElementsByClassName('lds-roller')[0]
if (loadingScreen) {
ScreenLoaderService.show()
loadingScreen.style.backdropFilter = 'none'
loadingScreen.style.backgroundColor = 'transparent'

if (swipeTimeout) {
clearTimeout(swipeTimeout);
}

swipeTimeout = setTimeout(() => {
swipeMessage = false;
}, 1500);

return;
}
}
}

if (message.data instanceof Blob) {
if (shouldUpdateScreen()) {
Expand All @@ -228,7 +254,7 @@ module.exports = function DeviceScreenDirective(
$scope.displayError = false
})
}
if (ScreenLoaderService.isVisible) {
if (ScreenLoaderService.isVisible && !swipeMessage) {
ScreenLoaderService.hide()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
border-radius: 50%;
background: #fff;
margin: -4px 0 0 -4px;
box-shadow: rgba(6, 24, 44, 0.4) 0px 0px 0px 1px, rgba(6, 24, 44, 0.65) 0px 0px 0px -1px, rgba(255, 255, 255, 0.08) 0px 1px 0px inset
}
.lds-roller__item:nth-child(1) {
animation-delay: -0.036s;
Expand Down
6 changes: 3 additions & 3 deletions res/app/components/stf/tokens/access-token-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = function AccessTokenServiceFactory(
var AccessTokenService = {}

AccessTokenService.getAccessTokens = function() {
return $http.get('/api/v1/user/accessTokens')
return $http.get('/api/v1/user/fullAccessTokens')
}

AccessTokenService.generateAccessToken = function(title) {
Expand All @@ -19,9 +19,9 @@ module.exports = function AccessTokenServiceFactory(
})
}

AccessTokenService.removeAccessToken = function(title) {
AccessTokenService.removeAccessToken = function(id) {
socket.emit('user.keys.accessToken.remove', {
title: title
id: id
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,17 @@ module.exports = function generateAccessTokenDirective() {
}

$scope.generateToken = function() {
if (!$scope.generateForm.title) {
return
}

AccessTokenService.generateAccessToken($scope.generateForm.title)
$scope.closeGenerateToken()
}

$scope.closeGenerateToken = function() {
$scope.title = ''
$scope.generateForm.title = ''
$scope.showGenerate = false
}
}
Expand Down
19 changes: 9 additions & 10 deletions res/app/control-panes/device-control/device-control-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,29 +92,28 @@ module.exports = function DeviceControlCtrl($scope, DeviceService, GroupService,
if (rotation === 'portrait') {
$scope.control.rotate(0)
$timeout(function() {
if (isLandscape()) {
console.log('tryToRotate is Landscape')
$scope.currentRotation = 'landscape'
}
isLandscape() ? $scope.currentRotation = 'landscape' : $scope.currentRotation = 'portrait'
}, 400)
} else if (rotation === 'landscape') {
$scope.control.rotate(90)
$timeout(function() {
if (isPortrait()) {
console.log('tryToRotate but it still porttrait')
$scope.currentRotation = 'portrait'
}
isPortrait() ? $scope.currentRotation = 'portrait' : $scope.currentRotation = 'landscape'
}, 400)
}
}

$scope.currentRotation = 'portrait'

$scope.$watch('device.display.rotation', function(newValue) {
$scope.currentRotation = 'rotating'
if (isPortrait(newValue)) {
$scope.currentRotation = 'portrait'
$timeout(function() {
isLandscape() ? $scope.currentRotation = 'landscape' : $scope.currentRotation = 'portrait'
}, 400)
} else if (isLandscape(newValue)) {
$scope.currentRotation = 'landscape'
$timeout(function() {
isPortrait() ? $scope.currentRotation = 'portrait' : $scope.currentRotation = 'landscape'
}, 400)
}
})

Expand Down
2 changes: 1 addition & 1 deletion res/app/control-panes/device-control/device-control.pug
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.interact-control.fill-height.as-table.stf-device-control(ng-controller='DeviceControlCtrl')
.as-cell.fill-height
.as-table.fill-height
.stf-vnc-navbar.as-row(ng-show='!$root.basicMode && !$root.standalone')
.stf-vnc-navbar.as-row(ng-show='!$root.standalone')
.stf-vnc-control-header.as-cell
.stf-vnc-right-buttons.pull-right
.btn-group
Expand Down
26 changes: 25 additions & 1 deletion res/app/device-list/column/device-column-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ module.exports = function DeviceColumnService($filter, gettext, SettingsService,
return (device.network.type || '').toUpperCase()
}
})
, display: TextCell({
, display: ScreenCell({
title: gettext('Screen')
, defaultOrder: 'desc'
, value: function(device) {
Expand Down Expand Up @@ -420,6 +420,30 @@ function TextCell(options) {
})
}

function ScreenCell(options) {
return _.defaults(options, {
title: options.title
, defaultOrder: 'asc'
, build: function() {
var td = document.createElement('td')
td.appendChild(document.createTextNode(''))
td.id = 'device-screen'
return td
}
, update: function(td, item) {
var t = td.firstChild
t.nodeValue = options.value(item)
return td
}
, compare: function(a, b) {
return compareIgnoreCase(options.value(a), options.value(b))
}
, filter: function(item, filter) {
return filterIgnoreCase(options.value(item), filter.query)
}
})
}

function NumberCell(options) {
return _.defaults(options, {
title: options.title
Expand Down
32 changes: 31 additions & 1 deletion res/app/device-list/details/device-list-details-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,31 @@ module.exports = function DeviceListDetailsDirective(

}

function escapeCSSSelector(id) {
return id.replace(/([!\"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~])/g, '\\$1');
}

function checkUpdatedData(device) {
if (device.using && device.state === 'using' && (!device.display.width || !device.display.height)) {
setTimeout(() => {
return $route.reload()
}, 1000);
}

const escapedId = escapeCSSSelector(calculateId(device));
const deviceRow = tbody.querySelector(`#${escapedId}`);

if (deviceRow && device.display.width && device.display.height) {
const sizeText = `${device.display.width.toString()}x${device.display.height.toString()}`

const sizeTd = deviceRow.querySelector('td#device-screen');

if (sizeTd && sizeTd.innerText !== sizeText) {
$route.reload()
}
}
}

// Triggers when the tracker sees a device for the first time.
function addListener(device) {
let deviceData = localStorage.getItem('deviceData') ? JSON.parse(localStorage.getItem('deviceData')) : [];
Expand Down Expand Up @@ -721,18 +746,23 @@ module.exports = function DeviceListDetailsDirective(
localStorage.setItem('deviceData', JSON.stringify(deviceData))

let row = createRow(device)

filterRow(row, device)
insertRow(row, device)
}

storeRows()
updateFilters(scope.filter())

checkUpdatedData(device)
}

// Triggers when the tracker notices that a device changed.
function changeListener(device) {
var id = calculateId(device)
var tr = tbody.children[id]

checkUpdatedData(device)

storeDevices(device)

Expand All @@ -750,8 +780,8 @@ module.exports = function DeviceListDetailsDirective(
// Should go lower in the list
insertRowToSegment(tr, device, tr.rowIndex + 1, rows.length - 1);
}

}

}

// Triggers when a device is removed entirely from the tracker.
Expand Down
Loading

0 comments on commit 605a7ef

Please sign in to comment.