@@ -5,30 +5,28 @@ import * as constants from "../../../../constants";
5
5
import * as net from "net" ;
6
6
import { cache } from "../../../decorators" ;
7
7
import * as helpers from "../../../../common/helpers" ;
8
+ import { IOSDeviceBase } from "../ios-device-base" ;
8
9
9
- export class IOSDevice implements Mobile . IiOSDevice {
10
+ export class IOSDevice extends IOSDeviceBase {
10
11
public applicationManager : Mobile . IDeviceApplicationManager ;
11
12
public fileSystem : Mobile . IDeviceFileSystem ;
12
13
public deviceInfo : Mobile . IDeviceInfo ;
13
- private socket : net . Socket ;
14
-
15
14
private _deviceLogHandler : ( ...args : any [ ] ) => void ;
16
15
17
16
constructor ( private deviceActionInfo : IOSDeviceLib . IDeviceActionInfo ,
18
- private $errors : IErrors ,
17
+ protected $errors : IErrors ,
19
18
private $injector : IInjector ,
20
- private $iOSDebuggerPortService : IIOSDebuggerPortService ,
19
+ protected $iOSDebuggerPortService : IIOSDebuggerPortService ,
21
20
private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
22
- private $processService : IProcessService ,
21
+ protected $processService : IProcessService ,
23
22
private $deviceLogProvider : Mobile . IDeviceLogProvider ,
24
23
private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
25
24
private $iOSDeviceProductNameMapper : Mobile . IiOSDeviceProductNameMapper ,
26
25
private $iosDeviceOperations : IIOSDeviceOperations ,
27
26
private $mobileHelper : Mobile . IMobileHelper ) {
28
-
27
+ super ( ) ;
29
28
this . applicationManager = this . $injector . resolve ( applicationManagerPath . IOSApplicationManager , { device : this , devicePointer : this . deviceActionInfo } ) ;
30
29
this . fileSystem = this . $injector . resolve ( fileSystemPath . IOSDeviceFileSystem , { device : this , devicePointer : this . deviceActionInfo } ) ;
31
-
32
30
const productType = deviceActionInfo . productType ;
33
31
const isTablet = this . $mobileHelper . isiOSTablet ( productType ) ;
34
32
const deviceStatus = deviceActionInfo . status || commonConstants . UNREACHABLE_STATUS ;
@@ -52,16 +50,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
52
50
return false ;
53
51
}
54
52
55
- public getApplicationInfo ( applicationIdentifier : string ) : Promise < Mobile . IApplicationInfo > {
56
- return this . applicationManager . getApplicationInfo ( applicationIdentifier ) ;
57
- }
58
-
59
- private actionOnDeviceLog ( response : IOSDeviceLib . IDeviceLogData ) : void {
60
- if ( response . deviceId === this . deviceInfo . identifier ) {
61
- this . $deviceLogProvider . logData ( response . message , this . $devicePlatformsConstants . iOS , this . deviceInfo . identifier ) ;
62
- }
63
- }
64
-
65
53
@cache ( )
66
54
public async openDeviceLogStream ( ) : Promise < void > {
67
55
if ( this . deviceInfo . status !== commonConstants . UNREACHABLE_STATUS ) {
@@ -71,33 +59,11 @@ export class IOSDevice implements Mobile.IiOSDevice {
71
59
}
72
60
}
73
61
74
- public detach ( ) : void {
75
- if ( this . _deviceLogHandler ) {
76
- this . $iosDeviceOperations . removeListener ( commonConstants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
77
- }
78
- }
79
-
80
- public async getLiveSyncSocket ( appId : string , projectDir : string ) : Promise < net . Socket > {
81
- return this . getSocket ( appId , projectDir ) ;
82
- }
83
-
84
- public async getDebugSocket ( appId : string , projectDir : string ) : Promise < net . Socket > {
85
- return this . getSocket ( appId , projectDir ) ;
86
- }
87
-
88
- private async getSocket ( appId : string , projectDir : string ) : Promise < net . Socket > {
89
- if ( this . socket ) {
90
- return this . socket ;
91
- }
92
-
62
+ protected async getSocketCore ( appId : string ) : Promise < net . Socket > {
93
63
await this . $iOSSocketRequestExecutor . executeAttachRequest ( this , constants . AWAIT_NOTIFICATION_TIMEOUT_SECONDS , appId ) ;
94
- const port = await this . $iOSDebuggerPortService . getPort ( { projectDir, deviceId : this . deviceInfo . identifier , appId } ) ;
95
- if ( ! port ) {
96
- this . $errors . failWithoutHelp ( "Device socket port cannot be found." ) ;
97
- }
98
-
64
+ const port = await this . getDebuggerPort ( appId ) ;
99
65
const deviceId = this . deviceInfo . identifier ;
100
- this . socket = await helpers . connectEventuallyUntilTimeout (
66
+ const socket = await helpers . connectEventuallyUntilTimeout (
101
67
async ( ) => {
102
68
const deviceResponse = _ . first ( ( await this . $iosDeviceOperations . connectToPort ( [ { deviceId : deviceId , port : port } ] ) ) [ deviceId ] ) ;
103
69
const _socket = new net . Socket ( ) ;
@@ -106,12 +72,19 @@ export class IOSDevice implements Mobile.IiOSDevice {
106
72
} ,
107
73
commonConstants . SOCKET_CONNECTION_TIMEOUT_MS ) ;
108
74
109
- this . socket . on ( "close" , ( ) => {
110
- this . socket = null ;
111
- } ) ;
75
+ return socket ;
76
+ }
112
77
113
- this . $processService . attachToProcessExitSignals ( this , this . destroySocket ) ;
114
- return this . socket ;
78
+ private actionOnDeviceLog ( response : IOSDeviceLib . IDeviceLogData ) : void {
79
+ if ( response . deviceId === this . deviceInfo . identifier ) {
80
+ this . $deviceLogProvider . logData ( response . message , this . $devicePlatformsConstants . iOS , this . deviceInfo . identifier ) ;
81
+ }
82
+ }
83
+
84
+ public detach ( ) : void {
85
+ if ( this . _deviceLogHandler ) {
86
+ this . $iosDeviceOperations . removeListener ( commonConstants . DEVICE_LOG_EVENT_NAME , this . _deviceLogHandler ) ;
87
+ }
115
88
}
116
89
117
90
private getActiveArchitecture ( productType : string ) : string {
@@ -135,13 +108,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
135
108
136
109
return activeArchitecture ;
137
110
}
138
-
139
- private destroySocket ( ) {
140
- if ( this . socket ) {
141
- this . socket . destroy ( ) ;
142
- this . socket = null ;
143
- }
144
- }
145
111
}
146
112
147
113
$injector . register ( "iOSDevice" , IOSDevice ) ;
0 commit comments