appium-ios-remotexpc 5.17.0 → 5.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/src/lib/plist/plist-service.d.ts +2 -1
- package/build/src/lib/plist/plist-service.d.ts.map +1 -1
- package/build/src/lib/plist/plist-service.js +28 -17
- package/build/src/lib/plist/plist-service.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/plist/plist-service.ts +36 -18
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## [5.17.2](https://github.com/appium/appium-ios-remotexpc/compare/v5.17.1...v5.17.2) (2026-08-31)
|
|
2
|
+
|
|
3
|
+
### Performance Improvements
|
|
4
|
+
|
|
5
|
+
* **plist:** resolve receivers on decode instead of 50ms polling ([#311](https://github.com/appium/appium-ios-remotexpc/issues/311)) ([97f8ad2](https://github.com/appium/appium-ios-remotexpc/commit/97f8ad27129a90937e96fc8dccd4d06115a691db))
|
|
6
|
+
|
|
7
|
+
## [5.17.1](https://github.com/appium/appium-ios-remotexpc/compare/v5.17.0...v5.17.1) (2026-08-29)
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **deps:** require appium-ios-tuntap ^2.0.0 ([#308](https://github.com/appium/appium-ios-remotexpc/issues/308)) ([696f887](https://github.com/appium/appium-ios-remotexpc/commit/696f887438948587616ca6a35e1745792671eac8))
|
|
12
|
+
|
|
1
13
|
## [5.17.0](https://github.com/appium/appium-ios-remotexpc/compare/v5.16.3...v5.17.0) (2026-08-28)
|
|
2
14
|
|
|
3
15
|
### Features
|
|
@@ -38,6 +38,7 @@ export declare class PlistService {
|
|
|
38
38
|
private readonly _decoder;
|
|
39
39
|
private _encoder;
|
|
40
40
|
private _messageQueue;
|
|
41
|
+
private _waiters;
|
|
41
42
|
/**
|
|
42
43
|
* Creates a new PlistService instance
|
|
43
44
|
* @param socket The socket to use for communication
|
|
@@ -61,7 +62,7 @@ export declare class PlistService {
|
|
|
61
62
|
* Receive a plist message with timeout
|
|
62
63
|
* @param timeout Timeout in ms
|
|
63
64
|
* @returns Promise resolving to the received message
|
|
64
|
-
* @throws Error if timeout is reached before
|
|
65
|
+
* @throws Error if the timeout is reached, or if close() is called before a message arrives
|
|
65
66
|
*/
|
|
66
67
|
receivePlist(timeout?: number): Promise<PlistMessage>;
|
|
67
68
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plist-service.d.ts","sourceRoot":"","sources":["../../../../src/lib/plist/plist-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,MAAM,EAAC,MAAM,UAAU,CAAC;AACrC,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,UAAU,CAAC;AAGxC,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAYjD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,KAAK,YAAY,GAAG,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"plist-service.d.ts","sourceRoot":"","sources":["../../../../src/lib/plist/plist-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,MAAM,EAAC,MAAM,UAAU,CAAC;AACrC,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,UAAU,CAAC;AAGxC,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAYjD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,KAAK,YAAY,GAAG,eAAe,CAAC;AAQpC;;GAEG;AACH,qBAAa,YAAY;IACvB;;OAEG;IACH,MAAM,CAAC,yBAAyB,IAAI,IAAI;IAKxC;;OAEG;IACH,MAAM,CAAC,0BAA0B,IAAI,IAAI;IAIzC;;;OAGG;IACH,MAAM,CAAC,4BAA4B,IAAI,OAAO;IAI9C;;;OAGG;IACI,SAAS,IAAI,MAAM,GAAG,SAAS;IAGtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAqB;IAC7C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAsB;IAChD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAC/C,OAAO,CAAC,QAAQ,CAAsB;IACtC,OAAO,CAAC,aAAa,CAAiB;IACtC,OAAO,CAAC,QAAQ,CAAgB;IAEhC;;;;OAIG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,GAAE,mBAAwB;IA8B7D;;;;;OAKG;IACU,mBAAmB,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,SAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAK3F;;;;OAIG;IACI,SAAS,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAO1C;;;;;OAKG;IACU,YAAY,CAAC,OAAO,SAAO,GAAG,OAAO,CAAC,YAAY,CAAC;IAuBhE;;OAEG;IACI,KAAK,IAAI,IAAI;IAmCpB;;OAEG;IACH,OAAO,CAAC,aAAa;IAMrB;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAO1B;;;OAGG;IACH,OAAO,CAAC,WAAW;CAapB"}
|
|
@@ -43,6 +43,7 @@ export class PlistService {
|
|
|
43
43
|
_decoder;
|
|
44
44
|
_encoder;
|
|
45
45
|
_messageQueue;
|
|
46
|
+
_waiters;
|
|
46
47
|
/**
|
|
47
48
|
* Creates a new PlistService instance
|
|
48
49
|
* @param socket The socket to use for communication
|
|
@@ -60,7 +61,16 @@ export class PlistService {
|
|
|
60
61
|
this.setupPipeline();
|
|
61
62
|
// Message queue for async receiving
|
|
62
63
|
this._messageQueue = [];
|
|
63
|
-
this.
|
|
64
|
+
this._waiters = [];
|
|
65
|
+
this._decoder.on('data', (data) => {
|
|
66
|
+
const waiter = this._waiters.shift();
|
|
67
|
+
if (waiter) {
|
|
68
|
+
clearTimeout(waiter.timeoutId);
|
|
69
|
+
waiter.resolve(data);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
this._messageQueue.push(data);
|
|
73
|
+
});
|
|
64
74
|
// Handle errors
|
|
65
75
|
this.setupErrorHandlers();
|
|
66
76
|
}
|
|
@@ -89,29 +99,26 @@ export class PlistService {
|
|
|
89
99
|
* Receive a plist message with timeout
|
|
90
100
|
* @param timeout Timeout in ms
|
|
91
101
|
* @returns Promise resolving to the received message
|
|
92
|
-
* @throws Error if timeout is reached before
|
|
102
|
+
* @throws Error if the timeout is reached, or if close() is called before a message arrives
|
|
93
103
|
*/
|
|
94
104
|
async receivePlist(timeout = 5000) {
|
|
95
105
|
return new Promise((resolve, reject) => {
|
|
96
|
-
// Check if we already have a message
|
|
97
106
|
const message = this._messageQueue.shift();
|
|
98
107
|
if (message) {
|
|
99
108
|
return resolve(message);
|
|
100
109
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
reject(new Error(`Timed out waiting for plist response after ${timeout}ms`));
|
|
114
|
-
}, timeout);
|
|
110
|
+
const waiter = {
|
|
111
|
+
resolve,
|
|
112
|
+
reject,
|
|
113
|
+
timeoutId: setTimeout(() => {
|
|
114
|
+
const index = this._waiters.indexOf(waiter);
|
|
115
|
+
if (index !== -1) {
|
|
116
|
+
this._waiters.splice(index, 1);
|
|
117
|
+
}
|
|
118
|
+
reject(new Error(`Timed out waiting for plist response after ${timeout}ms`));
|
|
119
|
+
}, timeout),
|
|
120
|
+
};
|
|
121
|
+
this._waiters.push(waiter);
|
|
115
122
|
});
|
|
116
123
|
}
|
|
117
124
|
/**
|
|
@@ -124,6 +131,10 @@ export class PlistService {
|
|
|
124
131
|
this._decoder.removeAllListeners();
|
|
125
132
|
// Clear the message queue to prevent processing during close
|
|
126
133
|
this._messageQueue = [];
|
|
134
|
+
for (const waiter of this._waiters.splice(0)) {
|
|
135
|
+
clearTimeout(waiter.timeoutId);
|
|
136
|
+
waiter.reject(new Error('Connection closed while waiting for plist response'));
|
|
137
|
+
}
|
|
127
138
|
// Unpipe the transformers to prevent data flow during close
|
|
128
139
|
try {
|
|
129
140
|
this._socket.unpipe(this._splitter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plist-service.js","sourceRoot":"","sources":["../../../../src/lib/plist/plist-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAEzC,MAAM,MAAM,GAAG;IACb,mBAAmB,EAAE,KAAK;CAC3B,CAAC;
|
|
1
|
+
{"version":3,"file":"plist-service.js","sourceRoot":"","sources":["../../../../src/lib/plist/plist-service.ts"],"names":[],"mappings":"AAGA,OAAO,EAAC,SAAS,EAAC,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAC,mBAAmB,EAAC,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAC,mBAAmB,EAAC,MAAM,oBAAoB,CAAC;AAEvD,MAAM,GAAG,GAAG,SAAS,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,QAAQ,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;AAEzC,MAAM,MAAM,GAAG;IACb,mBAAmB,EAAE,KAAK;CAC3B,CAAC;AAoBF;;GAEG;AACH,MAAM,OAAO,YAAY;IACvB;;OAEG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AC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC;YACnF,QAAQ,CAAC,KAAK,CAAC,yDAAyD,CAAC,CAAC;QAC5E,CAAC;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "appium-ios-remotexpc",
|
|
3
|
-
"version": "5.17.
|
|
3
|
+
"version": "5.17.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"bugs": {
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"@appium/strongbox": "^1.1.2",
|
|
94
94
|
"@appium/support": "^7.2.2",
|
|
95
95
|
"@xmldom/xmldom": "^0.x",
|
|
96
|
-
"appium-ios-tuntap": "^
|
|
96
|
+
"appium-ios-tuntap": "^2.0.0",
|
|
97
97
|
"async-lock": "^1.4.1",
|
|
98
98
|
"axios": "^1.15.1",
|
|
99
99
|
"commander": "^14.0.1",
|
|
@@ -26,6 +26,12 @@ export interface PlistServiceOptions {
|
|
|
26
26
|
*/
|
|
27
27
|
type PlistMessage = PlistDictionary;
|
|
28
28
|
|
|
29
|
+
interface PlistWaiter {
|
|
30
|
+
resolve: (message: PlistMessage) => void;
|
|
31
|
+
reject: (error: Error) => void;
|
|
32
|
+
timeoutId: NodeJS.Timeout;
|
|
33
|
+
}
|
|
34
|
+
|
|
29
35
|
/**
|
|
30
36
|
* Service for communication using plist protocol
|
|
31
37
|
*/
|
|
@@ -65,6 +71,7 @@ export class PlistService {
|
|
|
65
71
|
private readonly _decoder: PlistServiceDecoder;
|
|
66
72
|
private _encoder: PlistServiceEncoder;
|
|
67
73
|
private _messageQueue: PlistMessage[];
|
|
74
|
+
private _waiters: PlistWaiter[];
|
|
68
75
|
|
|
69
76
|
/**
|
|
70
77
|
* Creates a new PlistService instance
|
|
@@ -86,7 +93,16 @@ export class PlistService {
|
|
|
86
93
|
|
|
87
94
|
// Message queue for async receiving
|
|
88
95
|
this._messageQueue = [];
|
|
89
|
-
this.
|
|
96
|
+
this._waiters = [];
|
|
97
|
+
this._decoder.on('data', (data: PlistMessage) => {
|
|
98
|
+
const waiter = this._waiters.shift();
|
|
99
|
+
if (waiter) {
|
|
100
|
+
clearTimeout(waiter.timeoutId);
|
|
101
|
+
waiter.resolve(data);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this._messageQueue.push(data);
|
|
105
|
+
});
|
|
90
106
|
|
|
91
107
|
// Handle errors
|
|
92
108
|
this.setupErrorHandlers();
|
|
@@ -119,31 +135,28 @@ export class PlistService {
|
|
|
119
135
|
* Receive a plist message with timeout
|
|
120
136
|
* @param timeout Timeout in ms
|
|
121
137
|
* @returns Promise resolving to the received message
|
|
122
|
-
* @throws Error if timeout is reached before
|
|
138
|
+
* @throws Error if the timeout is reached, or if close() is called before a message arrives
|
|
123
139
|
*/
|
|
124
140
|
public async receivePlist(timeout = 5000): Promise<PlistMessage> {
|
|
125
141
|
return new Promise<PlistMessage>((resolve, reject) => {
|
|
126
|
-
// Check if we already have a message
|
|
127
142
|
const message = this._messageQueue.shift();
|
|
128
143
|
if (message) {
|
|
129
144
|
return resolve(message);
|
|
130
145
|
}
|
|
131
146
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
reject(new Error(`Timed out waiting for plist response after ${timeout}ms`));
|
|
146
|
-
}, timeout);
|
|
147
|
+
const waiter: PlistWaiter = {
|
|
148
|
+
resolve,
|
|
149
|
+
reject,
|
|
150
|
+
timeoutId: setTimeout(() => {
|
|
151
|
+
const index = this._waiters.indexOf(waiter);
|
|
152
|
+
if (index !== -1) {
|
|
153
|
+
this._waiters.splice(index, 1);
|
|
154
|
+
}
|
|
155
|
+
reject(new Error(`Timed out waiting for plist response after ${timeout}ms`));
|
|
156
|
+
}, timeout),
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
this._waiters.push(waiter);
|
|
147
160
|
});
|
|
148
161
|
}
|
|
149
162
|
|
|
@@ -159,6 +172,11 @@ export class PlistService {
|
|
|
159
172
|
// Clear the message queue to prevent processing during close
|
|
160
173
|
this._messageQueue = [];
|
|
161
174
|
|
|
175
|
+
for (const waiter of this._waiters.splice(0)) {
|
|
176
|
+
clearTimeout(waiter.timeoutId);
|
|
177
|
+
waiter.reject(new Error('Connection closed while waiting for plist response'));
|
|
178
|
+
}
|
|
179
|
+
|
|
162
180
|
// Unpipe the transformers to prevent data flow during close
|
|
163
181
|
try {
|
|
164
182
|
this._socket.unpipe(this._splitter);
|