1
+ import * as constants from "../../common/constants" ;
2
+
1
3
export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
2
4
constructor ( private $errors : IErrors ,
3
5
private $iOSNotification : IiOSNotification ,
@@ -6,18 +8,20 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
6
8
private $projectData : IProjectData ) { }
7
9
8
10
public async executeAttachRequest ( device : Mobile . IiOSDevice , timeout : number ) : Promise < void > {
11
+ const deviceIdentifier = device . deviceInfo . identifier ;
9
12
10
- let data = [ this . $iOSNotification . alreadyConnected , this . $iOSNotification . readyForAttach , this . $iOSNotification . attachAvailable ]
11
- . map ( ( notification ) => this . $iOSNotificationService . awaitNotification ( device . deviceInfo . identifier , notification , timeout ) ) ,
12
- alreadyConnected = data [ 0 ] ,
13
- readyForAttach = data [ 1 ] ,
14
- attachAvailable = data [ 2 ] ;
13
+ const observeNotificationPromises = [
14
+ await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . alreadyConnected , timeout ) ,
15
+ await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , timeout ) ,
16
+ await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . attachAvailable , timeout )
17
+ ] ;
15
18
16
- await this . $iOSNotificationService . postNotification ( device . deviceInfo . identifier , this . $iOSNotification . attachAvailabilityQuery ) ;
19
+ // Trigger the notifications update.
20
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachAvailabilityQuery , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
17
21
18
22
let receivedNotification : string ;
19
23
try {
20
- receivedNotification = await Promise . race ( [ alreadyConnected , readyForAttach , attachAvailable ] ) ;
24
+ receivedNotification = await Promise . race ( observeNotificationPromises ) ;
21
25
} catch ( e ) {
22
26
this . $errors . failWithoutHelp ( `The application ${ this . $projectData . projectId } does not appear to be running on ${ device . deviceInfo . displayName } or is not built with debugging enabled.` ) ;
23
27
}
@@ -27,7 +31,7 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
27
31
this . $errors . failWithoutHelp ( "A client is already connected." ) ;
28
32
break ;
29
33
case this . $iOSNotification . attachAvailable :
30
- await this . executeAttachAvailable ( device . deviceInfo . identifier , timeout ) ;
34
+ await this . executeAttachAvailable ( deviceIdentifier , timeout ) ;
31
35
break ;
32
36
case this . $iOSNotification . readyForAttach :
33
37
break ;
@@ -36,15 +40,16 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
36
40
37
41
public async executeLaunchRequest ( deviceIdentifier : string , timeout : number , readyForAttachTimeout : number , shouldBreak ?: boolean ) : Promise < void > {
38
42
try {
39
- await this . $iOSNotificationService . awaitNotification ( deviceIdentifier , this . $iOSNotification . appLaunching , timeout ) ;
43
+ const appLaunchingPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . appLaunching , timeout ) ;
44
+ await appLaunchingPromise ;
40
45
if ( shouldBreak ) {
41
- await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . waitForDebug ) ;
46
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . waitForDebug , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
42
47
}
43
48
44
49
// We need to send the ObserveNotification ReadyForAttach before we post the AttachRequest.
45
- const readyForAttachPromise = this . $iOSNotificationService . awaitNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , readyForAttachTimeout ) ;
50
+ const readyForAttachPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , readyForAttachTimeout ) ;
46
51
47
- await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachRequest ) ;
52
+ await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachRequest , constants . IOS_POST_NOTIFICATION_COMMAND_TYPE ) ;
48
53
await readyForAttachPromise ;
49
54
} catch ( e ) {
50
55
this . $logger . trace ( "Launch request error:" ) ;
@@ -57,7 +62,7 @@ export class IOSSocketRequestExecutor implements IiOSSocketRequestExecutor {
57
62
try {
58
63
// We should create this promise here because we need to send the ObserveNotification on the device
59
64
// before we send the PostNotification.
60
- const readyForAttachPromise = this . $iOSNotificationService . awaitNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , timeout ) ;
65
+ const readyForAttachPromise = await this . $iOSNotificationService . subscribeForNotification ( deviceIdentifier , this . $iOSNotification . readyForAttach , timeout ) ;
61
66
await this . $iOSNotificationService . postNotification ( deviceIdentifier , this . $iOSNotification . attachRequest ) ;
62
67
await readyForAttachPromise ;
63
68
} catch ( e ) {
0 commit comments