@@ -5,30 +5,28 @@ import * as constants from "../../../../constants";
55import * as net from "net" ;
66import { cache } from "../../../decorators" ;
77import * as helpers from "../../../../common/helpers" ;
8+ import { IOSDeviceBase } from "../ios-device-base" ;
89
9- export class IOSDevice implements Mobile . IiOSDevice {
10+ export class IOSDevice extends IOSDeviceBase {
1011 public applicationManager : Mobile . IDeviceApplicationManager ;
1112 public fileSystem : Mobile . IDeviceFileSystem ;
1213 public deviceInfo : Mobile . IDeviceInfo ;
13- private socket : net . Socket ;
14-
1514 private _deviceLogHandler : ( ...args : any [ ] ) => void ;
1615
1716 constructor ( private deviceActionInfo : IOSDeviceLib . IDeviceActionInfo ,
18- private $errors : IErrors ,
17+ protected $errors : IErrors ,
1918 private $injector : IInjector ,
20- private $iOSDebuggerPortService : IIOSDebuggerPortService ,
19+ protected $iOSDebuggerPortService : IIOSDebuggerPortService ,
2120 private $iOSSocketRequestExecutor : IiOSSocketRequestExecutor ,
22- private $processService : IProcessService ,
21+ protected $processService : IProcessService ,
2322 private $deviceLogProvider : Mobile . IDeviceLogProvider ,
2423 private $devicePlatformsConstants : Mobile . IDevicePlatformsConstants ,
2524 private $iOSDeviceProductNameMapper : Mobile . IiOSDeviceProductNameMapper ,
2625 private $iosDeviceOperations : IIOSDeviceOperations ,
2726 private $mobileHelper : Mobile . IMobileHelper ) {
28-
27+ super ( ) ;
2928 this . applicationManager = this . $injector . resolve ( applicationManagerPath . IOSApplicationManager , { device : this , devicePointer : this . deviceActionInfo } ) ;
3029 this . fileSystem = this . $injector . resolve ( fileSystemPath . IOSDeviceFileSystem , { device : this , devicePointer : this . deviceActionInfo } ) ;
31-
3230 const productType = deviceActionInfo . productType ;
3331 const isTablet = this . $mobileHelper . isiOSTablet ( productType ) ;
3432 const deviceStatus = deviceActionInfo . status || commonConstants . UNREACHABLE_STATUS ;
@@ -52,16 +50,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
5250 return false ;
5351 }
5452
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-
6553 @cache ( )
6654 public async openDeviceLogStream ( ) : Promise < void > {
6755 if ( this . deviceInfo . status !== commonConstants . UNREACHABLE_STATUS ) {
@@ -71,33 +59,11 @@ export class IOSDevice implements Mobile.IiOSDevice {
7159 }
7260 }
7361
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 > {
9363 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 ) ;
9965 const deviceId = this . deviceInfo . identifier ;
100- this . socket = await helpers . connectEventuallyUntilTimeout (
66+ const socket = await helpers . connectEventuallyUntilTimeout (
10167 async ( ) => {
10268 const deviceResponse = _ . first ( ( await this . $iosDeviceOperations . connectToPort ( [ { deviceId : deviceId , port : port } ] ) ) [ deviceId ] ) ;
10369 const _socket = new net . Socket ( ) ;
@@ -106,12 +72,19 @@ export class IOSDevice implements Mobile.IiOSDevice {
10672 } ,
10773 commonConstants . SOCKET_CONNECTION_TIMEOUT_MS ) ;
10874
109- this . socket . on ( "close" , ( ) => {
110- this . socket = null ;
111- } ) ;
75+ return socket ;
76+ }
11277
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+ }
11588 }
11689
11790 private getActiveArchitecture ( productType : string ) : string {
@@ -135,13 +108,6 @@ export class IOSDevice implements Mobile.IiOSDevice {
135108
136109 return activeArchitecture ;
137110 }
138-
139- private destroySocket ( ) {
140- if ( this . socket ) {
141- this . socket . destroy ( ) ;
142- this . socket = null ;
143- }
144- }
145111}
146112
147113$injector . register ( "iOSDevice" , IOSDevice ) ;
0 commit comments