@@ -4,19 +4,27 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
4
4
constructor ( private $errors : IErrors ,
5
5
private $iOSNotification : IiOSNotification ,
6
6
private $iOSNotificationService : IiOSNotificationService ,
7
- private $logger : ILogger ) { }
7
+ private $logger : ILogger ,
8
+ private $projectData : IProjectData ,
9
+ private $iosDeviceOperations : IIOSDeviceOperations ) {
10
+ this . $iosDeviceOperations . setShouldDispose ( false ) ;
11
+ }
8
12
9
13
public async executeAttachRequest ( device : Mobile . IiOSDevice , timeout : number , projectId : string ) : Promise < void > {
10
14
const deviceIdentifier = device . deviceInfo . identifier ;
11
15
12
- const observeNotificationPromises = [
13
- await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getAlreadyConnected ( projectId ) , timeout ) ,
14
- await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getReadyForAttach ( projectId ) , timeout ) ,
15
- await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getAttachAvailable ( projectId ) , timeout )
16
+ const observeNotificationSockets = [
17
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . alreadyConnected , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE ) ,
18
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE ) ,
19
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachAvailable , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE )
16
20
] ;
17
21
22
+ const observeNotificationPromises = _ . map ( observeNotificationSockets , s => {
23
+ return this . $iOSNotificationService . awaitNotification ( deviceIdentifier , + s , timeout ) ;
24
+ } ) ;
25
+
18
26
// Trigger the notifications update.
19
- await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . getAttachAvailabilityQuery ( projectId ) , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
27
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachAvailabilityQuery ) ;
20
28
21
29
let receivedNotification : string ;
22
30
try {
@@ -43,16 +51,18 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
43
51
44
52
public async executeLaunchRequest ( deviceIdentifier : string , timeout : number , readyForAttachTimeout : number , projectId : string , shouldBreak ?: boolean ) : Promise < void > {
45
53
try {
46
- const appLaunchingPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getAppLaunching ( projectId ) , timeout ) ;
47
- await appLaunchingPromise ;
54
+ const appLaunchingSocket = await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . appLaunching , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE ) ;
55
+ await this . $iOSNotificationService . awaitNotification ( deviceIdentifier , + appLaunchingSocket , timeout ) ;
56
+
48
57
if ( shouldBreak ) {
49
58
await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . getWaitForDebug ( projectId ) , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
50
59
}
51
60
52
61
// We need to send the ObserveNotification ReadyForAttach before we post the AttachRequest.
53
- const readyForAttachPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getReadyForAttach ( projectId ) , readyForAttachTimeout ) ;
62
+ const readyForAttachSocket = await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE ) ;
63
+ const readyForAttachPromise = this . $iOSNotificationService . awaitNotification ( deviceIdentifier , + readyForAttachSocket , readyForAttachTimeout ) ;
54
64
55
- await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . getAttachRequest ( projectId ) , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
65
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachRequest ) ;
56
66
await readyForAttachPromise ;
57
67
} catch ( e ) {
58
68
this . $logger . trace ( "Launch request error:" ) ;
@@ -65,8 +75,9 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
65
75
try {
66
76
// We should create this promise here because we need to send the ObserveNotification on the device
67
77
// before we send the PostNotification.
68
- const readyForAttachPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . getReadyForAttach ( projectId ) , timeout ) ;
69
- await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . getAttachRequest ( projectId ) ) ;
78
+ const readyForAttachSocket = await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , constants . IOS_OBSERVE_NOTIFICATION_COMMAND_TYPE ) ;
79
+ const readyForAttachPromise = this . $iOSNotificationService . awaitNotification ( deviceIdentifier , + readyForAttachSocket , timeout ) ;
80
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachRequest ) ;
70
81
await readyForAttachPromise ;
71
82
} catch ( e ) {
72
83
this . $errors . failWithoutHelp ( `The application ${ projectId } timed out when performing the socket handshake.` ) ;
0 commit comments