1
1
import * as applicationManagerPath from "./ios-application-manager" ;
2
2
import * as fileSystemPath from "./ios-device-file-system" ;
3
- import * as constants from "../../../constants" ;
3
+ import * as commonConstants from "../../../constants" ;
4
+ import * as constants from "../../../../constants" ;
4
5
import * as net from "net" ;
5
6
import { cache } from "../../../decorators" ;
7
+ import * as helpers from "../../../../common/helpers" ;
8
+ import { IOSDeviceBase } from "../ios-device-base" ;
6
9
7
- export class IOSDevice implements Mobile . IiOSDevice {
10
+ export class IOSDevice extends IOSDeviceBase {
8
11
public applicationManager : Mobile . IDeviceApplicationManager ;
9
12
public fileSystem : Mobile . IDeviceFileSystem ;
10
13
public deviceInfo : Mobile . IDeviceInfo ;
11
-
12
- private _socket : net . Socket ;
13
14
private _deviceLogHandler : ( ...args : any [ ] ) => void ;
14
15
15
16
constructor ( private deviceActionInfo : IOSDeviceLib . IDeviceActionInfo ,
17
+ protected $errors : IErrors ,
16
18
private $injector : IInjector ,
17
- private $processService : IProcessService ,
19
+ protected $iOSDebuggerPortService : IIOSDebuggerPortService ,
20
+ private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
21
+ protected $processService : IProcessService ,
18
22
private $deviceLogProvider : Mobile . IDeviceLogProvider ,
19
23
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
20
24
private $iOSDeviceProductNameMapper : Mobile . IiOSDeviceProductNameMapper ,
21
25
private $iosDeviceOperations : IIOSDeviceOperations ,
22
26
private $mobileHelper : Mobile . IMobileHelper ) {
23
-
27
+ super ( ) ;
24
28
this . applicationManager = this . $injector . resolve ( applicationManagerPath . IOSApplicationManager , { device : this , devicePointer : this . deviceActionInfo } ) ;
25
29
this . fileSystem = this . $injector . resolve ( fileSystemPath . IOSDeviceFileSystem , { device : this , devicePointer : this . deviceActionInfo } ) ;
26
-
27
30
const productType = deviceActionInfo . productType ;
28
31
const isTablet = this . $mobileHelper . isiOSTablet ( productType ) ;
29
- const deviceStatus = deviceActionInfo . status || constants . UNREACHABLE_STATUS ;
32
+ const deviceStatus = deviceActionInfo . status || commonConstants . UNREACHABLE_STATUS ;
30
33
this . deviceInfo = {
31
34
identifier : deviceActionInfo . deviceId ,
32
35
vendor : "Apple" ,
33
36
platform : this . $devicePlatformsConstants . iOS ,
34
37
status : deviceStatus ,
35
- errorHelp : deviceStatus === constants . UNREACHABLE_STATUS ? `Device ${ deviceActionInfo . deviceId } is ${ constants . UNREACHABLE_STATUS } ` : null ,
38
+ errorHelp : deviceStatus === commonConstants . UNREACHABLE_STATUS ? `Device ${ deviceActionInfo . deviceId } is ${ commonConstants . UNREACHABLE_STATUS } ` : null ,
36
39
type : "Device" ,
37
40
isTablet : isTablet ,
38
41
displayName : this . $iOSDeviceProductNameMapper . resolveProductName ( deviceActionInfo . deviceName ) || deviceActionInfo . deviceName ,
@@ -47,8 +50,29 @@ export class IOSDevice implements Mobile.IiOSDevice {
47
50
return false ;
48
51
}
49
52
50
- public getApplicationInfo ( applicationIdentifier : string ) : Promise < Mobile . IApplicationInfo > {
51
- return this . applicationManager . getApplicationInfo ( applicationIdentifier ) ;
53
+ @cache ( )
54
+ public async openDeviceLogStream ( ) : Promise < void > {
55
+ if ( this . deviceInfo . status !== commonConstants . UNREACHABLE_STATUS ) {
56
+ this . _deviceLogHandler = this . actionOnDeviceLog . bind ( this ) ;
57
+ this . $iosDeviceOperations . on ( commonConstants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
58
+ this . $iosDeviceOperations . startDeviceLog ( this . deviceInfo . identifier ) ;
59
+ }
60
+ }
61
+
62
+ protected async getSocketCore ( appId : string ) : Promise < net . Socket > {
63
+ await this . $iOSSocketRequestExecutor . executeAttachRequest ( this , constants . AWAIT_NOTIFICATION_TIMEOUT_SECONDS , appId ) ;
64
+ const port = await this . getDebuggerPort ( appId ) ;
65
+ const deviceId = this . deviceInfo . identifier ;
66
+ const socket = await helpers . connectEventuallyUntilTimeout (
67
+ async ( ) => {
68
+ const deviceResponse = _ . first ( ( await this . $iosDeviceOperations . connectToPort ( [ { deviceId : deviceId , port : port } ] ) ) [ deviceId ] ) ;
69
+ const _socket = new net . Socket ( ) ;
70
+ _socket . connect ( deviceResponse . port , deviceResponse . host ) ;
71
+ return _socket ;
72
+ } ,
73
+ commonConstants . SOCKET_CONNECTION_TIMEOUT_MS ) ;
74
+
75
+ return socket ;
52
76
}
53
77
54
78
private actionOnDeviceLog ( response : IOSDeviceLib . IDeviceLogData ) : void {
@@ -57,34 +81,12 @@ export class IOSDevice implements Mobile.IiOSDevice {
57
81
}
58
82
}
59
83
60
- @cache ( )
61
- public async openDeviceLogStream ( ) : Promise < void > {
62
- if ( this . deviceInfo . status !== constants . UNREACHABLE_STATUS ) {
63
- this . _deviceLogHandler = this . actionOnDeviceLog . bind ( this ) ;
64
- this . $iosDeviceOperations . on ( constants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
65
- this . $iosDeviceOperations . startDeviceLog ( this . deviceInfo . identifier ) ;
66
- }
67
- }
68
-
69
84
public detach ( ) : void {
70
85
if ( this . _deviceLogHandler ) {
71
- this . $iosDeviceOperations . removeListener ( constants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
86
+ this . $iosDeviceOperations . removeListener ( commonConstants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
72
87
}
73
88
}
74
89
75
- // This function works only on OSX
76
- public async connectToPort ( port : number ) : Promise < net . Socket > {
77
- const deviceId = this . deviceInfo . identifier ;
78
- const deviceResponse = _ . first ( ( await this . $iosDeviceOperations . connectToPort ( [ { deviceId : deviceId , port : port } ] ) ) [ deviceId ] ) ;
79
-
80
- const socket = new net . Socket ( ) ;
81
- socket . connect ( deviceResponse . port , deviceResponse . host ) ;
82
- this . _socket = socket ;
83
-
84
- this . $processService . attachToProcessExitSignals ( this , this . destroySocket ) ;
85
- return this . _socket ;
86
- }
87
-
88
90
private getActiveArchitecture ( productType : string ) : string {
89
91
let activeArchitecture = "" ;
90
92
if ( productType ) {
@@ -106,13 +108,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
106
108
107
109
return activeArchitecture ;
108
110
}
109
-
110
- private destroySocket ( ) {
111
- if ( this . _socket ) {
112
- this . _socket . destroy ( ) ;
113
- this . _socket = null ;
114
- }
115
- }
116
111
}
117
112
118
113
$injector . register ( "iOSDevice" , IOSDevice ) ;
0 commit comments