Skip to content

Commit

Permalink
Merge pull request #750 from danymill/feature/device-reconnections
Browse files Browse the repository at this point in the history
Feature/device reconnections
  • Loading branch information
vdelendik authored Aug 15, 2023
2 parents 1ef206f + 73abdbe commit efd402c
Show file tree
Hide file tree
Showing 24 changed files with 775 additions and 614 deletions.
4 changes: 2 additions & 2 deletions lib/units/ios-device/plugins/devicenotifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = syrup.serial()
const log = logger.createLogger('device:plugins:notifier')
const notifier = {}

notifier.setDeviceTemporaryUnavialable = function(err) {
notifier.setDeviceTemporaryUnavailable = function(err) {
group.get()
.then((currentGroup) => {
push.send([
Expand All @@ -22,7 +22,7 @@ module.exports = syrup.serial()
])
})
.catch(err => {
log.error('Cannot set device temporary unavialable', err)
log.error('Cannot set device temporary unavailable', err)
})
}

Expand Down
2 changes: 1 addition & 1 deletion lib/units/ios-device/plugins/screen/stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = syrup.serial()

function handleSocketError(err, message) {
log.error(message, err)
notifier.setDeviceTemporaryUnavialable(err)
notifier.setDeviceTemporaryUnavailable(err)
ws.close()
}

Expand Down
13 changes: 1 addition & 12 deletions lib/units/websocket/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,17 +400,6 @@ module.exports = function(options) {
}
})
})
.on(wire.ConnectivityEvent, function(channel, message) {
var {serial} = message
delete message.serial
socket.emit('device.change', {
important: false,
data: {
serial: serial,
network: message
}
})
})
.on(wire.PhoneStateEvent, function(channel, message) {
var {serial} = message
delete message.serial
Expand Down Expand Up @@ -676,7 +665,7 @@ module.exports = function(options) {
} catch(e) {
log.error(e)
}

})
.on('input.touchMoveIos', function(channel, data) {
data.duration = 0.042
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = function blurElementDirective($parse, $timeout) {
module.exports = function blurElementDirective(
$parse,
$rootScope,
$timeout,
) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
Expand All @@ -13,7 +17,15 @@ module.exports = function blurElementDirective($parse, $timeout) {
})

element.bind('blur', function() {
scope.$apply(model.assign(scope, false))
if(!$rootScope.$$phase) {
scope.$apply(() => {
model.assign(scope, false)
})
} else {
scope.$applyAsync(() => {
model.assign(scope, false)
})
}
})
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = function focusElementDirective($parse, $timeout) {
module.exports = function focusElementDirective(
$parse,
$rootScope,
$timeout,
) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
Expand All @@ -14,7 +18,15 @@ module.exports = function focusElementDirective($parse, $timeout) {

element.bind('blur', function() {
if (model && model.assign) {
scope.$apply(model.assign(scope, false))
if(!$rootScope.$$phase) {
scope.$apply(() => {
model.assign(scope, false)
})
} else {
scope.$applyAsync(() => {
model.assign(scope, false)
})
}
}
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
module.exports =
function FatalMessageServiceFactory($uibModal, $location, $route, $interval,
StateClassesService) {
var FatalMessageService = {}
function FatalMessageServiceFactory(
$interval,
$location,
$route,
$uibModal,
StateClassesService,
) {
const FatalMessageService = {}
let intervalDeviceInfo

var intervalDeviceInfo

var ModalInstanceCtrl = function($scope, $uibModalInstance, device,
tryToReconnect) {
const ModalInstanceCtrl = function(
$scope,
$uibModalInstance,
device,
tryToReconnect,
) {
$scope.ok = function() {
$uibModalInstance.close(true)
$route.reload()
Expand Down Expand Up @@ -43,7 +51,7 @@ module.exports =
$uibModalInstance.dismiss('cancel')
}

var destroyInterval = function() {
const destroyInterval = function() {
if (angular.isDefined(intervalDeviceInfo)) {
$interval.cancel(intervalDeviceInfo)
intervalDeviceInfo = undefined
Expand All @@ -56,7 +64,7 @@ module.exports =
}

FatalMessageService.open = function(device, tryToReconnect) {
var modalInstance = $uibModal.open({
const modalInstance = $uibModal.open({
template: require('./fatal-message.pug'),
controller: ModalInstanceCtrl,
resolve: {
Expand All @@ -73,8 +81,9 @@ module.exports =
}, function() {

})
}

return modalInstance
}

return FatalMessageService
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = angular.module('stf.temporarily-unavailable', [
require('stf/common-ui/modals/common').name
])
.factory('TemporarilyUnavailableService', require('./temporarily-unavailable-service'))
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
module.exports =
function TemporarilyUnavialableServiceFactory($uibModal, $location, $window) {
function TemporarilyUnavailableServiceFactory($uibModal, $location, $window, $route) {
var service = {}

var ModalInstanceCtrl = function($scope, $uibModalInstance, message) {
$scope.ok = function() {
$uibModalInstance.close(true)
$window.location.reload()
$route.reload() // TODO: check if works and git history
}

$scope.message = message

$scope.cancel = function() {
$uibModalInstance.dismiss('cancel')
//document.getElementById('temporarily-unavialable').remove()
}

$scope.second = function() {
$uibModalInstance.dismiss()
$location.path('/devices/')
//document.getElementById('temporarily-unavialable').remove()
}

}

service.open = function(message) {
const tempModal = document.getElementById('temporarily-unavialable')
const tempModal = document.getElementById('temporarily-unavailable')

if(!tempModal) {
var modalInstance = $uibModal.open({
template: require('./temporarily-unavialable.pug'),
template: require('./temporarily-unavailable.pug'),
controller: ModalInstanceCtrl,
resolve: {
message: function() {
return message
}
}
},
openedClass: '_temporarily-unavailable-modal',
windowClass: 'temporarily-unavailable-modal',
windowTopClass: '_top',
})

modalInstance.result.then(function() {
}, function() {
})

return modalInstance
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.stf-modal#temporarily-unavialable
.stf-modal#temporarily-unavailable
.modal-header.dialog-header-errorX
button(type='button', ng-click='cancel()').close ×
h4.modal-title.text-danger
Expand Down

This file was deleted.

33 changes: 16 additions & 17 deletions res/app/components/stf/device/device-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,17 @@ module.exports = function DeviceServiceFactory($http, socket, EnhanceDeviceServi
}
}.bind(this)

function fetch(data) {
deviceService.load(data.serial)
.then(function(device) {
return changeListener({
important: true
, data: device
})
})
.catch(function() {})
}
// unused code
// function fetch(data) {
// deviceService.load(data.serial)
// .then(function(device) {
// return changeListener({
// important: true
// , data: device
// })
// })
// .catch(function() {})
// }

function addListener(event) {
var device = get(event.data)
Expand Down Expand Up @@ -247,16 +248,14 @@ module.exports = function DeviceServiceFactory($http, socket, EnhanceDeviceServi
})
}

deviceService.get = function(serial, $scope) {
var tracker = new Tracker($scope, {
filter: function(device) {
return device.serial === serial
}
, digest: true
deviceService.get = (serial, $scope) => {
const tracker = new Tracker($scope, {
filter: (device) => device.serial === serial,
digest: true,
})

return deviceService.load(serial)
.then(function(device) {
.then((device) => {
tracker.add(device)
return device
})
Expand Down
2 changes: 1 addition & 1 deletion res/app/components/stf/screen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = angular.module('stf/screen', [
, require('stf/page-visibility').name
, require('stf/browser-info').name
, require('stf/common-ui/nothing-to-show').name
, require('stf/common-ui/modals/temporarily-unavialable').name
, require('stf/common-ui/modals/temporarily-unavailable').name
, require('stf/screen/screen-loader').name
])
.directive('deviceScreen', require('./screen-directive'))
Expand Down
Loading

0 comments on commit efd402c

Please sign in to comment.