@expo/serve-sim 0.1.47 → 0.1.48

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.
@@ -37,7 +37,7 @@ function __sd_simulate(p){
37
37
  `+Object.keys(U).map((j)=>`${j}: ${U[j]}`).join(`\r
38
38
  `)+`\r
39
39
  \r
40
- `+_)}function N(M,F,_,U,j,x){if(M.listenerCount("wsClientError")){let S=Error(j);Error.captureStackTrace(S,N),M.emit("wsClientError",S,_,F)}else E(_,U,j,x)}});I3=_0(kZ(),1),x3=_0(p8(),1),q3=_0($4(),1),S3=_0(Z$(),1),w3=_0(J$(),1),y3=_0(Y$(),1),tZ=_0(m8(),1),_$=_0(fZ(),1),$$=tZ.default;K2={"Network.setUserAgentOverride":"Page.overrideUserAgent","Network.setCacheDisabled":"Network.setResourceCachingDisabled"},z2={"Network.requestWillBeSent":{walltime:"wallTime"}},H2={hasUserGesture:!1,redirectHasExtraInfo:!1},M2={hasExtraInfo:!1},_2={encodedDataLength:0,shouldReportCorbBlocking:!1},F2={initialPriority:"Medium",referrerPolicy:"origin"},N2={connectionReused:!1,connectionId:0,fromDiskCache:!1,fromServiceWorker:!1,encodedDataLength:0};E2={"media-rule":"mediaRule","media-import-rule":"importRule","media-style-node":"inlineSheet","media-link-node":"linkedSheet"};S2={protocolVersion:"1.3",product:"Safari/inspect-webkit",revision:"605.1.15",userAgent:"Mozilla/5.0 (iPhone; CPU iPhone OS like Mac OS X) AppleWebKit/605.1.15 Safari/inspect-webkit",jsVersion:""};g2=["Animation","Autofill","Audits","ServiceWorker","Profiler","HeapProfiler","Storage","Tethering","Tracing","BackgroundService","FedCm","DeviceAccess","WebAuthn","Cast","Database","ApplicationCache","BackgroundFetch","DeviceOrientation","EventBreakpoints","FileSystem","HeadlessExperimental","IndexedDB","Memory","PerformanceTimeline","Performance","Preload","Schema","Security","SystemInfo","WebAudio"],u2={"Network.setAttachDebugStack":{},"Network.emulateNetworkConditionsByRule":{ruleIds:[]},"Network.overrideNetworkState":{},"Network.clearAcceptedEncodingsOverride":{},"Network.setAcceptedEncodings":{},"Network.enableReportingApi":{},"Overlay.setShowHinge":{},"Overlay.setShowViewportSizeOnResize":{},"Overlay.setShowGridOverlays":{},"Overlay.setShowFlexOverlays":{},"Overlay.setShowScrollSnapOverlays":{},"Overlay.setShowContainerQueryOverlays":{},"Overlay.setShowIsolatedElements":{},"Overlay.setPausedInDebuggerMessage":{},"Overlay.setShowAdHighlights":{},"Overlay.setShowDebugBorders":{},"Overlay.setShowFPSCounter":{},"Overlay.setShowLayoutShiftRegions":{},"Overlay.setShowScrollBottleneckRects":{},"Overlay.setShowHitTestBorders":{},"Overlay.setShowWebVitals":{},"CSS.trackComputedStyleUpdates":{},"CSS.takeComputedStyleUpdates":{nodeIds:[]},"CSS.startRuleUsageTracking":{},"CSS.stopRuleUsageTracking":{ruleUsage:[]},"CSS.takeCoverageDelta":{coverage:[],timestamp:0},"Page.setAdBlockingEnabled":{},"Page.removeScriptToEvaluateOnNewDocument":{},"Page.setBypassCSP":{},"Page.setInterceptFileChooserDialog":{},"Page.setPrerenderingAllowed":{},"Page.setRPHRegistrationMode":{},"Page.setSPCTransactionMode":{},"Emulation.setEmulatedVisionDeficiency":{},"Emulation.setFocusEmulationEnabled":{},"Emulation.setAutoDarkModeOverride":{},"Emulation.setAutomationOverride":{},"Emulation.setLocaleOverride":{},"Emulation.setTimezoneOverride":{},"Emulation.setVisibleSize":{},"Emulation.setIdleOverride":{},"Emulation.clearIdleOverride":{},"Emulation.setGeolocationOverride":{},"Emulation.clearGeolocationOverride":{},"Emulation.setSensorOverrideEnabled":{},"Emulation.setSensorOverrideReadings":{},"Emulation.setHardwareConcurrencyOverride":{},"Emulation.setNavigatorOverrides":{},"Emulation.setPageScaleFactor":{},"Emulation.setScrollbarsHidden":{},"Emulation.setDocumentCookieDisabled":{},"DOMDebugger.setBreakOnCSPViolation":{},"Runtime.addBinding":{},"Runtime.removeBinding":{},"Debugger.setReturnValue":{},"Debugger.setBlackboxExecutionContexts":{},"Debugger.setInstrumentationBreakpoint":{},"DOM.markUndoableState":{},"DOM.undo":{},"DOM.redo":{},"DOM.copyTo":{nodeId:0},"DOM.collectClassNamesFromSubtree":{classNames:[]},"Accessibility.enable":{},"Accessibility.disable":{},"Accessibility.getFullAXTree":{nodes:[]},"Accessibility.getRootAXNode":{node:null},"Accessibility.getPartialAXTree":{nodes:[]},"Accessibility.queryAXTree":{nodes:[]},"Accessibility.getAXNodeAndAncestors":{nodes:[]},"Accessibility.getChildAXNodes":{nodes:[]}};m2={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}});import{readdirSync as X1,readFileSync as G1,existsSync as c$,unlinkSync as E$,watch as T$}from"fs";import{readFile as V1,unlink as W1}from"fs/promises";import{execSync as X4,spawn as K1,exec as z1,execFile as N0}from"child_process";import{tmpdir as l$}from"os";import{join as v4}from"path";import{createServer as H1}from"net";import{createHash as d$,randomBytes as I$,timingSafeEqual as M1}from"crypto";import{WebSocket as x$}from"ws";var p4="Accessibility unavailable on this simulator.";import{createRequire as T5}from"module";import{dirname as l4,join as d4}from"path";import{existsSync as I5}from"fs";import{fileURLToPath as j9}from"url";var z4={mjpegFps:60,mjpegQuality:0.7,maxDimension:0,h264Bitrate:6000000,h264Fps:60},U5={transport:"http",httpCodec:"auto",webRtcCodec:"h264",...z4};function N9($){return typeof $==="number"&&Number.isFinite($)?$:null}function L9($,Q,Z,J){let Y=N9($);return Y==null?Q:Math.min(J,Math.max(Z,Y))}function K4($,Q,Z,J){return Math.round(L9($,Q,Z,J))}function A5($){if(!Array.isArray($)||$.length>16)return null;let Q=[];for(let Z of $){if(!Z||typeof Z!=="object")return null;let J=Z.urls;if(!Array.isArray(J)||J.length===0||J.length>16||!J.every((G)=>typeof G==="string"&&G.length<=2048&&/^(stun|stuns|turn|turns):/i.test(G)))return null;let{username:Y,credential:X}=Z;if(Y!==void 0&&typeof Y!=="string")return null;if(X!==void 0&&typeof X!=="string")return null;Q.push({urls:J,...typeof Y==="string"?{username:Y}:{},...typeof X==="string"?{credential:X}:{}})}return Q}var j5=new Set(["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"]),R5=new Set(["maxDimension","h264Bitrate","h264Fps"]);function B9($,Q){if(!$||typeof $!=="object"||Array.isArray($))return null;let Z=$,J=Object.keys(Z),Y=Q==="webrtc"?R5:j5;if(J.length===0||J.some((X)=>!Y.has(X)))return null;for(let X of["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"])if(X in Z&&N9(Z[X])==null)return null;return Z}function F9($={},Q=U5){let J=Object.prototype.hasOwnProperty.call($,"iceServers")?A5($.iceServers):Q.iceServers,Y=J===null?Q.iceServers:J&&J.length>0?J:void 0;return{transport:$.transport==="http"||$.transport==="webrtc"?$.transport:Q.transport,httpCodec:$.httpCodec==="auto"||$.httpCodec==="mjpeg"||$.httpCodec==="h264"?$.httpCodec:Q.httpCodec,webRtcCodec:$.webRtcCodec==="vp8"||$.webRtcCodec==="vp9"||$.webRtcCodec==="h264"?$.webRtcCodec:Q.webRtcCodec,...Y?{iceServers:Y}:{},...m4($,Q)}}function m4($={},Q=z4){return{mjpegFps:K4($.mjpegFps,Q.mjpegFps,1,120),mjpegQuality:L9($.mjpegQuality,Q.mjpegQuality,0.05,1),maxDimension:K4($.maxDimension,Q.maxDimension,0,4096),h264Bitrate:K4($.h264Bitrate,Q.h264Bitrate,1e5,50000000),h264Fps:K4($.h264Fps,Q.h264Fps,1,140)}}function O9($){return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function c4($,Q){if(Q==="webrtc")return{maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps};return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function U9($){let Q=$?{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}:{};if($?.transport==="webrtc")return F9({transport:"webrtc",webRtcCodec:$.codec,iceServers:$.iceServers,...Q});return F9({transport:"http",httpCodec:$?.codec??"auto",...Q})}function M4($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function H4($){return typeof $==="number"&&Number.isFinite($)?$:0}function Z0($){return typeof $==="number"&&Number.isFinite($)?$:null}function l0($){return typeof $==="string"&&$.length>0?$:null}function C5($){if(!M4($))return{};let Q={};for(let[Z,J]of Object.entries($)){let Y=Z0(J);if(Y!==null)Q[Z]=Y*1000}return Q}function D5($,Q){let Z=[l0($),l0(Q)];if(Z.some((J)=>J===null))return"unknown";return Z.includes("relay")?"relay":"direct"}function P5($){let Q=H4($.framesEncoded),Z=H4($.packetsSent),J=H4($.packetsLost),Y=Z0($.totalEncodeTime),X=Z0($.targetBitrate),G=Z0($.roundTripTime);return{sessionId:l0($.sessionId)??"",sourceFrames:Z0($.sourceFrames),sourceFps:Z0($.sourceFramesPerSecond),sourceFramesDropped:Z0($.sourceFramesDropped),codec:l0($.codec),connected:$.connected===!0,qualityLimitationReason:l0($.qualityLimitationReason),qualityLimitationMs:C5($.qualityLimitationDurations),framesEncoded:Q,framesSent:H4($.framesSent),reportedFps:Z0($.framesPerSecond),targetKbps:X===null?null:X/1000,totalEncodeMs:Y===null?null:Y*1000,encodeMsPerFrame:Y===null||Q<=0?null:Y*1000/Q,width:Z0($.frameWidth),height:Z0($.frameHeight),packetsSent:Z,packetsLost:J,lossRatio:Z>0?Math.max(0,J)/Z:null,roundTripMs:G===null?null:G*1000,path:D5($.localCandidateType,$.remoteCandidateType)}}function A9($){if(!M4($)||!Array.isArray($.sessions))return{sessions:[]};return{sessions:$.sessions.filter(M4).map(P5),capture:E5($.capture)}}function E5($){if(!M4($))return null;let{screenFrames:Q,idleFrames:Z}=$;if(typeof Q!=="number"||typeof Z!=="number")return null;return{screenFrames:Q,idleFrames:Z,offeredFrames:typeof $.offeredFrames==="number"?$.offeredFrames:null,forwardedFrames:typeof $.forwardedFrames==="number"?$.forwardedFrames:null}}var x5=T5(import.meta.url),q5=0,S5=1,w5=1,y5=2,d0={portrait:1,portraitUpsideDown:2,landscapeRight:3,landscapeLeft:4};function k5(){let $=[d4(l4(process.execPath),"native","serve-sim-native.node"),d4(l4(j9(import.meta.url)),"native","serve-sim-native.node"),d4(l4(j9(import.meta.url)),"..","dist","native","serve-sim-native.node")];for(let Q of $)if(I5(Q))return Q;throw Error(`serve-sim-native.node not found. Looked in:
40
+ `+_)}function N(M,F,_,U,j,x){if(M.listenerCount("wsClientError")){let S=Error(j);Error.captureStackTrace(S,N),M.emit("wsClientError",S,_,F)}else E(_,U,j,x)}});I3=_0(kZ(),1),x3=_0(p8(),1),q3=_0($4(),1),S3=_0(Z$(),1),w3=_0(J$(),1),y3=_0(Y$(),1),tZ=_0(m8(),1),_$=_0(fZ(),1),$$=tZ.default;K2={"Network.setUserAgentOverride":"Page.overrideUserAgent","Network.setCacheDisabled":"Network.setResourceCachingDisabled"},z2={"Network.requestWillBeSent":{walltime:"wallTime"}},H2={hasUserGesture:!1,redirectHasExtraInfo:!1},M2={hasExtraInfo:!1},_2={encodedDataLength:0,shouldReportCorbBlocking:!1},F2={initialPriority:"Medium",referrerPolicy:"origin"},N2={connectionReused:!1,connectionId:0,fromDiskCache:!1,fromServiceWorker:!1,encodedDataLength:0};E2={"media-rule":"mediaRule","media-import-rule":"importRule","media-style-node":"inlineSheet","media-link-node":"linkedSheet"};S2={protocolVersion:"1.3",product:"Safari/inspect-webkit",revision:"605.1.15",userAgent:"Mozilla/5.0 (iPhone; CPU iPhone OS like Mac OS X) AppleWebKit/605.1.15 Safari/inspect-webkit",jsVersion:""};g2=["Animation","Autofill","Audits","ServiceWorker","Profiler","HeapProfiler","Storage","Tethering","Tracing","BackgroundService","FedCm","DeviceAccess","WebAuthn","Cast","Database","ApplicationCache","BackgroundFetch","DeviceOrientation","EventBreakpoints","FileSystem","HeadlessExperimental","IndexedDB","Memory","PerformanceTimeline","Performance","Preload","Schema","Security","SystemInfo","WebAudio"],u2={"Network.setAttachDebugStack":{},"Network.emulateNetworkConditionsByRule":{ruleIds:[]},"Network.overrideNetworkState":{},"Network.clearAcceptedEncodingsOverride":{},"Network.setAcceptedEncodings":{},"Network.enableReportingApi":{},"Overlay.setShowHinge":{},"Overlay.setShowViewportSizeOnResize":{},"Overlay.setShowGridOverlays":{},"Overlay.setShowFlexOverlays":{},"Overlay.setShowScrollSnapOverlays":{},"Overlay.setShowContainerQueryOverlays":{},"Overlay.setShowIsolatedElements":{},"Overlay.setPausedInDebuggerMessage":{},"Overlay.setShowAdHighlights":{},"Overlay.setShowDebugBorders":{},"Overlay.setShowFPSCounter":{},"Overlay.setShowLayoutShiftRegions":{},"Overlay.setShowScrollBottleneckRects":{},"Overlay.setShowHitTestBorders":{},"Overlay.setShowWebVitals":{},"CSS.trackComputedStyleUpdates":{},"CSS.takeComputedStyleUpdates":{nodeIds:[]},"CSS.startRuleUsageTracking":{},"CSS.stopRuleUsageTracking":{ruleUsage:[]},"CSS.takeCoverageDelta":{coverage:[],timestamp:0},"Page.setAdBlockingEnabled":{},"Page.removeScriptToEvaluateOnNewDocument":{},"Page.setBypassCSP":{},"Page.setInterceptFileChooserDialog":{},"Page.setPrerenderingAllowed":{},"Page.setRPHRegistrationMode":{},"Page.setSPCTransactionMode":{},"Emulation.setEmulatedVisionDeficiency":{},"Emulation.setFocusEmulationEnabled":{},"Emulation.setAutoDarkModeOverride":{},"Emulation.setAutomationOverride":{},"Emulation.setLocaleOverride":{},"Emulation.setTimezoneOverride":{},"Emulation.setVisibleSize":{},"Emulation.setIdleOverride":{},"Emulation.clearIdleOverride":{},"Emulation.setGeolocationOverride":{},"Emulation.clearGeolocationOverride":{},"Emulation.setSensorOverrideEnabled":{},"Emulation.setSensorOverrideReadings":{},"Emulation.setHardwareConcurrencyOverride":{},"Emulation.setNavigatorOverrides":{},"Emulation.setPageScaleFactor":{},"Emulation.setScrollbarsHidden":{},"Emulation.setDocumentCookieDisabled":{},"DOMDebugger.setBreakOnCSPViolation":{},"Runtime.addBinding":{},"Runtime.removeBinding":{},"Debugger.setReturnValue":{},"Debugger.setBlackboxExecutionContexts":{},"Debugger.setInstrumentationBreakpoint":{},"DOM.markUndoableState":{},"DOM.undo":{},"DOM.redo":{},"DOM.copyTo":{nodeId:0},"DOM.collectClassNamesFromSubtree":{classNames:[]},"Accessibility.enable":{},"Accessibility.disable":{},"Accessibility.getFullAXTree":{nodes:[]},"Accessibility.getRootAXNode":{node:null},"Accessibility.getPartialAXTree":{nodes:[]},"Accessibility.queryAXTree":{nodes:[]},"Accessibility.getAXNodeAndAncestors":{nodes:[]},"Accessibility.getChildAXNodes":{nodes:[]}};m2={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}});import{readdirSync as X1,readFileSync as G1,existsSync as c$,unlinkSync as E$,watch as T$}from"fs";import{readFile as V1,unlink as W1}from"fs/promises";import{execSync as X4,spawn as K1,exec as z1,execFile as N0}from"child_process";import{tmpdir as l$}from"os";import{join as v4}from"path";import{createServer as H1}from"net";import{createHash as d$,randomBytes as I$,timingSafeEqual as M1}from"crypto";import{WebSocket as x$}from"ws";var p4="Accessibility unavailable on this simulator.";import{createRequire as T5}from"module";import{dirname as l4,join as d4}from"path";import{existsSync as I5}from"fs";import{fileURLToPath as j9}from"url";var z4={mjpegFps:60,mjpegQuality:0.7,maxDimension:0,h264Bitrate:6000000,h264Fps:60},U5={transport:"http",httpCodec:"auto",webRtcCodec:"h264",...z4};function N9($){return typeof $==="number"&&Number.isFinite($)?$:null}function L9($,Q,Z,J){let Y=N9($);return Y==null?Q:Math.min(J,Math.max(Z,Y))}function K4($,Q,Z,J){return Math.round(L9($,Q,Z,J))}function A5($){if(!Array.isArray($)||$.length>16)return null;let Q=[];for(let Z of $){if(!Z||typeof Z!=="object")return null;let J=Z.urls;if(!Array.isArray(J)||J.length===0||J.length>16||!J.every((G)=>typeof G==="string"&&G.length<=2048&&/^(stun|stuns|turn|turns):/i.test(G)))return null;let{username:Y,credential:X}=Z;if(Y!==void 0&&typeof Y!=="string")return null;if(X!==void 0&&typeof X!=="string")return null;Q.push({urls:J,...typeof Y==="string"?{username:Y}:{},...typeof X==="string"?{credential:X}:{}})}return Q}var j5=new Set(["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"]),R5=new Set(["maxDimension","h264Bitrate","h264Fps"]);function B9($,Q){if(!$||typeof $!=="object"||Array.isArray($))return null;let Z=$,J=Object.keys(Z),Y=Q==="webrtc"?R5:j5;if(J.length===0||J.some((X)=>!Y.has(X)))return null;for(let X of["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"])if(X in Z&&N9(Z[X])==null)return null;return Z}function F9($={},Q=U5){let J=Object.prototype.hasOwnProperty.call($,"iceServers")?A5($.iceServers):Q.iceServers,Y=J===null?Q.iceServers:J&&J.length>0?J:void 0;return{transport:$.transport==="http"||$.transport==="webrtc"?$.transport:Q.transport,httpCodec:$.httpCodec==="auto"||$.httpCodec==="mjpeg"||$.httpCodec==="h264"?$.httpCodec:Q.httpCodec,webRtcCodec:$.webRtcCodec==="vp8"||$.webRtcCodec==="vp9"||$.webRtcCodec==="h264"?$.webRtcCodec:Q.webRtcCodec,...Y?{iceServers:Y}:{},...m4($,Q)}}function m4($={},Q=z4){return{mjpegFps:K4($.mjpegFps,Q.mjpegFps,1,120),mjpegQuality:L9($.mjpegQuality,Q.mjpegQuality,0.05,1),maxDimension:K4($.maxDimension,Q.maxDimension,0,4096),h264Bitrate:K4($.h264Bitrate,Q.h264Bitrate,1e5,50000000),h264Fps:K4($.h264Fps,Q.h264Fps,1,140)}}function O9($){return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function c4($,Q){if(Q==="webrtc")return{maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps};return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function U9($){let Q=$?{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}:{};if($?.transport==="webrtc")return F9({transport:"webrtc",webRtcCodec:$.codec,iceServers:$.iceServers,...Q});return F9({transport:"http",httpCodec:$?.codec??"auto",...Q})}function M4($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function H4($){return typeof $==="number"&&Number.isFinite($)?$:0}function Z0($){return typeof $==="number"&&Number.isFinite($)?$:null}function l0($){return typeof $==="string"&&$.length>0?$:null}function C5($){if(!M4($))return{};let Q={};for(let[Z,J]of Object.entries($)){let Y=Z0(J);if(Y!==null)Q[Z]=Y*1000}return Q}function D5($,Q){let Z=[l0($),l0(Q)];if(Z.some((J)=>J===null))return"unknown";return Z.includes("relay")?"relay":"direct"}function P5($){let Q=H4($.framesEncoded),Z=H4($.packetsSent),J=H4($.packetsLost),Y=Z0($.totalEncodeTime),X=Z0($.targetBitrate),G=Z0($.roundTripTime);return{sessionId:l0($.sessionId)??"",sourceFrames:Z0($.sourceFrames),sourceFps:Z0($.sourceFramesPerSecond),sourceFramesDropped:Z0($.sourceFramesDropped),codec:l0($.codec),connected:$.connected===!0,qualityLimitationReason:l0($.qualityLimitationReason),qualityLimitationMs:C5($.qualityLimitationDurations),framesEncoded:Q,framesSent:H4($.framesSent),reportedFps:Z0($.framesPerSecond),targetKbps:X===null?null:X/1000,totalEncodeMs:Y===null?null:Y*1000,encodeMsPerFrame:Y===null||Q<=0?null:Y*1000/Q,width:Z0($.frameWidth),height:Z0($.frameHeight),packetsSent:Z,packetsLost:J,lossRatio:Z>0?Math.max(0,J)/Z:null,roundTripMs:G===null?null:G*1000,path:D5($.localCandidateType,$.remoteCandidateType)}}function A9($){if(!M4($)||!Array.isArray($.sessions))return{sessions:[]};return{sessions:$.sessions.filter(M4).map(P5),capture:E5($.capture)}}function E5($){if(!M4($))return null;let{screenFrames:Q,idleFrames:Z}=$;if(typeof Q!=="number"||typeof Z!=="number")return null;return{screenFrames:Q,idleFrames:Z,offeredFrames:typeof $.offeredFrames==="number"?$.offeredFrames:null,forwardedFrames:typeof $.forwardedFrames==="number"?$.forwardedFrames:null,pumpRestarts:typeof $.pumpRestarts==="number"?$.pumpRestarts:null}}var x5=T5(import.meta.url),q5=0,S5=1,w5=1,y5=2,d0={portrait:1,portraitUpsideDown:2,landscapeRight:3,landscapeLeft:4};function k5(){let $=[d4(l4(process.execPath),"native","serve-sim-native.node"),d4(l4(j9(import.meta.url)),"native","serve-sim-native.node"),d4(l4(j9(import.meta.url)),"..","dist","native","serve-sim-native.node")];for(let Q of $)if(I5(Q))return Q;throw Error(`serve-sim-native.node not found. Looked in:
41
41
  ${$.join(`
42
42
  `)}
43
43
  Run \`bun run build.ts\` to build the native addon.`)}var n4;function _4(){if(!n4)n4=x5(k5());return n4}class i4{handle;constructor($){this.handle=new(_4()).SimHID($)}async guard($,Q,Z){try{return await Q()}catch(J){return console.error(`[hid] ${$} ignored bad input:`,J instanceof Error?J.message:J),Z}}touch($,Q,Z,J,Y,X=0){return this.guard("touch",()=>this.handle.touch($,Q,Z,J,Y,X),void 0)}multiTouch($,Q,Z,J,Y,X,G){return this.guard("multiTouch",()=>this.handle.multiTouch($,Q,Z,J,Y,X,G),void 0)}button($){return this.guard("button",()=>this.handle.button($),void 0)}buttonHid($,Q,Z="press"){return this.guard("buttonHid",()=>this.handle.buttonHid($,Q,Z),void 0)}key($,Q){return this.guard("key",()=>this.handle.key($,Q),void 0)}scroll($,Q,Z,J,Y,X){return this.guard("scroll",()=>this.handle.scroll($,Q,Y??NaN,X??NaN,Z,J),void 0)}digitalCrown($){return this.guard("digitalCrown",()=>this.handle.digitalCrown($),void 0)}orientation($){return this.guard("orientation",()=>this.handle.orientation($),!1)}memoryWarning(){return this.guard("memoryWarning",()=>this.handle.memoryWarning(),void 0)}softwareKeyboard(){return this.guard("softwareKeyboard",()=>this.handle.softwareKeyboard(),void 0)}caDebug($,Q){return this.guard("caDebug",()=>this.handle.caDebug($,Q),!1)}}class o4{handle;constructor($,Q=z4){this.handle=new(_4()).SimCapture($,Q.mjpegFps,Q.mjpegQuality,Q.maxDimension,Q.h264Fps,Q.h264Bitrate)}start(){return this.handle.start()}updateStreamSettings($){return this.handle.updateStreamSettings($.mjpegFps,$.mjpegQuality,$.maxDimension,$.h264Fps,$.h264Bitrate)}subscribeMjpeg($){return this.handle.subscribe(q5,(Q,Z,J,Y)=>{return $({data:Q,width:Z,height:J})})}subscribeAvcc($){return this.handle.subscribe(S5,(Q,Z,J,Y)=>{return $({data:Q,width:Z,height:J,isDescription:(Y&w5)!==0,isKeyframe:(Y&y5)!==0})})}async handleWebRTCOffer($){return JSON.parse(await this.handle.handleWebRTCOffer(JSON.stringify($)))}closeWebRTCSession($){return this.handle.closeWebRTCSession($)}async webRTCSenderStats($){return A9(JSON.parse(await this.handle.webRTCSenderStats($??"")))}screenSize(){return this.handle.screenSize()}stop(){return this.handle.stop()}}function F4($){return _4().axDescribe($)}function N4($){return _4().axFrontmost($)}var a4=500,R9=500,f5=2000,v5=15000;function b5($){return $[0]?.frame??{x:0,y:0,width:1,height:1}}function h5($,Q){return Math.abs($.x-Q.x)<0.5&&Math.abs($.y-Q.y)<0.5&&Math.abs($.width-Q.width)<0.5&&Math.abs($.height-Q.height)<0.5}function g5($){let Q=b5($),Z=[],J=(Y,X)=>{if(Z.length>=a4)return;let G=Y.frame;if(!h5(G,Q))Z.push({id:Y.AXUniqueId??X,path:X,label:Y.AXLabel??"",value:Y.AXValue??"",role:Y.role_description,type:Y.type,enabled:Y.enabled!==!1,frame:G});for(let V=0;V<Y.children.length&&Z.length<a4;V++)J(Y.children[V],`${X}.${V}`)};for(let Y=0;Y<$.length&&Z.length<a4;Y++)J($[Y],String(Y));return{screen:{width:Q.width,height:Q.height},elements:Z}}async function u5($){let Q;try{Q=JSON.parse(await F4($))}catch{return{screen:{width:1,height:1},elements:[],errors:[p4]}}return g5(Q)}function p5($){return $?.errors?.includes(p4)??!1}function m5($){return $.elements.length>0&&$.screen.width>1&&$.screen.height>1}async function c5($){let Q=[];try{let Z=await u5($);if(Z.errors?.length)return Z;if(!m5(Z))throw Error(`native AX returned ${Z.elements.length} elements in ${Z.screen.width}x${Z.screen.height} AX space`);return{...Z,errors:Q}}catch(Z){Q.push(Z.message||String(Z))}return{screen:{width:1,height:1},elements:[],errors:Q}}function l5($){return`data: ${JSON.stringify($)}
@@ -131,5 +131,5 @@ ${N}`)}})();return}if(!A){H.destroy();return}let D=A.device??T;if(A.upstreamPath
131
131
  \r
132
132
  `)};let L=async(O)=>{return o6(z,O)},B=h6({path:`${Z}/exec-ws`,execToken:K,ssePrefixes:[`${Z}/api/events`,`${Z}/api/event-log/events`,`${Z}/grid/api/status/events`,`${Z}/appstate`,`${Z}/logs`,`${Z}/metrics`,`${Z}/ax`],onUiRequest:W,onCommandResult:(O,H)=>k$(O,H),onSseRequest(O,H){let P=new URL(O,H.url);return L(new Request(P,{headers:{accept:"text/event-stream"}}))}});return L.handleWebSocket=(O,H)=>{if(B(O,H))return!0;if(f9(O,H,{helperProxyTarget:(P)=>a8(P,J),fallbackDevice:$?.device??null,resolveSession:(P)=>a0(P,Q)}))return!0;return!1},L.handleUpgrade=(O,H,P)=>{z.handleUpgrade?.(O,H,P)},L}export{q1 as startDeviceInProcess,JY as simMiddleware,W0 as selectServeSimState,y4 as rewriteStateForRequestHost,J0 as readServeSimStates,r8 as previewConfigForState,b$ as parseGridPaging,ZY as matchInstalledAppByDisplayName,i1 as handleMetricsRequest,U1 as deviceNameFromBootedNames};
133
133
 
134
- //# debugId=3D74F43EE3A2EB4F64756E2164756E21
134
+ //# debugId=078A99A4F7DA3BA064756E2164756E21
135
135
  //# sourceMappingURL=middleware.js.map
Binary file
package/dist/serve-sim.js CHANGED
@@ -48,7 +48,7 @@ Simulator-wide UI options:
48
48
  `)}function j1($){if($)process.env.DEBUG=$;else delete process.env.DEBUG}function T1(){return process.env.DEBUG}function O1($){$.inspectOpts={};let Q=Object.keys(s9.inspectOpts);for(let Z=0;Z<Q.length;Z++)$.inspectOpts[Q[Z]]=s9.inspectOpts[Q[Z]]}X$.exports=V6()(s9);var{formatters:t9}=X$.exports;t9.o=function($){return this.inspectOpts.colors=this.useColors,Y$.inspect($,this.inspectOpts).split(`
49
49
  `).map((Q)=>Q.trim()).join(" ")};t9.O=function($){return this.inspectOpts.colors=this.useColors,Y$.inspect($,this.inspectOpts)}});var Q2=K0((eK,H6)=>{if(typeof process>"u"||process.type==="renderer"||!1||process.__nwjs)H6.exports=r9();else H6.exports=$2()});var A4,L6,M6,M0,D4;var U6=d(()=>{A4=a8(Q2(),1),L6=A4.default("serve-sim:cli"),M6=A4.default("serve-sim:helper"),M0=A4.default("serve-sim:state"),D4=A4.default("serve-sim:mw")});import{createHash as y1}from"crypto";import{existsSync as G2,readFileSync as K2}from"fs";import{join as B6}from"path";function E4($){return B6(C0,`${$}.pid`)}function K$($){return B6(C0,`${$}.bundles.json`)}function W$($){return`/tmp/serve-sim-cam-${y1("sha1").update($).digest("hex").slice(0,12)}.sock`}function b1($){try{return process.kill($,0),!0}catch{return!1}}function R6($){try{let Q=Number(K2(E4($),"utf-8").trim());return Number.isInteger(Q)&&Q>0?Q:null}catch{return null}}function v1($){if(!$||typeof $!=="object"||Array.isArray($))throw Error("invalid camera helper reply");return $}async function G4($,Q){let Z=W$($);if(!G2(Z))throw Error("camera helper socket not found");let J=await import("net");return new Promise((Y,X)=>{let G=J.createConnection(Z);G.setEncoding("utf8");let W="",K=!1,z,V=(H,B)=>{if(K)return;if(K=!0,z)clearTimeout(z);if(H)X(H);else Y(B??{})};G.on("data",(H)=>{W+=H;let B=W.indexOf(`
50
50
  `);if(B<0)return;try{V(void 0,v1(JSON.parse(W.slice(0,B))))}catch(N){V(N)}G.end()}),G.on("error",V),G.on("close",()=>V(Error("socket closed"))),z=setTimeout(()=>{G.destroy(),V(Error("helper timeout"))},f1),G.write(JSON.stringify(Q)+`
51
- `)})}function C4($){let Q=R6($);return Q!==null&&b1(Q)&&G2(W$($))}function z$($){let Q;try{let J=JSON.parse(K2(K$($),"utf-8"));if(!J||typeof J!=="object"||Array.isArray(J))return[];let Y=J;if(typeof Y.helperPid!=="number"||!Array.isArray(Y.bundleIds))return[];Q={helperPid:Y.helperPid,bundleIds:Y.bundleIds}}catch{return[]}let Z=R6($);if(Z===null||Q.helperPid!==Z)return[];return Q.bundleIds.filter((J)=>typeof J==="string")}async function V$($){if(!C4($))return{udid:$,alive:!1};let Q=R6($),Z=z$($);try{return{...await G4($,{action:"status"}),udid:$,alive:!0,helperPid:Q,bundleIds:Z}}catch(J){return{udid:$,alive:!0,helperPid:Q,bundleIds:Z,error:J instanceof Error?J.message:String(J)}}}var C0,f1=3000;var N6=d(()=>{r4();C0=B6(H0,"simcam")});function z2($){return typeof $==="number"&&Number.isFinite($)?$:null}function V2($,Q,Z,J){let Y=z2($);return Y==null?Q:Math.min(J,Math.max(Z,Y))}function H$($,Q,Z,J){return Math.round(V2($,Q,Z,J))}function g1($){if(!Array.isArray($)||$.length>16)return null;let Q=[];for(let Z of $){if(!Z||typeof Z!=="object")return null;let J=Z.urls;if(!Array.isArray(J)||J.length===0||J.length>16||!J.every((G)=>typeof G==="string"&&G.length<=2048&&/^(stun|stuns|turn|turns):/i.test(G)))return null;let{username:Y,credential:X}=Z;if(Y!==void 0&&typeof Y!=="string")return null;if(X!==void 0&&typeof X!=="string")return null;Q.push({urls:J,...typeof Y==="string"?{username:Y}:{},...typeof X==="string"?{credential:X}:{}})}return Q}function H2($,Q){if(!$||typeof $!=="object"||Array.isArray($))return null;let Z=$,J=Object.keys(Z),Y=Q==="webrtc"?m1:u1;if(J.length===0||J.some((X)=>!Y.has(X)))return null;for(let X of["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"])if(X in Z&&z2(Z[X])==null)return null;return Z}function W2($={},Q=h1){let J=Object.prototype.hasOwnProperty.call($,"iceServers")?g1($.iceServers):Q.iceServers,Y=J===null?Q.iceServers:J&&J.length>0?J:void 0;return{transport:$.transport==="http"||$.transport==="webrtc"?$.transport:Q.transport,httpCodec:$.httpCodec==="auto"||$.httpCodec==="mjpeg"||$.httpCodec==="h264"?$.httpCodec:Q.httpCodec,webRtcCodec:$.webRtcCodec==="vp8"||$.webRtcCodec==="vp9"||$.webRtcCodec==="h264"?$.webRtcCodec:Q.webRtcCodec,...Y?{iceServers:Y}:{},...K4($,Q)}}function K4($={},Q=L$){return{mjpegFps:H$($.mjpegFps,Q.mjpegFps,1,120),mjpegQuality:V2($.mjpegQuality,Q.mjpegQuality,0.05,1),maxDimension:H$($.maxDimension,Q.maxDimension,0,4096),h264Bitrate:H$($.h264Bitrate,Q.h264Bitrate,1e5,50000000),h264Fps:H$($.h264Fps,Q.h264Fps,1,140)}}function L2($){return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function T6($,Q){if(Q==="webrtc")return{maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps};return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function M2($){let Q=$?{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}:{};if($?.transport==="webrtc")return W2({transport:"webrtc",webRtcCodec:$.codec,iceServers:$.iceServers,...Q});return W2({transport:"http",httpCodec:$?.codec??"auto",...Q})}var F6=120,j6=140,L$,h1,u1,m1;var P4=d(()=>{L$={mjpegFps:60,mjpegQuality:0.7,maxDimension:0,h264Bitrate:6000000,h264Fps:60},h1={transport:"http",httpCodec:"auto",webRtcCodec:"h264",...L$};u1=new Set(["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"]),m1=new Set(["maxDimension","h264Bitrate","h264Fps"])});var D6="Accessibility unavailable on this simulator.";function U$($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function M$($){return typeof $==="number"&&Number.isFinite($)?$:0}function U0($){return typeof $==="number"&&Number.isFinite($)?$:null}function q4($){return typeof $==="string"&&$.length>0?$:null}function l1($){if(!U$($))return{};let Q={};for(let[Z,J]of Object.entries($)){let Y=U0(J);if(Y!==null)Q[Z]=Y*1000}return Q}function n1($,Q){let Z=[q4($),q4(Q)];if(Z.some((J)=>J===null))return"unknown";return Z.includes("relay")?"relay":"direct"}function d1($){let Q=M$($.framesEncoded),Z=M$($.packetsSent),J=M$($.packetsLost),Y=U0($.totalEncodeTime),X=U0($.targetBitrate),G=U0($.roundTripTime);return{sessionId:q4($.sessionId)??"",sourceFrames:U0($.sourceFrames),sourceFps:U0($.sourceFramesPerSecond),sourceFramesDropped:U0($.sourceFramesDropped),codec:q4($.codec),connected:$.connected===!0,qualityLimitationReason:q4($.qualityLimitationReason),qualityLimitationMs:l1($.qualityLimitationDurations),framesEncoded:Q,framesSent:M$($.framesSent),reportedFps:U0($.framesPerSecond),targetKbps:X===null?null:X/1000,totalEncodeMs:Y===null?null:Y*1000,encodeMsPerFrame:Y===null||Q<=0?null:Y*1000/Q,width:U0($.frameWidth),height:U0($.frameHeight),packetsSent:Z,packetsLost:J,lossRatio:Z>0?Math.max(0,J)/Z:null,roundTripMs:G===null?null:G*1000,path:n1($.localCandidateType,$.remoteCandidateType)}}function B2($){if(!U$($)||!Array.isArray($.sessions))return{sessions:[]};return{sessions:$.sessions.filter(U$).map(d1),capture:i1($.capture)}}function i1($){if(!U$($))return null;let{screenFrames:Q,idleFrames:Z}=$;if(typeof Q!=="number"||typeof Z!=="number")return null;return{screenFrames:Q,idleFrames:Z,offeredFrames:typeof $.offeredFrames==="number"?$.offeredFrames:null,forwardedFrames:typeof $.forwardedFrames==="number"?$.forwardedFrames:null}}import{createRequire as o1}from"module";import{dirname as E6,join as C6}from"path";import{existsSync as a1}from"fs";import{fileURLToPath as R2}from"url";function QJ(){let $=[C6(E6(process.execPath),"native","serve-sim-native.node"),C6(E6(R2(import.meta.url)),"native","serve-sim-native.node"),C6(E6(R2(import.meta.url)),"..","dist","native","serve-sim-native.node")];for(let Q of $)if(a1(Q))return Q;throw Error(`serve-sim-native.node not found. Looked in:
51
+ `)})}function C4($){let Q=R6($);return Q!==null&&b1(Q)&&G2(W$($))}function z$($){let Q;try{let J=JSON.parse(K2(K$($),"utf-8"));if(!J||typeof J!=="object"||Array.isArray(J))return[];let Y=J;if(typeof Y.helperPid!=="number"||!Array.isArray(Y.bundleIds))return[];Q={helperPid:Y.helperPid,bundleIds:Y.bundleIds}}catch{return[]}let Z=R6($);if(Z===null||Q.helperPid!==Z)return[];return Q.bundleIds.filter((J)=>typeof J==="string")}async function V$($){if(!C4($))return{udid:$,alive:!1};let Q=R6($),Z=z$($);try{return{...await G4($,{action:"status"}),udid:$,alive:!0,helperPid:Q,bundleIds:Z}}catch(J){return{udid:$,alive:!0,helperPid:Q,bundleIds:Z,error:J instanceof Error?J.message:String(J)}}}var C0,f1=3000;var N6=d(()=>{r4();C0=B6(H0,"simcam")});function z2($){return typeof $==="number"&&Number.isFinite($)?$:null}function V2($,Q,Z,J){let Y=z2($);return Y==null?Q:Math.min(J,Math.max(Z,Y))}function H$($,Q,Z,J){return Math.round(V2($,Q,Z,J))}function g1($){if(!Array.isArray($)||$.length>16)return null;let Q=[];for(let Z of $){if(!Z||typeof Z!=="object")return null;let J=Z.urls;if(!Array.isArray(J)||J.length===0||J.length>16||!J.every((G)=>typeof G==="string"&&G.length<=2048&&/^(stun|stuns|turn|turns):/i.test(G)))return null;let{username:Y,credential:X}=Z;if(Y!==void 0&&typeof Y!=="string")return null;if(X!==void 0&&typeof X!=="string")return null;Q.push({urls:J,...typeof Y==="string"?{username:Y}:{},...typeof X==="string"?{credential:X}:{}})}return Q}function H2($,Q){if(!$||typeof $!=="object"||Array.isArray($))return null;let Z=$,J=Object.keys(Z),Y=Q==="webrtc"?m1:u1;if(J.length===0||J.some((X)=>!Y.has(X)))return null;for(let X of["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"])if(X in Z&&z2(Z[X])==null)return null;return Z}function W2($={},Q=h1){let J=Object.prototype.hasOwnProperty.call($,"iceServers")?g1($.iceServers):Q.iceServers,Y=J===null?Q.iceServers:J&&J.length>0?J:void 0;return{transport:$.transport==="http"||$.transport==="webrtc"?$.transport:Q.transport,httpCodec:$.httpCodec==="auto"||$.httpCodec==="mjpeg"||$.httpCodec==="h264"?$.httpCodec:Q.httpCodec,webRtcCodec:$.webRtcCodec==="vp8"||$.webRtcCodec==="vp9"||$.webRtcCodec==="h264"?$.webRtcCodec:Q.webRtcCodec,...Y?{iceServers:Y}:{},...K4($,Q)}}function K4($={},Q=L$){return{mjpegFps:H$($.mjpegFps,Q.mjpegFps,1,120),mjpegQuality:V2($.mjpegQuality,Q.mjpegQuality,0.05,1),maxDimension:H$($.maxDimension,Q.maxDimension,0,4096),h264Bitrate:H$($.h264Bitrate,Q.h264Bitrate,1e5,50000000),h264Fps:H$($.h264Fps,Q.h264Fps,1,140)}}function L2($){return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function T6($,Q){if(Q==="webrtc")return{maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps};return{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}}function M2($){let Q=$?{mjpegFps:$.mjpegFps,mjpegQuality:$.mjpegQuality,maxDimension:$.maxDimension,h264Bitrate:$.h264Bitrate,h264Fps:$.h264Fps}:{};if($?.transport==="webrtc")return W2({transport:"webrtc",webRtcCodec:$.codec,iceServers:$.iceServers,...Q});return W2({transport:"http",httpCodec:$?.codec??"auto",...Q})}var F6=120,j6=140,L$,h1,u1,m1;var P4=d(()=>{L$={mjpegFps:60,mjpegQuality:0.7,maxDimension:0,h264Bitrate:6000000,h264Fps:60},h1={transport:"http",httpCodec:"auto",webRtcCodec:"h264",...L$};u1=new Set(["mjpegFps","mjpegQuality","maxDimension","h264Bitrate","h264Fps"]),m1=new Set(["maxDimension","h264Bitrate","h264Fps"])});var D6="Accessibility unavailable on this simulator.";function U$($){return typeof $==="object"&&$!==null&&!Array.isArray($)}function M$($){return typeof $==="number"&&Number.isFinite($)?$:0}function U0($){return typeof $==="number"&&Number.isFinite($)?$:null}function q4($){return typeof $==="string"&&$.length>0?$:null}function l1($){if(!U$($))return{};let Q={};for(let[Z,J]of Object.entries($)){let Y=U0(J);if(Y!==null)Q[Z]=Y*1000}return Q}function n1($,Q){let Z=[q4($),q4(Q)];if(Z.some((J)=>J===null))return"unknown";return Z.includes("relay")?"relay":"direct"}function d1($){let Q=M$($.framesEncoded),Z=M$($.packetsSent),J=M$($.packetsLost),Y=U0($.totalEncodeTime),X=U0($.targetBitrate),G=U0($.roundTripTime);return{sessionId:q4($.sessionId)??"",sourceFrames:U0($.sourceFrames),sourceFps:U0($.sourceFramesPerSecond),sourceFramesDropped:U0($.sourceFramesDropped),codec:q4($.codec),connected:$.connected===!0,qualityLimitationReason:q4($.qualityLimitationReason),qualityLimitationMs:l1($.qualityLimitationDurations),framesEncoded:Q,framesSent:M$($.framesSent),reportedFps:U0($.framesPerSecond),targetKbps:X===null?null:X/1000,totalEncodeMs:Y===null?null:Y*1000,encodeMsPerFrame:Y===null||Q<=0?null:Y*1000/Q,width:U0($.frameWidth),height:U0($.frameHeight),packetsSent:Z,packetsLost:J,lossRatio:Z>0?Math.max(0,J)/Z:null,roundTripMs:G===null?null:G*1000,path:n1($.localCandidateType,$.remoteCandidateType)}}function B2($){if(!U$($)||!Array.isArray($.sessions))return{sessions:[]};return{sessions:$.sessions.filter(U$).map(d1),capture:i1($.capture)}}function i1($){if(!U$($))return null;let{screenFrames:Q,idleFrames:Z}=$;if(typeof Q!=="number"||typeof Z!=="number")return null;return{screenFrames:Q,idleFrames:Z,offeredFrames:typeof $.offeredFrames==="number"?$.offeredFrames:null,forwardedFrames:typeof $.forwardedFrames==="number"?$.forwardedFrames:null,pumpRestarts:typeof $.pumpRestarts==="number"?$.pumpRestarts:null}}import{createRequire as o1}from"module";import{dirname as E6,join as C6}from"path";import{existsSync as a1}from"fs";import{fileURLToPath as R2}from"url";function QJ(){let $=[C6(E6(process.execPath),"native","serve-sim-native.node"),C6(E6(R2(import.meta.url)),"native","serve-sim-native.node"),C6(E6(R2(import.meta.url)),"..","dist","native","serve-sim-native.node")];for(let Q of $)if(a1(Q))return Q;throw Error(`serve-sim-native.node not found. Looked in:
52
52
  ${$.join(`
53
53
  `)}
54
54
  Run \`bun run build.ts\` to build the native addon.`)}function _$(){if(!P6)P6=r1(QJ());return P6}class q6{handle;constructor($){this.handle=new(_$()).SimHID($)}async guard($,Q,Z){try{return await Q()}catch(J){return console.error(`[hid] ${$} ignored bad input:`,J instanceof Error?J.message:J),Z}}touch($,Q,Z,J,Y,X=0){return this.guard("touch",()=>this.handle.touch($,Q,Z,J,Y,X),void 0)}multiTouch($,Q,Z,J,Y,X,G){return this.guard("multiTouch",()=>this.handle.multiTouch($,Q,Z,J,Y,X,G),void 0)}button($){return this.guard("button",()=>this.handle.button($),void 0)}buttonHid($,Q,Z="press"){return this.guard("buttonHid",()=>this.handle.buttonHid($,Q,Z),void 0)}key($,Q){return this.guard("key",()=>this.handle.key($,Q),void 0)}scroll($,Q,Z,J,Y,X){return this.guard("scroll",()=>this.handle.scroll($,Q,Y??NaN,X??NaN,Z,J),void 0)}digitalCrown($){return this.guard("digitalCrown",()=>this.handle.digitalCrown($),void 0)}orientation($){return this.guard("orientation",()=>this.handle.orientation($),!1)}memoryWarning(){return this.guard("memoryWarning",()=>this.handle.memoryWarning(),void 0)}softwareKeyboard(){return this.guard("softwareKeyboard",()=>this.handle.softwareKeyboard(),void 0)}caDebug($,Q){return this.guard("caDebug",()=>this.handle.caDebug($,Q),!1)}}class I6{handle;constructor($,Q=L$){this.handle=new(_$()).SimCapture($,Q.mjpegFps,Q.mjpegQuality,Q.maxDimension,Q.h264Fps,Q.h264Bitrate)}start(){return this.handle.start()}updateStreamSettings($){return this.handle.updateStreamSettings($.mjpegFps,$.mjpegQuality,$.maxDimension,$.h264Fps,$.h264Bitrate)}subscribeMjpeg($){return this.handle.subscribe(t1,(Q,Z,J,Y)=>{return $({data:Q,width:Z,height:J})})}subscribeAvcc($){return this.handle.subscribe(s1,(Q,Z,J,Y)=>{return $({data:Q,width:Z,height:J,isDescription:(Y&e1)!==0,isKeyframe:(Y&$J)!==0})})}async handleWebRTCOffer($){return JSON.parse(await this.handle.handleWebRTCOffer(JSON.stringify($)))}closeWebRTCSession($){return this.handle.closeWebRTCSession($)}async webRTCSenderStats($){return B2(JSON.parse(await this.handle.webRTCSenderStats($??"")))}screenSize(){return this.handle.screenSize()}stop(){return this.handle.stop()}}function B$($){return _$().axDescribe($)}function R$($){return _$().axFrontmost($)}var r1,t1=0,s1=1,e1=1,$J=2,I4,P6;var N$=d(()=>{P4();r1=o1(import.meta.url),I4={portrait:1,portraitUpsideDown:2,landscapeRight:3,landscapeLeft:4}});function YJ($){return $[0]?.frame??{x:0,y:0,width:1,height:1}}function XJ($,Q){return Math.abs($.x-Q.x)<0.5&&Math.abs($.y-Q.y)<0.5&&Math.abs($.width-Q.width)<0.5&&Math.abs($.height-Q.height)<0.5}function GJ($){let Q=YJ($),Z=[],J=(Y,X)=>{if(Z.length>=x6)return;let G=Y.frame;if(!XJ(G,Q))Z.push({id:Y.AXUniqueId??X,path:X,label:Y.AXLabel??"",value:Y.AXValue??"",role:Y.role_description,type:Y.type,enabled:Y.enabled!==!1,frame:G});for(let K=0;K<Y.children.length&&Z.length<x6;K++)J(Y.children[K],`${X}.${K}`)};for(let Y=0;Y<$.length&&Z.length<x6;Y++)J($[Y],String(Y));return{screen:{width:Q.width,height:Q.height},elements:Z}}async function KJ($){let Q;try{Q=JSON.parse(await B$($))}catch{return{screen:{width:1,height:1},elements:[],errors:[D6]}}return GJ(Q)}function WJ($){return $?.errors?.includes(D6)??!1}function zJ($){return $.elements.length>0&&$.screen.width>1&&$.screen.height>1}async function VJ($){let Q=[];try{let Z=await KJ($);if(Z.errors?.length)return Z;if(!zJ(Z))throw Error(`native AX returned ${Z.elements.length} elements in ${Z.screen.width}x${Z.screen.height} AX space`);return{...Z,errors:Q}}catch(Z){Q.push(Z.message||String(Z))}return{screen:{width:1,height:1},elements:[],errors:Q}}function HJ($){return`data: ${JSON.stringify($)}
@@ -172,7 +172,7 @@ Usage:
172
172
  serve-sim permissions reset <permission|all> <bundle-id> [-d <udid|name>]
173
173
  serve-sim permissions list [bundle-id] [-d <udid|name>]
174
174
 
175
- Permissions: ${t$().join(", ")}`),process.exit(1);let Y=J.device?t(J.device):X0();if(!Y)console.error("No booted simulator. Boot one or pass -d <udid|name>."),process.exit(1);if(J.verb==="list"){let G={udid:Y,bundleId:J.bundleId??null,tcc:kZ(Y,J.bundleId),location:fZ(Y,J.bundleId),notifications:gZ(Y,J.bundleId)};console.log(JSON.stringify(G,null,Q?0:2)),process.exit(0)}let X=J.bundleId;try{if(J.permission==="all")for(let G of t$())S9(Y,"reset",G,void 0,X);else S9(Y,J.verb,J.permission,J.value,X)}catch(G){console.error(G?.message??String(G)),process.exit(1)}if(Q)console.log(JSON.stringify({udid:Y,verb:J.verb,permission:J.permission,value:J.value??null,bundleId:X}));else{let G=J.value?` (${J.value})`:"";console.log(`\uD83D\uDD10 ${J.verb} ${J.permission}${G} for ${X} on ${Y}`)}process.exit(0)}z6();U6();function Y2($,Q={}){let Z=new Date($.timestamp),J=Number.isNaN(Z.getTime())?$.timestamp:Z.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Y=Q.deviceLabel??($.device?$.device.slice(0,8):null),X=$.status==="error"?" failed":"";return[J,Y,`${x1($)}${X?` (${X.trim()})`:""}`].filter(Boolean).join(" ")}function x1($){if($.kind==="tap"){let Q=G$($.details,"current")??G$($.details,"start");return Q?`Tap at ${_6(Q)}`:"Tap"}if($.kind==="drag"){let Q=G$($.details,"start"),Z=G$($.details,"current");if(Q&&Z)return`Drag from ${_6(Q)} to ${_6(Z)}`;return"Drag"}if($.kind==="key"){let Q=S1($.details,"key")??$.action??"key",Z=$.action==="down"?"down":$.action==="up"?"up":$.action;return Z?`Key ${Z} ${J2(Q)}`:`Key ${J2(Q)}`}if($.kind==="rotate"){let Q=$.action?X2($.action):"";return Q?`Rotate ${Q}`:"Rotate"}return k1($.msg??$.summary)}function G$($,Q){let Z=$?.[Q];if(!Z||typeof Z!=="object"||Array.isArray(Z))return null;let J=Z;return typeof J.x==="number"&&typeof J.y==="number"?{x:J.x,y:J.y}:null}function S1($,Q){let Z=$?.[Q];return typeof Z==="string"&&Z.length>0?Z:null}function _6($){return`${Z2($.x)}, ${Z2($.y)}`}function Z2($){if(!Number.isFinite($))return"?";return(Math.round((w1($,0,1)+Number.EPSILON)*100)/100).toFixed(2)}function w1($,Q,Z){return Math.min(Z,Math.max(Q,$))}function k1($){return $.replace(/\b[a-z]+(?:_[a-z]+)+\b/g,X2)}function X2($){return $.replace(/[-_]+/g," ")}function J2($){return{MetaLeft:"Left Command",MetaRight:"Right Command",AltLeft:"Left Option",AltRight:"Right Option",ControlLeft:"Left Control",ControlRight:"Right Control",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",ArrowLeft:"Left Arrow",ArrowRight:"Right Arrow",ArrowUp:"Up Arrow",ArrowDown:"Down Arrow"}[$]??$}N6();P4();function O6($,Q){let Z=$.split(",").map((Y)=>Y.trim()).filter(Boolean),J=Q==="stun"?/^stuns?:/i:/^turns?:/i;if(Z.length===0||Z.length>16||Z.some((Y)=>Y.length>2048||!J.test(Y)))throw Error(`Expected one or more comma-separated ${Q.toUpperCase()} URLs`);return Z}function A6($,Q){let Z=$??{transport:"http"},J=Q??{transport:"http"};if(Z.transport!==J.transport)return!1;let Y=K4(Z),X=K4(J);if(Y.mjpegFps!==X.mjpegFps||Y.mjpegQuality!==X.mjpegQuality||Y.maxDimension!==X.maxDimension||Y.h264Bitrate!==X.h264Bitrate||Y.h264Fps!==X.h264Fps)return!1;if(Z.transport==="http"&&J.transport==="http")return(Z.codec??"auto")===(J.codec??"auto");if(Z.transport!=="webrtc"||J.transport!=="webrtc")return!1;if(Z.codec!==J.codec)return!1;let G=Z.iceServers??[],W=J.iceServers??[];if(G.length!==W.length)return!1;return G.every((K,z)=>{let V=W[z];return K.username===V.username&&K.credential===V.credential&&K.urls.length===V.urls.length&&K.urls.every((H,B)=>H===V.urls[B])})}function U2($,Q){let Z=[];for(let J of $??[])for(let Y of J.urls){let X=Y.toLowerCase();if(Q.some((G)=>X.startsWith(G)))Z.push(Y)}return Z}function c1($){for(let Q of $??[])if(Q.urls.some((Z)=>/^turns?:/i.test(Z)))return Q;return null}function p1($){if(!$)return[];let Q=[];if(Q.push("--transport",$.transport),$.transport==="http"){if($.codec)Q.push("--codec",$.codec)}else{Q.push("--webrtc-codec",$.codec);let Z=U2($.iceServers,["stun:","stuns:"]);if(Z.length)Q.push("--stun-url",Z.join(","));let J=U2($.iceServers,["turn:","turns:"]);if(J.length){Q.push("--turn-url",J.join(","));let Y=c1($.iceServers);if(Y?.username)Q.push("--turn-username",Y.username);if(Y?.credential)Q.push("--turn-credential",Y.credential)}}if($.mjpegFps!==void 0)Q.push("--mjpeg-fps",String($.mjpegFps));if($.mjpegQuality!==void 0)Q.push("--mjpeg-quality",String($.mjpegQuality));if($.maxDimension!==void 0)Q.push("--max-dimension",String($.maxDimension));if($.h264Bitrate!==void 0)Q.push("--video-bitrate",String($.h264Bitrate));if($.h264Fps!==void 0)Q.push("--video-fps",String($.h264Fps));return Q}function _2($,Q,Z,J){return[$,"--port",String(Q),"--host",Z,...p1(J)]}P4();var y0=s4(import.meta.url);function HG(){return"0.1.47"}function f5(){if(!V0(H0))w8(H0,{recursive:!0})}function e($){if($)return x8(i4($));for(let Q of a4()){let Z=x8(Q);if(Z)return Z}return null}var f$={at:0,booted:null};function LG(){let $=Date.now();if(f$.booted&&$-f$.at<1000)return f$.booted;try{let Q=Z0("xcrun simctl list devices booted -j",{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:3000}),Z=JSON.parse(Q),J=new Set;for(let Y of Object.values(Z.devices))for(let X of Y)if(X.state==="Booted")J.add(X.udid);return f$={at:$,booted:J},J}catch{return null}}function x8($){try{if(!V0($))return M0("state file missing %s",$),null;let Q=JSON.parse(o0($,"utf-8"));try{process.kill(Q.pid,0)}catch{return M0("helper pid %d dead, removing stale state %s",Q.pid,$),i0($),null}let Z=LG();if(Z&&!Z.has(Q.device)){if(Q.pid===process.pid){M0("dropping own stale state for non-booted device %s",Q.device);try{i0($)}catch{}return null}M0("helper pid %d bound to non-booted device %s — killing stale helper",Q.pid,Q.device),console.error(`[serve-sim] Helper pid ${Q.pid} is bound to device ${Q.device} which is no longer booted — killing stale helper.`);try{process.kill(Q.pid,"SIGTERM")}catch{}try{i0($)}catch{}return null}return M0("state ok pid=%d device=%s port=%d",Q.pid,Q.device,Q.port),Q}catch(Q){return M0("readStateFile threw for %s: %o",$,Q),null}}function c4(){let $=[];for(let Q of a4()){let Z=x8(Q);if(Z)$.push(Z)}return $}function MG($){f5(),o4($),M0("wrote state pid=%d device=%s port=%d",$.pid,$.device,$.port)}function D0($){if($){M0("clearState device=%s",$);try{i0(i4($))}catch{}}else{M0("clearState (all)");for(let Q of a4())try{i0(Q)}catch{}}}function f8(){try{let $=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Q=JSON.parse($),Z=Object.keys(Q.devices).filter((J)=>/SimRuntime\.iOS-/i.test(J)).sort((J,Y)=>{let X=(J.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number),G=(Y.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number);return(G[0]??0)-(X[0]??0)||(G[1]??0)-(X[1]??0)});for(let J of Z){let X=(Q.devices[J]??[]).find((G)=>G.isAvailable!==!1&&/^iPhone\b/i.test(G.name));if(X)return{udid:X.udid,name:X.name}}}catch{}return null}function w5($){return b5().get($)??null}function b5(){let $=new Map;try{let Q=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Z=JSON.parse(Q);for(let J of Object.values(Z.devices))for(let Y of J)$.set(Y.udid,Y.name)}catch{}return $}function v5($){try{let Q=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Z=JSON.parse(Q);for(let J of Object.values(Z.devices))for(let Y of J)if(Y.udid===$)return Y.state==="Booted"}catch{}return!1}function S8($){try{return process.kill($,0),!0}catch{return!1}}function b$($){try{process.kill($,"SIGTERM")}catch{return}let Q=Date.now()+500;while(Date.now()<Q)try{process.kill($,0),v0(25)}catch{return}try{process.kill($,"SIGKILL")}catch{}let Z=Date.now()+500;while(Date.now()<Z)try{process.kill($,0),v0(25)}catch{return}}function UG($){if(!v5($))try{Z0(`xcrun simctl boot ${$}`,{encoding:"utf-8",stdio:"pipe"})}catch(Q){let Z=(Q.stderr??Q.message??"").toLowerCase();if(!Z.includes("booted")&&!Z.includes("current state"))throw Error(`Failed to boot device ${$}: ${Q.stderr||Q.message}`)}try{Z0("open -ga Simulator",{encoding:"utf-8",stdio:"pipe",timeout:3000})}catch{}}function _G(){let $=VG();for(let Q of Object.values($))for(let Z of Q??[])if(Z.family==="IPv4"&&!Z.internal)return Z.address;return null}async function h5($){let Q=new Set(c4().map((Z)=>Z.port));for(let Z=$;Z<$+100;Z++){if(Q.has(Z))continue;if(await D9(Z))return Z}throw Error(`No available port found in range ${$}-${$+99}`)}async function BG($){UG($);try{Z0(`xcrun simctl bootstatus ${$} -b`,{encoding:"utf-8",stdio:"pipe",timeout:60000})}catch(Q){if(!v5($))console.error(`Device ${$} failed to reach booted state: ${Q.stderr||Q.message}`),process.exit(1)}}function RG($){if(process.argv[0]&&/(^|\/)serve-sim$/.test(process.argv[0]))return{command:process.argv[0],args:$};return{command:process.argv[0],args:[process.argv[1],...$]}}async function NG($,Q=150000){let Z=Date.now();while(Date.now()-Z<Q){let J=e($);if(J)return J;await new Promise((Y)=>setTimeout(Y,200))}return null}async function g5($,Q,Z){M6("startHelper udid=%s port=%d detach=%s",$,Q,Z.detach);let J="127.0.0.1";f5(),D0($),P9(Q);let Y=B0(H0,`server-${$}.log`),X=k8(Y,"w"),{command:G,args:W}=RG(_2($,Q,J,Z.stream)),K=k5(G,W,{detached:Z.detach,stdio:["ignore",X,X]});if(y8(X),Z.detach)K.unref();let z=await NG($);if(!z){if(K.pid)b$(K.pid);let V="";try{V=o0(Y,"utf-8").trim()}catch{}console.error(V?`Preview server failed:
175
+ Permissions: ${t$().join(", ")}`),process.exit(1);let Y=J.device?t(J.device):X0();if(!Y)console.error("No booted simulator. Boot one or pass -d <udid|name>."),process.exit(1);if(J.verb==="list"){let G={udid:Y,bundleId:J.bundleId??null,tcc:kZ(Y,J.bundleId),location:fZ(Y,J.bundleId),notifications:gZ(Y,J.bundleId)};console.log(JSON.stringify(G,null,Q?0:2)),process.exit(0)}let X=J.bundleId;try{if(J.permission==="all")for(let G of t$())S9(Y,"reset",G,void 0,X);else S9(Y,J.verb,J.permission,J.value,X)}catch(G){console.error(G?.message??String(G)),process.exit(1)}if(Q)console.log(JSON.stringify({udid:Y,verb:J.verb,permission:J.permission,value:J.value??null,bundleId:X}));else{let G=J.value?` (${J.value})`:"";console.log(`\uD83D\uDD10 ${J.verb} ${J.permission}${G} for ${X} on ${Y}`)}process.exit(0)}z6();U6();function Y2($,Q={}){let Z=new Date($.timestamp),J=Number.isNaN(Z.getTime())?$.timestamp:Z.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),Y=Q.deviceLabel??($.device?$.device.slice(0,8):null),X=$.status==="error"?" failed":"";return[J,Y,`${x1($)}${X?` (${X.trim()})`:""}`].filter(Boolean).join(" ")}function x1($){if($.kind==="tap"){let Q=G$($.details,"current")??G$($.details,"start");return Q?`Tap at ${_6(Q)}`:"Tap"}if($.kind==="drag"){let Q=G$($.details,"start"),Z=G$($.details,"current");if(Q&&Z)return`Drag from ${_6(Q)} to ${_6(Z)}`;return"Drag"}if($.kind==="key"){let Q=S1($.details,"key")??$.action??"key",Z=$.action==="down"?"down":$.action==="up"?"up":$.action;return Z?`Key ${Z} ${J2(Q)}`:`Key ${J2(Q)}`}if($.kind==="rotate"){let Q=$.action?X2($.action):"";return Q?`Rotate ${Q}`:"Rotate"}return k1($.msg??$.summary)}function G$($,Q){let Z=$?.[Q];if(!Z||typeof Z!=="object"||Array.isArray(Z))return null;let J=Z;return typeof J.x==="number"&&typeof J.y==="number"?{x:J.x,y:J.y}:null}function S1($,Q){let Z=$?.[Q];return typeof Z==="string"&&Z.length>0?Z:null}function _6($){return`${Z2($.x)}, ${Z2($.y)}`}function Z2($){if(!Number.isFinite($))return"?";return(Math.round((w1($,0,1)+Number.EPSILON)*100)/100).toFixed(2)}function w1($,Q,Z){return Math.min(Z,Math.max(Q,$))}function k1($){return $.replace(/\b[a-z]+(?:_[a-z]+)+\b/g,X2)}function X2($){return $.replace(/[-_]+/g," ")}function J2($){return{MetaLeft:"Left Command",MetaRight:"Right Command",AltLeft:"Left Option",AltRight:"Right Option",ControlLeft:"Left Control",ControlRight:"Right Control",ShiftLeft:"Left Shift",ShiftRight:"Right Shift",ArrowLeft:"Left Arrow",ArrowRight:"Right Arrow",ArrowUp:"Up Arrow",ArrowDown:"Down Arrow"}[$]??$}N6();P4();function O6($,Q){let Z=$.split(",").map((Y)=>Y.trim()).filter(Boolean),J=Q==="stun"?/^stuns?:/i:/^turns?:/i;if(Z.length===0||Z.length>16||Z.some((Y)=>Y.length>2048||!J.test(Y)))throw Error(`Expected one or more comma-separated ${Q.toUpperCase()} URLs`);return Z}function A6($,Q){let Z=$??{transport:"http"},J=Q??{transport:"http"};if(Z.transport!==J.transport)return!1;let Y=K4(Z),X=K4(J);if(Y.mjpegFps!==X.mjpegFps||Y.mjpegQuality!==X.mjpegQuality||Y.maxDimension!==X.maxDimension||Y.h264Bitrate!==X.h264Bitrate||Y.h264Fps!==X.h264Fps)return!1;if(Z.transport==="http"&&J.transport==="http")return(Z.codec??"auto")===(J.codec??"auto");if(Z.transport!=="webrtc"||J.transport!=="webrtc")return!1;if(Z.codec!==J.codec)return!1;let G=Z.iceServers??[],W=J.iceServers??[];if(G.length!==W.length)return!1;return G.every((K,z)=>{let V=W[z];return K.username===V.username&&K.credential===V.credential&&K.urls.length===V.urls.length&&K.urls.every((H,B)=>H===V.urls[B])})}function U2($,Q){let Z=[];for(let J of $??[])for(let Y of J.urls){let X=Y.toLowerCase();if(Q.some((G)=>X.startsWith(G)))Z.push(Y)}return Z}function c1($){for(let Q of $??[])if(Q.urls.some((Z)=>/^turns?:/i.test(Z)))return Q;return null}function p1($){if(!$)return[];let Q=[];if(Q.push("--transport",$.transport),$.transport==="http"){if($.codec)Q.push("--codec",$.codec)}else{Q.push("--webrtc-codec",$.codec);let Z=U2($.iceServers,["stun:","stuns:"]);if(Z.length)Q.push("--stun-url",Z.join(","));let J=U2($.iceServers,["turn:","turns:"]);if(J.length){Q.push("--turn-url",J.join(","));let Y=c1($.iceServers);if(Y?.username)Q.push("--turn-username",Y.username);if(Y?.credential)Q.push("--turn-credential",Y.credential)}}if($.mjpegFps!==void 0)Q.push("--mjpeg-fps",String($.mjpegFps));if($.mjpegQuality!==void 0)Q.push("--mjpeg-quality",String($.mjpegQuality));if($.maxDimension!==void 0)Q.push("--max-dimension",String($.maxDimension));if($.h264Bitrate!==void 0)Q.push("--video-bitrate",String($.h264Bitrate));if($.h264Fps!==void 0)Q.push("--video-fps",String($.h264Fps));return Q}function _2($,Q,Z,J){return[$,"--port",String(Q),"--host",Z,...p1(J)]}P4();var y0=s4(import.meta.url);function HG(){return"0.1.48"}function f5(){if(!V0(H0))w8(H0,{recursive:!0})}function e($){if($)return x8(i4($));for(let Q of a4()){let Z=x8(Q);if(Z)return Z}return null}var f$={at:0,booted:null};function LG(){let $=Date.now();if(f$.booted&&$-f$.at<1000)return f$.booted;try{let Q=Z0("xcrun simctl list devices booted -j",{encoding:"utf-8",stdio:["ignore","pipe","pipe"],timeout:3000}),Z=JSON.parse(Q),J=new Set;for(let Y of Object.values(Z.devices))for(let X of Y)if(X.state==="Booted")J.add(X.udid);return f$={at:$,booted:J},J}catch{return null}}function x8($){try{if(!V0($))return M0("state file missing %s",$),null;let Q=JSON.parse(o0($,"utf-8"));try{process.kill(Q.pid,0)}catch{return M0("helper pid %d dead, removing stale state %s",Q.pid,$),i0($),null}let Z=LG();if(Z&&!Z.has(Q.device)){if(Q.pid===process.pid){M0("dropping own stale state for non-booted device %s",Q.device);try{i0($)}catch{}return null}M0("helper pid %d bound to non-booted device %s — killing stale helper",Q.pid,Q.device),console.error(`[serve-sim] Helper pid ${Q.pid} is bound to device ${Q.device} which is no longer booted — killing stale helper.`);try{process.kill(Q.pid,"SIGTERM")}catch{}try{i0($)}catch{}return null}return M0("state ok pid=%d device=%s port=%d",Q.pid,Q.device,Q.port),Q}catch(Q){return M0("readStateFile threw for %s: %o",$,Q),null}}function c4(){let $=[];for(let Q of a4()){let Z=x8(Q);if(Z)$.push(Z)}return $}function MG($){f5(),o4($),M0("wrote state pid=%d device=%s port=%d",$.pid,$.device,$.port)}function D0($){if($){M0("clearState device=%s",$);try{i0(i4($))}catch{}}else{M0("clearState (all)");for(let Q of a4())try{i0(Q)}catch{}}}function f8(){try{let $=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Q=JSON.parse($),Z=Object.keys(Q.devices).filter((J)=>/SimRuntime\.iOS-/i.test(J)).sort((J,Y)=>{let X=(J.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number),G=(Y.match(/iOS-(\d+)-(\d+)/)??[]).slice(1).map(Number);return(G[0]??0)-(X[0]??0)||(G[1]??0)-(X[1]??0)});for(let J of Z){let X=(Q.devices[J]??[]).find((G)=>G.isAvailable!==!1&&/^iPhone\b/i.test(G.name));if(X)return{udid:X.udid,name:X.name}}}catch{}return null}function w5($){return b5().get($)??null}function b5(){let $=new Map;try{let Q=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Z=JSON.parse(Q);for(let J of Object.values(Z.devices))for(let Y of J)$.set(Y.udid,Y.name)}catch{}return $}function v5($){try{let Q=Z0("xcrun simctl list devices -j",{encoding:"utf-8"}),Z=JSON.parse(Q);for(let J of Object.values(Z.devices))for(let Y of J)if(Y.udid===$)return Y.state==="Booted"}catch{}return!1}function S8($){try{return process.kill($,0),!0}catch{return!1}}function b$($){try{process.kill($,"SIGTERM")}catch{return}let Q=Date.now()+500;while(Date.now()<Q)try{process.kill($,0),v0(25)}catch{return}try{process.kill($,"SIGKILL")}catch{}let Z=Date.now()+500;while(Date.now()<Z)try{process.kill($,0),v0(25)}catch{return}}function UG($){if(!v5($))try{Z0(`xcrun simctl boot ${$}`,{encoding:"utf-8",stdio:"pipe"})}catch(Q){let Z=(Q.stderr??Q.message??"").toLowerCase();if(!Z.includes("booted")&&!Z.includes("current state"))throw Error(`Failed to boot device ${$}: ${Q.stderr||Q.message}`)}try{Z0("open -ga Simulator",{encoding:"utf-8",stdio:"pipe",timeout:3000})}catch{}}function _G(){let $=VG();for(let Q of Object.values($))for(let Z of Q??[])if(Z.family==="IPv4"&&!Z.internal)return Z.address;return null}async function h5($){let Q=new Set(c4().map((Z)=>Z.port));for(let Z=$;Z<$+100;Z++){if(Q.has(Z))continue;if(await D9(Z))return Z}throw Error(`No available port found in range ${$}-${$+99}`)}async function BG($){UG($);try{Z0(`xcrun simctl bootstatus ${$} -b`,{encoding:"utf-8",stdio:"pipe",timeout:60000})}catch(Q){if(!v5($))console.error(`Device ${$} failed to reach booted state: ${Q.stderr||Q.message}`),process.exit(1)}}function RG($){if(process.argv[0]&&/(^|\/)serve-sim$/.test(process.argv[0]))return{command:process.argv[0],args:$};return{command:process.argv[0],args:[process.argv[1],...$]}}async function NG($,Q=150000){let Z=Date.now();while(Date.now()-Z<Q){let J=e($);if(J)return J;await new Promise((Y)=>setTimeout(Y,200))}return null}async function g5($,Q,Z){M6("startHelper udid=%s port=%d detach=%s",$,Q,Z.detach);let J="127.0.0.1";f5(),D0($),P9(Q);let Y=B0(H0,`server-${$}.log`),X=k8(Y,"w"),{command:G,args:W}=RG(_2($,Q,J,Z.stream)),K=k5(G,W,{detached:Z.detach,stdio:["ignore",X,X]});if(y8(X),Z.detach)K.unref();let z=await NG($);if(!z){if(K.pid)b$(K.pid);let V="";try{V=o0(Y,"utf-8").trim()}catch{}console.error(V?`Preview server failed:
176
176
  ${V}`:"Preview server failed to start"),process.exit(1)}return Z.detach?{pid:z.pid}:{pid:z.pid,child:K}}async function FG($,Q,Z,J,Y=!1){L6("follow devices=%o startPort=%d",$,Q);let X=$.length>0?$.map(t):(()=>{let H=X0();if(H)return[H];let B=f8();if(!B)console.error("No device specified and no available iOS simulator found."),process.exit(1);if(!Z)console.log(`No booted simulator — booting ${B.name}...`);return[B.udid]})(),G=new Map,W=[],K=Q;for(let H of X){let B=e(H);if(B)if(Y&&!A6(B.streamSettings,J))b$(B.pid),D0(H);else{if(!Z){let D=w5(H)??H;if(X.length>1)console.log(`
177
177
  ==> ${D} (${H}) <==`);console.log(` Already running on port ${B.port}`),console.log(` Stream: ${B.streamUrl}`),console.log(` WebSocket: ${B.wsUrl}`)}W.push(B);continue}K=await h5(K);let{child:N}=await g5(H,K,{detach:!1,stream:J});if(N)G.set(H,N);let M=e(H)??Q4(H,K,"/","127.0.0.1");if(W.push(M),!Z){let D=w5(H)??H;if(X.length>1)console.log(`
178
178
  ==> ${D} (${H}) <==`);console.log(` Stream: ${M.streamUrl}`),console.log(` WebSocket: ${M.wsUrl}`),console.log(` Port: ${K}`)}K++}if(W.length===1){let H=W[0];console.log(JSON.stringify({url:H.url,streamUrl:H.streamUrl,wsUrl:H.wsUrl,port:H.port,device:H.device}))}else console.log(JSON.stringify({devices:W.map((H)=>({url:H.url,streamUrl:H.streamUrl,wsUrl:H.wsUrl,port:H.port,device:H.device}))}));if(G.size===0)return;let z=!1,V=(H)=>{if(z)return;if(z=!0,!Z)console.log(`
@@ -227,5 +227,5 @@ Examples:
227
227
  serve-sim --list Show all running streams
228
228
  serve-sim --kill Stop all streams`).action(async($,Q)=>{if(Q.list!==void 0){OG(typeof Q.list==="string"?Q.list:void 0);return}if(Q.kill!==void 0){AG(typeof Q.kill==="string"?Q.kill:void 0);return}if(Q.transport!=="http"&&Q.transport!=="webrtc")console.error("--transport must be one of: http, webrtc."),process.exit(1);let Z=(B)=>J0.getOptionValueSource(B)==="cli",J=["webrtcCodec","stunUrl","turnUrl","turnUsername","turnCredential"].some(Z);if(Q.transport==="http"&&J)console.error("WebRTC options require --transport webrtc."),process.exit(1);if(Q.transport==="webrtc"&&Z("codec"))console.error("--codec configures HTTP streaming; use --webrtc-codec with --transport webrtc."),process.exit(1);if(Q.turnUsername===void 0!==(Q.turnCredential===void 0))console.error("--turn-username and --turn-credential must be provided together."),process.exit(1);if((Q.turnUsername!==void 0||Q.turnCredential!==void 0)&&!Q.turnUrl)console.error("--turn-username and --turn-credential require --turn-url."),process.exit(1);let Y=Q.stunUrl??[],X=[];if(Y.length)X.push({urls:Y});if(Q.turnUrl)X.push({urls:Q.turnUrl,username:Q.turnUsername,credential:Q.turnCredential});let G=["mjpegFps","mjpegQuality","maxDimension","videoBitrate","videoFps"],W={...Z("mjpegFps")?{mjpegFps:Q.mjpegFps}:{},...Z("mjpegQuality")?{mjpegQuality:Q.mjpegQuality}:{},...Z("maxDimension")?{maxDimension:Q.maxDimension}:{},...Z("videoBitrate")?{h264Bitrate:Q.videoBitrate}:{},...Z("videoFps")?{h264Fps:Q.videoFps}:{}},K=Q.transport==="webrtc"?{transport:"webrtc",codec:Q.webrtcCodec,...X.length?{iceServers:X}:{},...W}:{transport:"http",codec:Q.codec,...W},z=Q.port,V=Z("transport")||Z("codec")||J||G.some(Z),H=Q.debugStream?.trim();if(Q.debugStream!==void 0){let B=!H?"--debug-stream needs a file path, for example --debug-stream ./stream.ndjson":Q.detach||Q.preview===!1?"--debug-stream needs the preview server, so drop --detach/--no-preview.":K.transport!=="webrtc"?"--debug-stream records sender statistics, which only exist on --transport webrtc.":null;if(B!==null)console.error(B),process.exit(1)}if(Q.detach){let B=await jG($,z??3100,K,V);TG(B)}else if(Q.preview===!1)await FG($,z??3100,!!Q.quiet,K,V);else await nG(z??3200,$,z!==void 0,Q.host,{stream:K,metricsCorsOrigins:Q.metricsCorsOrigin,debugStreamPath:H})});var f0=["-d, --device <udid>","Target a specific simulator (udid or name)"];J0.command("gesture").description("Send a touch gesture").argument("<json>",`Gesture JSON, e.g. '{"type":"begin","x":0.5,"y":0.5}'`).option(...f0).action(($,Q)=>PG($,Q.device));J0.command("tap").description("Tap at normalized 0..1 coords").argument("<x>","X coord, normalized 0..1").argument("<y>","Y coord, normalized 0..1").option(...f0).action(($,Q,Z)=>qG($,Q,Z.device));J0.command("button").description("Send a hardware button press").argument("[name]","Button name","home").option(...f0).action(($,Q)=>wG($,Q.device));J0.command("type").description("Type text (US keyboard only)").argument("[text...]","Text to type").option(...f0).option("--stdin","Read text from stdin").option("--file <path>","Read text from a file").action(($,Q)=>IG($,{device:Q.device,stdin:Q.stdin,file:Q.file}));J0.command("rotate").description("Set device orientation (portrait|portrait_upside_down|landscape_left|landscape_right)").argument("<orientation>").option(...f0).action(($,Q)=>xG($,Q.device));J0.command("ca-debug").description("Toggle a CoreAnimation debug render flag (blended|copies|misaligned|offscreen|slow-animations)").argument("<option>").argument("<state>","on|off").option(...f0).action(($,Q,Z)=>kG($,Q,Z.device));J0.command("memory-warning").description("Simulate a memory warning on the device").option(...f0).action(($)=>yG($.device));J0.command("event-log").description("Show recent simulator events").option(...f0).option("-j, --json","Print JSON").option("-n, --limit <count>","Maximum number of events").action(($)=>DG($.device,{json:$.json,limit:$.limit}));J0.command("camera").description("Inject a synthetic camera feed and launch an app (see `camera --help`)").allowUnknownOption(!0).helpOption(!1).argument("[args...]").action(($)=>pG($));J0.command("permissions").description("Manage app permissions (see `permissions` with no args for usage)").allowUnknownOption(!0).helpOption(!1).argument("[args...]").action(($)=>h9($));J0.command("ui").description("Get or set simulator-wide UI options (see `ui --help`)").allowUnknownOption(!0).helpOption(!1).argument("[args...]").action(($)=>n9($));await J0.parseAsync(process.argv);
229
229
 
230
- //# debugId=EF488BFB505B147764756E2164756E21
230
+ //# debugId=5A23146B989C8C7364756E2164756E21
231
231
  //# sourceMappingURL=serve-sim.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expo/serve-sim",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "author": {
6
6
  "name": "Evan Bacon",