@limrun/api 0.79.0 → 0.79.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 +26 -0
- package/destination-tunnel-dialer.d.mts.map +1 -1
- package/destination-tunnel-dialer.d.ts.map +1 -1
- package/destination-tunnel-dialer.js +23 -14
- package/destination-tunnel-dialer.js.map +1 -1
- package/destination-tunnel-dialer.mjs +23 -14
- package/destination-tunnel-dialer.mjs.map +1 -1
- package/internal/app-log-events.d.mts +21 -0
- package/internal/app-log-events.d.mts.map +1 -0
- package/internal/app-log-events.d.ts +21 -0
- package/internal/app-log-events.d.ts.map +1 -0
- package/internal/app-log-events.js +73 -0
- package/internal/app-log-events.js.map +1 -0
- package/internal/app-log-events.mjs +69 -0
- package/internal/app-log-events.mjs.map +1 -0
- package/internal/signaling-transport.d.mts +79 -0
- package/internal/signaling-transport.d.mts.map +1 -0
- package/internal/signaling-transport.d.ts +79 -0
- package/internal/signaling-transport.d.ts.map +1 -0
- package/internal/signaling-transport.js +320 -0
- package/internal/signaling-transport.js.map +1 -0
- package/internal/signaling-transport.mjs +316 -0
- package/internal/signaling-transport.mjs.map +1 -0
- package/ios-client.d.mts +4 -9
- package/ios-client.d.mts.map +1 -1
- package/ios-client.d.ts +4 -9
- package/ios-client.d.ts.map +1 -1
- package/ios-client.js +172 -412
- package/ios-client.js.map +1 -1
- package/ios-client.mjs +173 -413
- package/ios-client.mjs.map +1 -1
- package/log-stream.d.mts +11 -4
- package/log-stream.d.mts.map +1 -1
- package/log-stream.d.ts +11 -4
- package/log-stream.d.ts.map +1 -1
- package/log-stream.js +45 -8
- package/log-stream.js.map +1 -1
- package/log-stream.mjs +45 -8
- package/log-stream.mjs.map +1 -1
- package/package.json +1 -1
- package/resources/macos-instances-helpers.d.mts +12 -0
- package/resources/macos-instances-helpers.d.mts.map +1 -1
- package/resources/macos-instances-helpers.d.ts +12 -0
- package/resources/macos-instances-helpers.d.ts.map +1 -1
- package/resources/macos-instances-helpers.js +118 -141
- package/resources/macos-instances-helpers.js.map +1 -1
- package/resources/macos-instances-helpers.mjs +118 -141
- package/resources/macos-instances-helpers.mjs.map +1 -1
- package/src/destination-tunnel-dialer.ts +23 -14
- package/src/internal/app-log-events.ts +76 -0
- package/src/internal/signaling-transport.ts +454 -0
- package/src/ios-client.ts +193 -471
- package/src/log-stream.ts +54 -11
- package/src/resources/macos-instances-helpers.ts +153 -136
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/ios-client.js
CHANGED
|
@@ -11,7 +11,6 @@ const os_1 = tslib_1.__importDefault(require("os"));
|
|
|
11
11
|
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
12
12
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
13
13
|
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
14
|
-
const ws_1 = require("ws");
|
|
15
14
|
const events_1 = require("events");
|
|
16
15
|
const tunnel_1 = require("./tunnel.js");
|
|
17
16
|
const destination_tunnel_dialer_1 = require("./destination-tunnel-dialer.js");
|
|
@@ -31,6 +30,7 @@ const target_http_port_1 = require("./target-http-port.js");
|
|
|
31
30
|
const persist_option_1 = require("./internal/persist-option.js");
|
|
32
31
|
const session_stream_1 = require("./internal/session-stream.js");
|
|
33
32
|
const log_stream_1 = require("./log-stream.js");
|
|
33
|
+
const signaling_transport_1 = require("./internal/signaling-transport.js");
|
|
34
34
|
var log_stream_2 = require("./log-stream.js");
|
|
35
35
|
Object.defineProperty(exports, "LogStream", { enumerable: true, get: function () { return log_stream_2.LogStream; } });
|
|
36
36
|
const ACTIVE_RECORDING_FILENAME = 'recording.mp4';
|
|
@@ -320,28 +320,14 @@ function streamPerformance(options) {
|
|
|
320
320
|
* @returns An InstanceClient for controlling the instance
|
|
321
321
|
*/
|
|
322
322
|
async function createInstanceClient(options) {
|
|
323
|
-
const endpointWebSocketUrl = `${options.apiUrl
|
|
324
|
-
.replace('https://', 'wss://')
|
|
325
|
-
.replace('http://', 'ws://')}/signaling?token=${options.token}`;
|
|
326
323
|
const logLevel = options.logLevel ?? 'info';
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
const maxReconnectDelay = options.maxReconnectDelay ?? 30000;
|
|
330
|
-
let ws = undefined;
|
|
331
|
-
let connectionState = 'connecting';
|
|
332
|
-
let reconnectAttempts = 0;
|
|
333
|
-
let reconnectTimeout;
|
|
334
|
-
let handshakeDeadline;
|
|
335
|
-
let intentionalDisconnect = false;
|
|
336
|
-
let lastError;
|
|
337
|
-
// Centralized pending requests map - handles all request/response patterns
|
|
338
|
-
const pendingRequests = new Map();
|
|
324
|
+
// Set once the signaling socket opens, before any method can run.
|
|
325
|
+
let transport;
|
|
339
326
|
// Simctl uses streaming, so it needs separate handling
|
|
340
327
|
const simctlExecutions = new Map();
|
|
341
328
|
const serverNotifications = new Map();
|
|
342
329
|
const xcrunShimCleanups = [];
|
|
343
330
|
const httpProxyCleanups = [];
|
|
344
|
-
const stateChangeCallbacks = new Set();
|
|
345
331
|
// Logger functions
|
|
346
332
|
const logger = {
|
|
347
333
|
debug: (...args) => {
|
|
@@ -361,49 +347,10 @@ async function createInstanceClient(options) {
|
|
|
361
347
|
console.error(...args);
|
|
362
348
|
},
|
|
363
349
|
};
|
|
364
|
-
const
|
|
365
|
-
if (connectionState !== newState) {
|
|
366
|
-
connectionState = newState;
|
|
367
|
-
logger.debug(`Connection state changed to: ${newState}`);
|
|
368
|
-
stateChangeCallbacks.forEach((callback) => {
|
|
369
|
-
try {
|
|
370
|
-
callback(newState);
|
|
371
|
-
}
|
|
372
|
-
catch (err) {
|
|
373
|
-
logger.error('Error in connection state callback:', err);
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
};
|
|
378
|
-
const failPendingRequests = (reason) => {
|
|
379
|
-
pendingRequests.forEach((request) => {
|
|
380
|
-
clearTimeout(request.timeout);
|
|
381
|
-
request.reject(new Error(reason));
|
|
382
|
-
});
|
|
383
|
-
pendingRequests.clear();
|
|
350
|
+
const failExecutions = (reason) => {
|
|
384
351
|
simctlExecutions.forEach((execution) => execution._handleError(new Error(reason)));
|
|
385
352
|
simctlExecutions.clear();
|
|
386
353
|
};
|
|
387
|
-
const cleanupConnection = () => {
|
|
388
|
-
clearTimeout(handshakeDeadline);
|
|
389
|
-
if (reconnectTimeout) {
|
|
390
|
-
clearTimeout(reconnectTimeout);
|
|
391
|
-
reconnectTimeout = undefined;
|
|
392
|
-
}
|
|
393
|
-
if (pingInterval) {
|
|
394
|
-
clearInterval(pingInterval);
|
|
395
|
-
pingInterval = undefined;
|
|
396
|
-
}
|
|
397
|
-
if (ws) {
|
|
398
|
-
ws.removeAllListeners();
|
|
399
|
-
// A retired socket can emit an error when an unfinished handshake is cancelled.
|
|
400
|
-
ws.on('error', () => { });
|
|
401
|
-
if (ws.readyState === ws_1.WebSocket.OPEN || ws.readyState === ws_1.WebSocket.CONNECTING) {
|
|
402
|
-
ws.close();
|
|
403
|
-
}
|
|
404
|
-
ws = undefined;
|
|
405
|
-
}
|
|
406
|
-
};
|
|
407
354
|
const cleanupClientResources = () => {
|
|
408
355
|
const shimCleanups = xcrunShimCleanups.splice(0);
|
|
409
356
|
for (const closeShim of shimCleanups) {
|
|
@@ -414,10 +361,6 @@ async function createInstanceClient(options) {
|
|
|
414
361
|
closeProxy().catch((error) => logger.warn('Failed to close HTTP proxy:', error));
|
|
415
362
|
}
|
|
416
363
|
};
|
|
417
|
-
const cleanup = () => {
|
|
418
|
-
cleanupConnection();
|
|
419
|
-
cleanupClientResources();
|
|
420
|
-
};
|
|
421
364
|
const registerServerNotification = (type, notificationId, handler) => {
|
|
422
365
|
const handlers = serverNotifications.get(type) ?? new Map();
|
|
423
366
|
handlers.set(notificationId, handler);
|
|
@@ -452,38 +395,7 @@ async function createInstanceClient(options) {
|
|
|
452
395
|
const clearServerNotifications = () => {
|
|
453
396
|
serverNotifications.clear();
|
|
454
397
|
};
|
|
455
|
-
|
|
456
|
-
const keepAliveSessionId = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
|
|
457
|
-
return new Promise((resolveConnection, rejectConnection) => {
|
|
458
|
-
let hasResolved = false;
|
|
459
|
-
let retriedHandshake = false;
|
|
460
|
-
// Reconnection logic with exponential backoff
|
|
461
|
-
const scheduleReconnect = () => {
|
|
462
|
-
if (intentionalDisconnect) {
|
|
463
|
-
logger.debug('Skipping reconnection (intentional disconnect)');
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
if ((0, tunnel_1.isNonRetryableError)(lastError ?? '')) {
|
|
467
|
-
logger.error(`Skipping reconnection (non-retryable error): ${lastError}`);
|
|
468
|
-
updateConnectionState('disconnected');
|
|
469
|
-
clearServerNotifications();
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
if (reconnectAttempts >= maxReconnectAttempts) {
|
|
473
|
-
logger.error(`Max reconnection attempts (${maxReconnectAttempts}) reached. Giving up.`);
|
|
474
|
-
updateConnectionState('disconnected');
|
|
475
|
-
clearServerNotifications();
|
|
476
|
-
return;
|
|
477
|
-
}
|
|
478
|
-
const currentDelay = Math.min(reconnectDelay * Math.pow(2, reconnectAttempts), maxReconnectDelay);
|
|
479
|
-
reconnectAttempts++;
|
|
480
|
-
logger.debug(`Scheduling reconnection attempt ${reconnectAttempts} in ${currentDelay}ms...`);
|
|
481
|
-
updateConnectionState('reconnecting');
|
|
482
|
-
reconnectTimeout = setTimeout(() => {
|
|
483
|
-
logger.debug(`Attempting to reconnect (attempt ${reconnectAttempts})...`);
|
|
484
|
-
setupWebSocket();
|
|
485
|
-
}, currentDelay);
|
|
486
|
-
};
|
|
398
|
+
{
|
|
487
399
|
// Generate unique request ID
|
|
488
400
|
const generateId = () => {
|
|
489
401
|
return `ts-client-${Date.now()}-${Math.random().toString(36).substring(7)}`;
|
|
@@ -508,31 +420,7 @@ async function createInstanceClient(options) {
|
|
|
508
420
|
const source = failedAction ?? message;
|
|
509
421
|
return new CommandError(message.error, source.code, source.written);
|
|
510
422
|
};
|
|
511
|
-
|
|
512
|
-
const sendRequest = (type, params = {}, transform, timeoutMs = 30000) => {
|
|
513
|
-
return new Promise((resolve, reject) => {
|
|
514
|
-
if (!ws || ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
515
|
-
reject(new Error('WebSocket is not connected or connection is not open.'));
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
518
|
-
const id = generateId();
|
|
519
|
-
const timeout = setTimeout(() => {
|
|
520
|
-
pendingRequests.delete(id);
|
|
521
|
-
reject(new Error(`Request ${type} timed out`));
|
|
522
|
-
}, timeoutMs);
|
|
523
|
-
pendingRequests.set(id, transform ? { resolve, reject, timeout, transform } : { resolve, reject, timeout });
|
|
524
|
-
const request = { type, id, ...params };
|
|
525
|
-
logger.debug('Sending request:', redactRequestForDebug(request));
|
|
526
|
-
ws.send(JSON.stringify(request), (err) => {
|
|
527
|
-
if (err) {
|
|
528
|
-
clearTimeout(timeout);
|
|
529
|
-
pendingRequests.delete(id);
|
|
530
|
-
logger.error(`Failed to send ${type} request:`, err);
|
|
531
|
-
reject(err);
|
|
532
|
-
}
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
};
|
|
423
|
+
const sendRequest = (type, params = {}, transform, timeoutMs = 30000) => transport.request(type, params, transform, timeoutMs);
|
|
536
424
|
const splitAppLogTail = (logs) => {
|
|
537
425
|
if (logs.length === 0) {
|
|
538
426
|
return [];
|
|
@@ -663,259 +551,6 @@ async function createInstanceClient(options) {
|
|
|
663
551
|
exitCode: msg.exitCode ?? -1,
|
|
664
552
|
}),
|
|
665
553
|
};
|
|
666
|
-
const setupWebSocket = () => {
|
|
667
|
-
cleanupConnection();
|
|
668
|
-
updateConnectionState('connecting');
|
|
669
|
-
const proxyAgent = proxy_transport_1.nodeProxyTransport.getWebSocketAgent(endpointWebSocketUrl);
|
|
670
|
-
let opened = false;
|
|
671
|
-
let handshakeError;
|
|
672
|
-
const socket = new ws_1.WebSocket(endpointWebSocketUrl, proxyAgent ? { agent: proxyAgent } : {});
|
|
673
|
-
ws = socket;
|
|
674
|
-
// A socket inactivity timeout allows a slow TLS peer to keep the first command waiting.
|
|
675
|
-
handshakeDeadline = setTimeout(() => {
|
|
676
|
-
handshakeError = Object.assign(new Error('Opening handshake has timed out'), { code: 'ETIMEDOUT' });
|
|
677
|
-
socket.terminate();
|
|
678
|
-
}, 5000);
|
|
679
|
-
ws.on('message', (data) => {
|
|
680
|
-
let message;
|
|
681
|
-
try {
|
|
682
|
-
message = JSON.parse(data.toString());
|
|
683
|
-
}
|
|
684
|
-
catch (e) {
|
|
685
|
-
logger.error({ data, error: e }, 'Failed to parse JSON message');
|
|
686
|
-
return;
|
|
687
|
-
}
|
|
688
|
-
if (handleAppExit(message) || handleAppHang(message)) {
|
|
689
|
-
return;
|
|
690
|
-
}
|
|
691
|
-
// Handle simctl streaming separately (it uses multiple messages per request)
|
|
692
|
-
if (message.type === 'simctlStream') {
|
|
693
|
-
const execution = simctlExecutions.get(message.id);
|
|
694
|
-
if (!execution) {
|
|
695
|
-
logger.debug(`Received simctl stream for unknown execution: ${message.id}`);
|
|
696
|
-
return;
|
|
697
|
-
}
|
|
698
|
-
if (execution instanceof LldbExecution) {
|
|
699
|
-
execution._handleStarted();
|
|
700
|
-
}
|
|
701
|
-
if (message.stdout) {
|
|
702
|
-
try {
|
|
703
|
-
execution._handleStdout(Buffer.from(message.stdout, 'base64'));
|
|
704
|
-
}
|
|
705
|
-
catch (err) {
|
|
706
|
-
logger.error('Failed to decode stdout data:', err);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
if (message.stderr) {
|
|
710
|
-
try {
|
|
711
|
-
execution._handleStderr(Buffer.from(message.stderr, 'base64'));
|
|
712
|
-
}
|
|
713
|
-
catch (err) {
|
|
714
|
-
logger.error('Failed to decode stderr data:', err);
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
|
-
if (message.exitCode !== undefined) {
|
|
718
|
-
logger.debug(`Simctl execution ${message.id} completed with exit code ${message.exitCode}`);
|
|
719
|
-
// Forget the execution first: an exit listener may disconnect, and disconnecting
|
|
720
|
-
// fails every execution still tracked, including this one.
|
|
721
|
-
simctlExecutions.delete(message.id);
|
|
722
|
-
execution._handleExit(message.exitCode);
|
|
723
|
-
}
|
|
724
|
-
return;
|
|
725
|
-
}
|
|
726
|
-
// Handle all other request/response patterns generically
|
|
727
|
-
const request = pendingRequests.get(message.id);
|
|
728
|
-
if (!request) {
|
|
729
|
-
logger.debug(`Received response for unknown or already handled request: ${message.id}`);
|
|
730
|
-
return;
|
|
731
|
-
}
|
|
732
|
-
clearTimeout(request.timeout);
|
|
733
|
-
pendingRequests.delete(message.id);
|
|
734
|
-
if (message.error) {
|
|
735
|
-
logger.debug(`Server error for ${message.type}: ${message.error}`);
|
|
736
|
-
request.reject(commandError(message));
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
// Use handler to transform response, or resolve with raw message
|
|
740
|
-
const handler = request.transform ?? responseHandlers[message.type];
|
|
741
|
-
if (handler) {
|
|
742
|
-
try {
|
|
743
|
-
request.resolve(handler(message));
|
|
744
|
-
}
|
|
745
|
-
catch (err) {
|
|
746
|
-
request.reject(err);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
logger.warn('Received unexpected message type:', message.type);
|
|
751
|
-
request.resolve(message);
|
|
752
|
-
}
|
|
753
|
-
});
|
|
754
|
-
ws.on('error', (err) => {
|
|
755
|
-
lastError = err.message;
|
|
756
|
-
logger.error('WebSocket error:', err.message);
|
|
757
|
-
if (!opened)
|
|
758
|
-
handshakeError ?? (handshakeError = err);
|
|
759
|
-
});
|
|
760
|
-
ws.on('close', () => {
|
|
761
|
-
clearTimeout(handshakeDeadline);
|
|
762
|
-
if (pingInterval) {
|
|
763
|
-
clearInterval(pingInterval);
|
|
764
|
-
pingInterval = undefined;
|
|
765
|
-
}
|
|
766
|
-
const shouldReconnect = !intentionalDisconnect &&
|
|
767
|
-
!(0, tunnel_1.isNonRetryableError)(lastError ?? '') &&
|
|
768
|
-
connectionState !== 'disconnected';
|
|
769
|
-
updateConnectionState('disconnected');
|
|
770
|
-
logger.debug('Disconnected from server.');
|
|
771
|
-
failPendingRequests('Connection closed');
|
|
772
|
-
if (!hasResolved) {
|
|
773
|
-
const err = handshakeError ?? new Error('Connection closed before the client was ready');
|
|
774
|
-
// Retry only the opening handshake. Once open, deviceInfo owns its failure.
|
|
775
|
-
const code = err.code;
|
|
776
|
-
const transient = ['ETIMEDOUT', 'ECONNRESET', 'ECONNREFUSED', 'EHOSTUNREACH', 'ENETUNREACH', 'EAI_AGAIN'].includes(code ?? '') ||
|
|
777
|
-
/^(Opening handshake has timed out|socket hang up|Unexpected server response: 50[234])$/.test(err.message);
|
|
778
|
-
if (!opened && !retriedHandshake && maxReconnectAttempts > 0 && transient) {
|
|
779
|
-
retriedHandshake = true;
|
|
780
|
-
updateConnectionState('reconnecting');
|
|
781
|
-
reconnectTimeout = setTimeout(setupWebSocket, 100 + Math.floor(Math.random() * 151));
|
|
782
|
-
}
|
|
783
|
-
else {
|
|
784
|
-
cleanupConnection();
|
|
785
|
-
rejectConnection(err);
|
|
786
|
-
}
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
if (shouldReconnect) {
|
|
790
|
-
scheduleReconnect();
|
|
791
|
-
}
|
|
792
|
-
else if ((0, tunnel_1.isNonRetryableError)(lastError ?? '')) {
|
|
793
|
-
logger.error(`Closing connection due to non-retryable error: ${lastError}`);
|
|
794
|
-
cleanup();
|
|
795
|
-
updateConnectionState('disconnected');
|
|
796
|
-
failPendingRequests('Non-retryable error');
|
|
797
|
-
clearServerNotifications();
|
|
798
|
-
logger.debug('Non-retryable error. Closing connection.');
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
ws.on('open', async () => {
|
|
802
|
-
clearTimeout(handshakeDeadline);
|
|
803
|
-
opened = true;
|
|
804
|
-
logger.debug('WebSocket connected');
|
|
805
|
-
reconnectAttempts = 0;
|
|
806
|
-
lastError = undefined;
|
|
807
|
-
updateConnectionState('connected');
|
|
808
|
-
pingInterval = setInterval(() => {
|
|
809
|
-
if (ws && ws.readyState === ws_1.WebSocket.OPEN) {
|
|
810
|
-
ws.ping();
|
|
811
|
-
}
|
|
812
|
-
}, 30000);
|
|
813
|
-
if (!hasResolved) {
|
|
814
|
-
try {
|
|
815
|
-
// Fetch device info before resolving connection
|
|
816
|
-
cachedDeviceInfo = await fetchDeviceInfo();
|
|
817
|
-
logger.debug('Device info fetched:', cachedDeviceInfo);
|
|
818
|
-
}
|
|
819
|
-
catch (err) {
|
|
820
|
-
logger.error('Failed to fetch device info:', err);
|
|
821
|
-
cleanupConnection();
|
|
822
|
-
updateConnectionState('disconnected');
|
|
823
|
-
rejectConnection(err);
|
|
824
|
-
return;
|
|
825
|
-
}
|
|
826
|
-
hasResolved = true;
|
|
827
|
-
resolveConnection({
|
|
828
|
-
screenshot,
|
|
829
|
-
elementTree,
|
|
830
|
-
elementTreeRaw,
|
|
831
|
-
readElementTree,
|
|
832
|
-
focusedElement,
|
|
833
|
-
tap,
|
|
834
|
-
tapWithScreenSize,
|
|
835
|
-
tapElement,
|
|
836
|
-
incrementElement,
|
|
837
|
-
decrementElement,
|
|
838
|
-
setElementValue,
|
|
839
|
-
typeText,
|
|
840
|
-
pressKey,
|
|
841
|
-
toggleKeyboard,
|
|
842
|
-
launchApp,
|
|
843
|
-
terminateApp,
|
|
844
|
-
watchApp,
|
|
845
|
-
monitorApp,
|
|
846
|
-
appLogTail,
|
|
847
|
-
streamAppLog,
|
|
848
|
-
streamSyslog,
|
|
849
|
-
listApps,
|
|
850
|
-
openUrl,
|
|
851
|
-
installApp,
|
|
852
|
-
saveKeychain,
|
|
853
|
-
restoreKeychain,
|
|
854
|
-
resetKeychain,
|
|
855
|
-
setPermission,
|
|
856
|
-
getPermission,
|
|
857
|
-
restartServices,
|
|
858
|
-
setOrientation,
|
|
859
|
-
getFoldState,
|
|
860
|
-
screenshotDisplay,
|
|
861
|
-
tapDisplay,
|
|
862
|
-
setDuoOrientation,
|
|
863
|
-
setHingeAngle,
|
|
864
|
-
scroll,
|
|
865
|
-
performActions,
|
|
866
|
-
startRecording,
|
|
867
|
-
stopRecording,
|
|
868
|
-
startRecordingSession,
|
|
869
|
-
stopRecordingSession,
|
|
870
|
-
startAppLogCapture,
|
|
871
|
-
stopAppLogCapture,
|
|
872
|
-
startEventCapture,
|
|
873
|
-
stopEventCapture,
|
|
874
|
-
streamAppLogCapture,
|
|
875
|
-
streamEventCapture,
|
|
876
|
-
startPerformanceCapture,
|
|
877
|
-
stopPerformanceCapture,
|
|
878
|
-
streamPerformance: streamClientPerformance,
|
|
879
|
-
playOnMicrophone,
|
|
880
|
-
stopMicrophonePlayback,
|
|
881
|
-
microphoneStatus,
|
|
882
|
-
keepAlive,
|
|
883
|
-
syncApp,
|
|
884
|
-
setStoreKitConfig,
|
|
885
|
-
addCaCertificate,
|
|
886
|
-
setBlockedDomains,
|
|
887
|
-
getBlockedDomains,
|
|
888
|
-
clearStoreKitConfig,
|
|
889
|
-
discoverStoreKitConfig,
|
|
890
|
-
softReset,
|
|
891
|
-
startReverseTunnel,
|
|
892
|
-
startTunnel,
|
|
893
|
-
getTunnelStatus,
|
|
894
|
-
stopTunnel,
|
|
895
|
-
targetHttpPortUrl,
|
|
896
|
-
startHttpProxy,
|
|
897
|
-
startForwardHttpProxy,
|
|
898
|
-
disconnect,
|
|
899
|
-
getConnectionState,
|
|
900
|
-
onConnectionStateChange,
|
|
901
|
-
simctl,
|
|
902
|
-
lldb,
|
|
903
|
-
xcrun,
|
|
904
|
-
startXcrunShim,
|
|
905
|
-
xcodebuild,
|
|
906
|
-
pushFile,
|
|
907
|
-
pullFile,
|
|
908
|
-
listFiles,
|
|
909
|
-
deleteFile,
|
|
910
|
-
setCameraVideo,
|
|
911
|
-
clearCameraVideo,
|
|
912
|
-
lsof,
|
|
913
|
-
deviceInfo: cachedDeviceInfo,
|
|
914
|
-
getDeviceInfo,
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
});
|
|
918
|
-
};
|
|
919
554
|
// ========================================================================
|
|
920
555
|
// Client Methods - using centralized sendRequest
|
|
921
556
|
// ========================================================================
|
|
@@ -1207,14 +842,13 @@ async function createInstanceClient(options) {
|
|
|
1207
842
|
return sendRequest('appLogTail', { bundleId, lines });
|
|
1208
843
|
};
|
|
1209
844
|
const streamAppLog = (bundleId) => {
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
return new log_stream_1.LogStream(endpointWebSocketUrl, subscribeMessage, 'streamAppLogTerminate', id);
|
|
845
|
+
// The instance serves app logs as server-sent events; appLogTail stays on signaling.
|
|
846
|
+
return new log_stream_1.LogStream({ apiUrl: options.apiUrl, token: options.token, bundleId });
|
|
1213
847
|
};
|
|
1214
848
|
const streamSyslog = () => {
|
|
1215
849
|
const id = generateId();
|
|
1216
850
|
const subscribeMessage = { type: 'streamSyslog', id };
|
|
1217
|
-
return new log_stream_1.LogStream(
|
|
851
|
+
return new log_stream_1.LogStream(transport.url, subscribeMessage, 'streamSyslogTerminate', id);
|
|
1218
852
|
};
|
|
1219
853
|
const listApps = () => {
|
|
1220
854
|
return sendRequest('listApps');
|
|
@@ -1392,15 +1026,7 @@ async function createInstanceClient(options) {
|
|
|
1392
1026
|
const microphoneStatus = async () => {
|
|
1393
1027
|
return sendRequest('microphoneStatus');
|
|
1394
1028
|
};
|
|
1395
|
-
const keepAlive = () =>
|
|
1396
|
-
if (!ws || ws.readyState !== ws_1.WebSocket.OPEN) {
|
|
1397
|
-
return;
|
|
1398
|
-
}
|
|
1399
|
-
ws.send(JSON.stringify({
|
|
1400
|
-
type: 'keepAlive',
|
|
1401
|
-
sessionId: keepAliveSessionId,
|
|
1402
|
-
}));
|
|
1403
|
-
};
|
|
1029
|
+
const keepAlive = () => transport.keepAlive();
|
|
1404
1030
|
const syncApp = async (localAppBundlePath, opts) => {
|
|
1405
1031
|
const preparedApp = await (0, app_archive_1.prepareAppBundlePath)(localAppBundlePath);
|
|
1406
1032
|
const appBundlePath = preparedApp.appPath;
|
|
@@ -1511,7 +1137,7 @@ async function createInstanceClient(options) {
|
|
|
1511
1137
|
});
|
|
1512
1138
|
}
|
|
1513
1139
|
// Send request asynchronously
|
|
1514
|
-
if (!
|
|
1140
|
+
if (!transport.isOpen()) {
|
|
1515
1141
|
// Defer error to next tick to allow caller to attach listeners
|
|
1516
1142
|
process.nextTick(() => {
|
|
1517
1143
|
simctlExecutions.delete(id);
|
|
@@ -1521,7 +1147,7 @@ async function createInstanceClient(options) {
|
|
|
1521
1147
|
}
|
|
1522
1148
|
// stdin can carry secrets such as one-time codes, so it stays out of the log.
|
|
1523
1149
|
logger.debug(`Sending ${request.type} request:`, { ...request, stdin: undefined });
|
|
1524
|
-
|
|
1150
|
+
transport.send(request, (err) => {
|
|
1525
1151
|
if (err) {
|
|
1526
1152
|
logger.error(`Failed to send ${request.type} request:`, err);
|
|
1527
1153
|
simctlExecutions.delete(id);
|
|
@@ -1553,25 +1179,20 @@ async function createInstanceClient(options) {
|
|
|
1553
1179
|
const lldb = (args, opts = {}) => {
|
|
1554
1180
|
const id = generateId();
|
|
1555
1181
|
const sendInput = (data, close, sequence) => {
|
|
1556
|
-
|
|
1557
|
-
return;
|
|
1558
|
-
ws.send(JSON.stringify({
|
|
1182
|
+
transport.send({
|
|
1559
1183
|
type: 'lldbInput',
|
|
1560
1184
|
id,
|
|
1561
1185
|
sequence,
|
|
1562
1186
|
...(data && { data: data.toString('base64') }),
|
|
1563
1187
|
...(close && { close }),
|
|
1564
|
-
})
|
|
1188
|
+
});
|
|
1565
1189
|
};
|
|
1566
1190
|
const execution = new LldbExecution(() => {
|
|
1567
1191
|
// The session stays tracked: the instance answers with the exit of LLDB, which is what
|
|
1568
1192
|
// ends `wait()`. A session dropped without `end` would otherwise keep the app stopped.
|
|
1569
1193
|
if (!execution.isRunning)
|
|
1570
1194
|
return;
|
|
1571
|
-
if (
|
|
1572
|
-
ws.send(JSON.stringify({ type: 'simctlTerminate', id }));
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1195
|
+
if (!transport.send({ type: 'simctlTerminate', id })) {
|
|
1575
1196
|
// Without a connection the instance has already ended the session and cannot say so.
|
|
1576
1197
|
simctlExecutions.delete(id);
|
|
1577
1198
|
execution._handleExit(143);
|
|
@@ -1842,24 +1463,163 @@ async function createInstanceClient(options) {
|
|
|
1842
1463
|
httpProxyCleanups.push(proxy.close);
|
|
1843
1464
|
return proxy.port;
|
|
1844
1465
|
};
|
|
1845
|
-
const disconnect = () =>
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
logger
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1466
|
+
const disconnect = () => transport.disconnect();
|
|
1467
|
+
const getConnectionState = () => transport.getConnectionState();
|
|
1468
|
+
const onConnectionStateChange = (callback) => transport.onConnectionStateChange(callback);
|
|
1469
|
+
transport = await (0, signaling_transport_1.openSignalingTransport)({
|
|
1470
|
+
apiUrl: options.apiUrl,
|
|
1471
|
+
token: options.token,
|
|
1472
|
+
logger,
|
|
1473
|
+
...(options.maxReconnectAttempts !== undefined && {
|
|
1474
|
+
maxReconnectAttempts: options.maxReconnectAttempts,
|
|
1475
|
+
}),
|
|
1476
|
+
...(options.reconnectDelay !== undefined && { reconnectDelay: options.reconnectDelay }),
|
|
1477
|
+
...(options.maxReconnectDelay !== undefined && { maxReconnectDelay: options.maxReconnectDelay }),
|
|
1478
|
+
responseHandlers: responseHandlers,
|
|
1479
|
+
replyError: (message) => commandError(message),
|
|
1480
|
+
redactRequest: redactRequestForDebug,
|
|
1481
|
+
handleMessage: (signal) => {
|
|
1482
|
+
const message = signal;
|
|
1483
|
+
if (handleAppExit(message) || handleAppHang(message)) {
|
|
1484
|
+
return true;
|
|
1485
|
+
}
|
|
1486
|
+
// Handle simctl streaming separately (it uses multiple messages per request)
|
|
1487
|
+
if (message.type === 'simctlStream') {
|
|
1488
|
+
const execution = simctlExecutions.get(message.id);
|
|
1489
|
+
if (!execution) {
|
|
1490
|
+
logger.debug(`Received simctl stream for unknown execution: ${message.id}`);
|
|
1491
|
+
return true;
|
|
1492
|
+
}
|
|
1493
|
+
if (execution instanceof LldbExecution) {
|
|
1494
|
+
execution._handleStarted();
|
|
1495
|
+
}
|
|
1496
|
+
if (message.stdout) {
|
|
1497
|
+
try {
|
|
1498
|
+
execution._handleStdout(Buffer.from(message.stdout, 'base64'));
|
|
1499
|
+
}
|
|
1500
|
+
catch (err) {
|
|
1501
|
+
logger.error('Failed to decode stdout data:', err);
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (message.stderr) {
|
|
1505
|
+
try {
|
|
1506
|
+
execution._handleStderr(Buffer.from(message.stderr, 'base64'));
|
|
1507
|
+
}
|
|
1508
|
+
catch (err) {
|
|
1509
|
+
logger.error('Failed to decode stderr data:', err);
|
|
1510
|
+
}
|
|
1511
|
+
}
|
|
1512
|
+
if (message.exitCode !== undefined) {
|
|
1513
|
+
logger.debug(`Simctl execution ${message.id} completed with exit code ${message.exitCode}`);
|
|
1514
|
+
// Forget the execution first: an exit listener may disconnect, and disconnecting
|
|
1515
|
+
// fails every execution still tracked, including this one.
|
|
1516
|
+
simctlExecutions.delete(message.id);
|
|
1517
|
+
execution._handleExit(message.exitCode);
|
|
1518
|
+
}
|
|
1519
|
+
return true;
|
|
1520
|
+
}
|
|
1521
|
+
return false;
|
|
1522
|
+
},
|
|
1523
|
+
onConnectionLost: failExecutions,
|
|
1524
|
+
onClosed: () => {
|
|
1525
|
+
cleanupClientResources();
|
|
1526
|
+
clearServerNotifications();
|
|
1527
|
+
},
|
|
1528
|
+
onFirstOpen: async (opened) => {
|
|
1529
|
+
transport = opened;
|
|
1530
|
+
cachedDeviceInfo = await fetchDeviceInfo();
|
|
1531
|
+
logger.debug('Device info fetched:', cachedDeviceInfo);
|
|
1532
|
+
},
|
|
1533
|
+
});
|
|
1534
|
+
return {
|
|
1535
|
+
screenshot,
|
|
1536
|
+
elementTree,
|
|
1537
|
+
elementTreeRaw,
|
|
1538
|
+
focusedElement,
|
|
1539
|
+
readElementTree,
|
|
1540
|
+
tap,
|
|
1541
|
+
tapWithScreenSize,
|
|
1542
|
+
tapElement,
|
|
1543
|
+
incrementElement,
|
|
1544
|
+
decrementElement,
|
|
1545
|
+
setElementValue,
|
|
1546
|
+
typeText,
|
|
1547
|
+
pressKey,
|
|
1548
|
+
toggleKeyboard,
|
|
1549
|
+
launchApp,
|
|
1550
|
+
terminateApp,
|
|
1551
|
+
watchApp,
|
|
1552
|
+
monitorApp,
|
|
1553
|
+
appLogTail,
|
|
1554
|
+
streamAppLog,
|
|
1555
|
+
streamSyslog,
|
|
1556
|
+
listApps,
|
|
1557
|
+
openUrl,
|
|
1558
|
+
installApp,
|
|
1559
|
+
saveKeychain,
|
|
1560
|
+
restoreKeychain,
|
|
1561
|
+
resetKeychain,
|
|
1562
|
+
setPermission,
|
|
1563
|
+
getPermission,
|
|
1564
|
+
restartServices,
|
|
1565
|
+
setOrientation,
|
|
1566
|
+
getFoldState,
|
|
1567
|
+
screenshotDisplay,
|
|
1568
|
+
tapDisplay,
|
|
1569
|
+
setDuoOrientation,
|
|
1570
|
+
setHingeAngle,
|
|
1571
|
+
scroll,
|
|
1572
|
+
performActions,
|
|
1573
|
+
startRecording,
|
|
1574
|
+
stopRecording,
|
|
1575
|
+
startRecordingSession,
|
|
1576
|
+
stopRecordingSession,
|
|
1577
|
+
startAppLogCapture,
|
|
1578
|
+
stopAppLogCapture,
|
|
1579
|
+
startEventCapture,
|
|
1580
|
+
stopEventCapture,
|
|
1581
|
+
streamAppLogCapture,
|
|
1582
|
+
streamEventCapture,
|
|
1583
|
+
startPerformanceCapture,
|
|
1584
|
+
stopPerformanceCapture,
|
|
1585
|
+
streamPerformance: streamClientPerformance,
|
|
1586
|
+
playOnMicrophone,
|
|
1587
|
+
stopMicrophonePlayback,
|
|
1588
|
+
microphoneStatus,
|
|
1589
|
+
keepAlive,
|
|
1590
|
+
syncApp,
|
|
1591
|
+
setStoreKitConfig,
|
|
1592
|
+
addCaCertificate,
|
|
1593
|
+
setBlockedDomains,
|
|
1594
|
+
getBlockedDomains,
|
|
1595
|
+
clearStoreKitConfig,
|
|
1596
|
+
discoverStoreKitConfig,
|
|
1597
|
+
softReset,
|
|
1598
|
+
startReverseTunnel,
|
|
1599
|
+
startTunnel,
|
|
1600
|
+
getTunnelStatus,
|
|
1601
|
+
stopTunnel,
|
|
1602
|
+
targetHttpPortUrl,
|
|
1603
|
+
startHttpProxy,
|
|
1604
|
+
startForwardHttpProxy,
|
|
1605
|
+
disconnect,
|
|
1606
|
+
getConnectionState,
|
|
1607
|
+
onConnectionStateChange,
|
|
1608
|
+
simctl,
|
|
1609
|
+
lldb,
|
|
1610
|
+
xcrun,
|
|
1611
|
+
startXcrunShim,
|
|
1612
|
+
xcodebuild,
|
|
1613
|
+
pushFile,
|
|
1614
|
+
pullFile,
|
|
1615
|
+
listFiles,
|
|
1616
|
+
deleteFile,
|
|
1617
|
+
setCameraVideo,
|
|
1618
|
+
clearCameraVideo,
|
|
1619
|
+
lsof,
|
|
1620
|
+
deviceInfo: cachedDeviceInfo,
|
|
1621
|
+
getDeviceInfo,
|
|
1861
1622
|
};
|
|
1862
|
-
|
|
1863
|
-
});
|
|
1623
|
+
}
|
|
1864
1624
|
}
|
|
1865
1625
|
//# sourceMappingURL=ios-client.js.map
|