expo-device-hub 0.23.0 → 0.23.1
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/dist/client/_expo/static/js/web/{index-fc17c59814091405506ac8475e8e9765.js → index-27f4b6af29200f07e5fc6cf0b57414a7.js} +1 -1
- package/dist/client/index.html +1 -1
- package/package.json +1 -1
- package/vendor/serve-emu/dist/device-session-state.js +13 -4
- package/vendor/serve-emu/dist/display-orientation.js +35 -6
- package/vendor/serve-emu/dist/middleware.js +3 -2
- package/vendor/serve-emu/dist/screenshot-metadata.js +13 -0
- package/vendor/serve-emu/dist/screenshot-response.js +52 -3
- package/vendor/serve-emu/dist/server.js +3 -3
- package/vendor/serve-emu/dist/shared/api-contracts.js +32 -1
- package/vendor/serve-emu/dist/ui/assets/{index-C__KVGN2.js → index-Ui5WoIwK.js} +7 -7
- package/vendor/serve-sim/dist/middleware.js +113 -113
- package/vendor/serve-sim/dist/native/serve-sim-native.node +0 -0
- package/vendor/serve-sim/dist/serve-sim.js +124 -124
|
@@ -273,7 +273,7 @@ __d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{v
|
|
|
273
273
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.useAppPermissions=function({active:u,backend:c,appId:l}){const[o,f]=(0,s.useState)(null),[p,I]=(0,s.useState)(n.NO_PENDING_PERMISSION_WRITES),[P,_]=(0,s.useState)(null),E=(0,s.useRef)(new t.KeyedWriteTracker),N=(0,s.useRef)({}),S=(0,s.useMemo)(()=>u&&c&&l?{backend:c,appId:l}:null,[u,c,l]),b=(0,s.useRef)(S);(0,s.useEffect)(()=>{b.current=S,E.current.reset(),N.current={},f(null),I(n.NO_PENDING_PERMISSION_WRITES),_(null)},[S]);const R=s=>{const t=s.pending;I(0===t.size?n.NO_PENDING_PERMISSION_WRITES:t)},k=(0,s.useCallback)((s,t)=>{if(!S)return Promise.resolve();const u=E.current,c=N.current;return t(S.backend,S.appId).then(t=>{if(S!==b.current)return;const l=(0,n.heldPermissionIds)(u.pending,c,N.current,s);f(s=>(0,n.applyPermissionsRead)(s,t,l)),_(null)},s=>{S===b.current&&_(s instanceof Error?s.message:"Permission request failed")})},[S]),O=(0,s.useCallback)((s,n)=>{const t=E.current,u=t.pending;if(0===s.length||s.some(s=>u.has(s)))return;const c=s.flatMap(s=>{const n=t.start(s);return n?[n]:[]}),l=Object.assign({},N.current);for(const n of s)l[n]=(l[n]??0)+1;N.current=l,_(null),R(t),k(s,n).finally(()=>{let s=!1;for(const n of c)s=t.finish(n)||s;s&&R(t)})},[k]),h=(0,s.useCallback)((s,n)=>O([s],(t,u)=>t.write(u,s,n)),[O]),M=(0,s.useCallback)(()=>O((o??[]).map(s=>s.id),(s,n)=>s.reset(n)),[O,o]),C=(0,s.useCallback)(()=>{k([],(s,n)=>s.list(n))},[k]);return{permissions:o,permissionsPending:p,permissionsError:P,setPermission:h,resetPermissions:M,refreshPermissions:C}};var s=r(d[0]),n=r(d[1]),t=r(d[2])},207,[38,170,194]);
|
|
274
274
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.useStreamSettingsResource=function({url:u,initialSettings:s,parse:c,toPatch:o,fetchImpl:l=fetch}){const[f,S]=(0,t.useState)(s),[b,E]=(0,t.useState)(!1),h=(0,t.useRef)(0),w=(0,t.useRef)(s),p=(0,t.useRef)(!1),C=(0,t.useRef)(null),T=(0,t.useRef)(null),_=(0,t.useCallback)(()=>{++h.current,C.current?.abort(),C.current=null,T.current?.abort(),T.current=null},[]),y=(0,t.useCallback)(async t=>{if(!u||C.current||T.current)return;const s=++h.current,o=new AbortController;C.current=o;try{const t=await l(u,{cache:"no-store",signal:o.signal});if(!t.ok)throw new Error(`Stream settings request failed (${t.status})`);const f=c(await t.json(),w.current??n.DEFAULT_DEVICE_STREAM_SETTINGS);if(!f)throw new Error("Stream settings request returned an invalid response");o.signal.aborted||h.current!==s||(w.current=f,S(t=>(0,n.sameDeviceStreamSettings)(t,f)?t:f))}catch{}finally{C.current===o&&(C.current=null),t&&!o.signal.aborted&&h.current===s&&(p.current=!1,E(!1))}},[l,c,u]);(0,t.useEffect)(()=>(_(),w.current=s,S(s),u?(p.current=!0,E(!0),y(!0),_):(p.current=!1,void E(!1))),[_,s,y,u]);const R=(0,t.useCallback)(t=>{const s=o(t);if(!u||!s||p.current||T.current)return;const f=w.current??n.DEFAULT_DEVICE_STREAM_SETTINGS,b=c(Object.assign({},f,s),f);if(!b)return;C.current?.abort(),C.current=null;const _=++h.current,y=new AbortController;return T.current=y,p.current=!0,w.current=b,S(b),E(!0),l(u,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(s),signal:y.signal}).then(async t=>{if(!t.ok)throw new Error(`Stream settings update failed (${t.status})`);const n=c(await t.json(),b);if(!n)throw new Error("Stream settings update returned an invalid response");return!y.signal.aborted&&h.current===_&&(w.current=n,S(n),!0)}).catch(()=>(y.signal.aborted||h.current!==_||(w.current=f,S(f)),!1)).finally(()=>{T.current===y&&(T.current=null),y.signal.aborted||h.current!==_||(p.current=!1,E(!1))})},[l,c,o,u]),A=(0,t.useCallback)(()=>{y(!1)},[y]);return{streamSettings:f,streamSettingsPending:b,updateStreamSettings:R,refreshStreamSettings:A}};var t=r(d[0]),n=r(d[1])},208,[38,189]);
|
|
275
275
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.useDeviceSettingsReadStatus=function(s){const[u,l]=(0,t.useState)({scope:null,status:"idle"}),n=(0,t.useCallback)(()=>{l({scope:s,status:null===s?"idle":"loading"})},[s]),c=(0,t.useCallback)(t=>{l(u=>null===s||u.scope!==s||u.status===t?u:{scope:s,status:t})},[s]);return{deviceSettingsStatus:null===s?"idle":u.scope===s?u.status:"loading",resetRead:n,settleRead:c}};var t=r(d[0])},209,[38]);
|
|
276
|
-
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.fetchScreenshot=async function(
|
|
276
|
+
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.fetchScreenshot=async function(s,c,u=fetch){const l=`${(0,t.apiUrl)(s,"/api/screenshot")}${c?`?device=${encodeURIComponent(c)}`:""}`;try{const t=await u(l,{method:"POST",cache:"no-store"});if(!t.ok)return null;const s=o(t.headers);return Object.assign({blob:await t.blob(),artifact:n(t.headers)},s?{metadata:s}:{})}catch{return null}};var t=r(d[0]);function n(t){const n=t.get("X-Expo-Screenshot-Artifact");if(null===n)return null;if("failed"===n){const o=t.get("X-Expo-Screenshot-Artifact-Error")?.trim();return o?{status:n,error:o}:{status:n}}return"saved"===n||"disabled"===n?{status:n}:(console.warn(`Ignoring unknown X-Expo-Screenshot-Artifact value: ${n}`),null)}function o(t){const n=t.get("X-Expo-Screenshot-Metadata");if(n&&!(n.length>1024))try{const t=JSON.parse(n);if("object"!=typeof t||null===t||Array.isArray(t))return;const o=t,s=t=>"number"==typeof t&&Number.isSafeInteger(t)&&t>=0;if(!s(o.width)||!s(o.height)||void 0!==o.screen&&"inner"!==o.screen&&"outer"!==o.screen)return;const c=o.displayRotation;if(null!==c&&"portrait"!==c&&"portrait-upside-down"!==c&&"landscape-left"!==c&&"landscape-right"!==c)return;return Object.assign({width:o.width,height:o.height},void 0===o.screen?{}:{screen:o.screen},{displayRotation:c})}catch{return}}},210,[182]);
|
|
277
277
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.preferredVideoCodecs=T,e.buildWebRtcOfferPayload=C,e.isRetryableWebRtcOfferStatus=W,e.shouldFallbackCodecAfterFirstFrameTimeout=function(t,n){return t&&"codec"===(0,s.webRtcFailureDisposition)("first-frame-timeout",n)},e.videoRtpArriving=E,e.useWebRtcStream=function({offerUrl:t,closeUrl:c,closeBeaconUrl:k=c,statsUrl:L="",enabled:P,codec:F,iceServers:O,iceTransportPolicy:D="all",sendIceServersInOffer:U=!0,allowCodecFallback:A=!0,expectContinuousFrames:$=!0,judgeStalls:j=!0,onKeyframeNeeded:M,onBeforeDisconnect:H,fetchImpl:B=fetch,transportLocked:_=!1,raiseH264Level:x=!1}){const[q,G]=(0,o.useState)(null),[N,V]=(0,o.useState)(null),[z,J]=(0,o.useState)(null),[K,Q]=(0,o.useState)(!1),[X,Y]=(0,o.useState)(null),[Z,ee]=(0,o.useState)(!1),[te,ne]=(0,o.useState)(0),re=(0,o.useRef)(void 0),ie=(0,o.useRef)(j);ie.current=j;const oe=(0,o.useRef)(null),ce=(0,o.useRef)(null),se=(0,o.useRef)(!1),ae=(0,o.useRef)(0),ue=(0,o.useRef)(0),de=(0,o.useRef)(null),le=(0,o.useRef)(H),fe=(0,o.useRef)($),ve=(0,o.useRef)(null);(0,o.useLayoutEffect)(()=>{fe.current=$,ve.current?.setExpectContinuousFrames($)},[$]),(0,o.useLayoutEffect)(()=>{le.current=H},[H]);const me=(0,o.useRef)(new Set),pe=(0,o.useCallback)(t=>(me.current.add(t),()=>{me.current.delete(t)}),[]),be=(0,l.useWebRtcStreamStats)(X,L,ae,Z,B,pe),we=(0,o.useCallback)((t=1)=>{ae.current+=t,se.current||(se.current=!0,ue.current=0,void 0!==re.current&&(window.clearTimeout(re.current),re.current=void 0),V(null),J(null),Q(!1))},[]),ye=(0,o.useCallback)(()=>{ue.current=0,G(null),ne(t=>t+1)},[]);return(0,o.useEffect)(()=>{ue.current=0,de.current=null},[P,t,c,k,L,F,O,D,U,A,$,_,x]),(0,o.useEffect)(()=>{j?oe.current?.():ce.current?.()},[j]),(0,o.useEffect)(()=>{if(!P||!t)return;if(V(null),Q(!1),"undefined"==typeof RTCPeerConnection||"undefined"==typeof RTCRtpReceiver)return G(null),Y(null),J("WebRTC is not supported by this browser."),void V({sessionId:I(),kind:"permanent"});let o,$,j=!1,H=null,q=!1,N=null,z=!1,K=!1,X=!1,Z=!1,ee=0;const te=new AbortController,ae=I(),pe=O?.length?O:f;G(null),V(null),J(null),se.current=!1,void 0!==re.current&&(window.clearTimeout(re.current),re.current=void 0);const be=(t=!1)=>N||(N=(0,u.closeWebRtcSession)({url:c,beaconUrl:k,sessionId:ae,keepalive:t,fetchImpl:B}),N),we=()=>{be(!0)};window.addEventListener("pagehide",we),window.addEventListener("beforeunload",we);const ye=()=>{ee+=1,void 0!==re.current&&(window.clearTimeout(re.current),re.current=void 0)},ge=()=>{void 0!==$&&(window.clearTimeout($),$=void 0)},Re=()=>{if(ye(),ge(),!q){if(q=!0,H)try{le.current?.()}catch{}G(null),Y(t=>t?.sessionId===ae?null:t),H?.close()}},Se=()=>{try{M?.()}catch{}},he=t=>{j||z||(z=!0,Q(!1),J(t),V({sessionId:ae,kind:"permanent"}),Re(),be())},Te=()=>{j||z||(z=!0,Q(!1),Re(),be().finally(()=>{j||V({sessionId:ae,kind:"codec",codec:F})}))},Ce=t=>{if(j||z)return;z=!0,V(null);const n=ue.current++,c=Math.min(R*2**Math.min(n,4),S);Se(),J(`${t} Retrying...`),Q(!0),Re(),be(),o=window.setTimeout(()=>{j||ne(t=>t+1)},c)},We=async()=>{if(!L)return null;try{return await(0,l.requestWebRtcServerStats)(L,ae,AbortSignal.any([te.signal,AbortSignal.timeout(2e3)]),B)}catch{return null}},Ee=()=>{j||z||document.hidden||!ie.current||se.current||!K||!X||void 0!==re.current||(re.current=window.setTimeout(()=>{if(re.current=void 0,j||se.current)return;const t=ee;(async()=>{const n=await E(H);if(j||z||se.current||t!==ee)return;const o=await We();if(j||z||document.hidden||!ie.current||se.current||t!==ee)return;if(!0===o?.capture?.rebooting)return Z=!1,void Ee();const c=o?.encoder?.framesEncoded,u=n||"number"!=typeof c?null:c>0,l=H?.connectionState??"closed",f=(0,s.webRtcFailureDisposition)("first-frame-timeout",l,{mediaArriving:n,senderEncoding:u});"wait"!==f||Z?"transport"!==f&&A?(Se(),Te()):Ce("WebRTC did not establish a video path."):(Z=!0,Ee())})()},b))},Ie=()=>!j&&!z&&null!==H&&!document.hidden,ke=(0,n.startPlaybackStallWatchdog)({peer:()=>H,readable:Ie,judgeable:()=>Ie()&&"connected"===H?.connectionState&&se.current&&ie.current,publish:(t,n)=>{for(const o of me.current)o(t,n)},reconnectedAt:de,failCodec:()=>A?Te():Ce("WebRTC playback stalled."),retryTransport:Ce,expectContinuousFrames:fe.current,capturePaused:async()=>!0===(await We())?.capture?.rebooting});ve.current=ke,oe.current=Ee,ce.current=()=>{ye(),ke.invalidate()};const Le=()=>{ye(),document.hidden||Ee()};document.addEventListener("visibilitychange",Le);return(async()=>{try{H=new RTCPeerConnection({iceServers:pe,iceTransportPolicy:D}),Y({peerConnection:H,sessionId:ae});const o=H.addTransceiver("video",{direction:"recvonly"}),c=RTCRtpReceiver.getCapabilities("video");c?.codecs.length&&"setCodecPreferences"in o&&o.setCodecPreferences(T(c.codecs,F)),H.ontrack=t=>{j||(K=!0,se.current=!1,t.track.onended=()=>Ce("WebRTC video track ended."),G(t.streams[0]??new MediaStream([t.track])),ye(),Ee())},H.onconnectionstatechange=()=>{!j&&H&&("connected"===H.connectionState?(X=!0,ge(),Ee()):"disconnected"===H.connectionState?(X=!1,ye(),void 0===$&&($=window.setTimeout(()=>{$=void 0,!j&&H&&"connected"!==H.connectionState&&Ce("WebRTC remained disconnected.")},h))):"failed"!==H.connectionState&&"closed"!==H.connectionState||Ce("WebRTC connection failed."))};const s=await H.createOffer();await H.setLocalDescription(s),await(n=H,new Promise(t=>{if("complete"===n.iceGatheringState)return void t();let o,c=!1;const s=()=>{c||(c=!0,n.removeEventListener("icegatheringstatechange",u),void 0!==o&&window.clearTimeout(o),t())},u=()=>{"complete"===n.iceGatheringState&&s()};n.addEventListener("icegatheringstatechange",u),o=window.setTimeout(s,v)}));const l=H.localDescription;if(!l)throw new Error("WebRTC offer was not created");const f=await(0,u.postWebRtcOffer)({url:t,fetchImpl:B,signal:te.signal,requestTimeoutMs:p,busyRetryIntervalMs:w,busyRetryCount:y,body:JSON.stringify(C({description:l,sessionId:ae,codec:F,iceServers:pe,sendIceServersInOffer:U,raiseH264Level:x}))});if(!f.ok){const t=f.status;await(f.body?.cancel());const n=`WebRTC offer failed: HTTP ${t}.`;return void(W(t,_)?Ce(n):he(n))}const b=await f.json();if(j)return void await be(!0);try{await H.setRemoteDescription(b)}catch{he("WebRTC returned an invalid session description.")}}catch(t){if(j||te.signal.aborted)return;if(t instanceof u.WebRtcSignalingBusyError)return void Ce("WebRTC signaling stayed busy for too long.");const n=t instanceof u.WebRtcSignalingTimeoutError?"WebRTC signaling timed out.":"WebRTC signaling failed.";Ce(n)}var n})(),()=>{j=!0,ke.stop(),ve.current===ke&&(ve.current=null),oe.current=null,ce.current=null,document.removeEventListener("visibilitychange",Le),window.removeEventListener("pagehide",we),window.removeEventListener("beforeunload",we),te.abort(),void 0!==o&&window.clearTimeout(o),Re(),be(!0)}},[P,t,c,k,L,F,O,D,U,A,M,te,B,_,x]),{stream:q,failure:N,error:z,retrying:K,markFrameDecoded:we,restart:ye,streamStats:be,setStreamStatsEnabled:ee,subscribeStats:pe}};var t=r(d[0]),n=r(d[1]),o=r(d[2]),c=r(d[3]),s=r(d[4]),u=r(d[5]),l=r(d[6]);const f=[{urls:["stun:stun.l.google.com:19302"]},{urls:["stun:stun1.l.google.com:19302"]}],v=3e3,p=2e4,b=4e3,w=500,y=30,R=500,S=5e3,h=1e4;function T(t,n){const o="h264"===n?"video/h264":"vp9"===n?"video/vp9":"video/vp8";if("h264"!==n)return[...t.filter(t=>t.mimeType.toLowerCase()===o),...t.filter(t=>t.mimeType.toLowerCase()!==o)];const c=t=>t.mimeType.toLowerCase()===o,s=t=>/(?:^|;)\s*packetization-mode=1(?:\s*;|$)/i.test(t.sdpFmtpLine??"");return[...t.filter(t=>c(t)&&s(t)),...t.filter(t=>c(t)&&!s(t)),...t.filter(t=>!c(t))]}function C({description:n,sessionId:o,codec:c,iceServers:s,sendIceServersInOffer:u=!0,raiseH264Level:l=!1}){return Object.assign({type:n.type,sdp:l&&"h264"===c&&n.sdp?(0,t.raiseH264OfferLevel)(n.sdp):n.sdp,sessionId:o,codec:c},u?{iceServers:s}:{})}function W(t,n=!1){return n&&404===t||408===t||425===t||429===t||t>=500}async function E(t){if(!t)return!1;try{let n=!1;return(await(0,c.readStatsBeforeDeadline)(t))?.forEach(t=>{if("inbound-rtp"!==t.type)return;const o=t;"video"!==o.kind&&"video"!==o.mediaType||(o.framesReceived??0)>0&&(n=!0)}),n}catch{return!1}}function I(){if("function"==typeof crypto.randomUUID)return crypto.randomUUID();const t=crypto.getRandomValues(new Uint8Array(16));t[6]=15&t[6]|64,t[8]=63&t[8]|128;const n=Array.from(t,t=>t.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}},211,[212,213,38,214,216,218,219]);
|
|
278
278
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),Object.defineProperty(e,"H264_SEND_LEVEL_IDC",{enumerable:!0,get:function(){return t}}),e.raiseH264OfferLevel=function(u,o=t){if(!Number.isInteger(o)||o<=0||o>255)return u;const f=o.toString(16).padStart(2,"0"),p=(t,l,c)=>{const u=Number.parseInt(c.slice(0,2),16),p=Number.parseInt(c.slice(2,4),16),b=Number.parseInt(c.slice(4,6),16);if(b>=o)return t;const _=b===n&&s.has(u)?-17&p:p;return`${l}${c.slice(0,2)}${_.toString(16).padStart(2,"0")}${f}`};return u.replace(c,t=>t.replace(l,p))};const t=52,n=11,s=new Set([66,77,88]),l=/(profile-level-id=)([0-9a-fA-F]{6})(?![0-9a-fA-F])/g,c=/^a=fmtp:[^\r\n]*\blevel-asymmetry-allowed=1\b[^\r\n]*$/gm},212,[]);
|
|
279
279
|
__d(function(g,r,i,a,m,e,d){"use strict";Object.defineProperty(e,'__esModule',{value:!0}),e.parseInboundVideo=u,e.startPlaybackStallWatchdog=function({peer:f,readable:v,judgeable:p,publish:S,reconnectedAt:b,failCodec:L,retryTransport:y,expectContinuousFrames:P=!0,capturePaused:A}){let _=c.initialPlaybackStallState,k=null,R=[],C=0,D=null;const w=()=>{C+=1,_=c.initialPlaybackStallState,R=[],D=null},T=(0,n.startExclusivePoll)(async()=>{if(!v())return void w();const n=C,T=f(),h=await(0,t.readStatsBeforeDeadline)(T,o);if(h&&v()&&f()===T&&S(h,Date.now()),!p()||!T)return void w();if(n!==C)return;const B=performance.now();if(null!==D&&B-D>s)return w(),void(D=B);D=B;const E=h?u(h):[],O=(0,c.selectInboundReport)(E,k,R);if(R=E,!O)return void(_=c.initialPlaybackStallState);if(O.id!==k?.id&&(_=c.initialPlaybackStallState),k={id:O.id,framesReceived:O.framesReceived},!P&&O.framesReceived<=_.received)return void(_={decoded:O.framesDecoded,received:O.framesReceived,stalledPolls:0});const x=(0,c.nextPlaybackStallState)(_,{decoded:O.framesDecoded,received:O.framesReceived});if(_=x.stalled?c.initialPlaybackStallState:x.state,!x.stalled)return;if(A){const t=await A();if(n!==C||f()!==T||!p())return;if(t)return void w()}const K=(0,l.webRtcFailureDisposition)("playback-stall",T.connectionState,{mediaArriving:x.mediaArriving}),M=b.current,Y=(0,l.playbackStallAction)(K,null===M?null:performance.now()-M);if("fail-codec"===Y)return b.current=null,void L();"retry-transport"===Y&&("codec"===K&&(b.current=performance.now()),y("WebRTC playback stalled."))},c.PLAYBACK_STALL_POLL_MS);"undefined"!=typeof document&&document.addEventListener("visibilitychange",w);return{stop(){"undefined"!=typeof document&&document.removeEventListener("visibilitychange",w),w(),T()},invalidate:w,setExpectContinuousFrames(t){t!==P&&(P=t,w())}}};var t=r(d[0]),n=r(d[1]),l=r(d[2]),c=r(d[3]);const o=2*c.PLAYBACK_STALL_POLL_MS,s=c.PLAYBACK_STALL_POLL_MS*c.PLAYBACK_STALL_POLLS;function u(t){const n=[];return t.forEach(t=>{if("inbound-rtp"!==t.type)return;const l=t;"video"!==l.kind&&"video"!==l.mediaType||n.push({id:l.id,framesReceived:l.framesReceived??0,framesDecoded:"number"==typeof l.framesDecoded?l.framesDecoded:null})}),n}},213,[214,215,216,217]);
|
package/dist/client/index.html
CHANGED
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
<noscript> You need to enable JavaScript to run Expo Device Hub. </noscript>
|
|
60
60
|
<!-- The root element for the Hub dashboard. -->
|
|
61
61
|
<div id="root"></div>
|
|
62
|
-
<script src="./_expo/static/js/web/index-
|
|
62
|
+
<script src="./_expo/static/js/web/index-27f4b6af29200f07e5fc6cf0b57414a7.js" defer></script>
|
|
63
63
|
</body>
|
|
64
64
|
</html>
|
package/package.json
CHANGED
|
@@ -26,6 +26,7 @@ function abortReason(signal, fallback) {
|
|
|
26
26
|
#applyLocation;
|
|
27
27
|
#applyRotation;
|
|
28
28
|
#recordLock;
|
|
29
|
+
#beginLock;
|
|
29
30
|
#now;
|
|
30
31
|
#owners = new Set();
|
|
31
32
|
#inputTargets = new Map();
|
|
@@ -40,6 +41,7 @@ function abortReason(signal, fallback) {
|
|
|
40
41
|
});
|
|
41
42
|
this.orientation = display.reader;
|
|
42
43
|
this.#recordLock = display.locked;
|
|
44
|
+
this.#beginLock = display.locking;
|
|
43
45
|
this.#now = options.now ?? Date.now;
|
|
44
46
|
this.recorder = options.recorder ?? new SessionRecorder();
|
|
45
47
|
this.logcat = options.logcat ?? new LogcatHub(options.serial);
|
|
@@ -104,11 +106,18 @@ function abortReason(signal, fallback) {
|
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
106
108
|
* Lock or free the rotation and record it, so `/api` right after a lock reports the locked
|
|
107
|
-
* pose instead of a read from before it.
|
|
109
|
+
* pose instead of a read from before it. Readings that overlap the command are dropped, and a
|
|
110
|
+
* failed command leaves the reading stale.
|
|
108
111
|
*/ async setOrientation(mode) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
this.#beginLock();
|
|
113
|
+
let pose = null;
|
|
114
|
+
try {
|
|
115
|
+
const status = await this.#applyRotation(this.serial, mode);
|
|
116
|
+
pose = status.pose;
|
|
117
|
+
return status;
|
|
118
|
+
} finally{
|
|
119
|
+
this.#recordLock(pose);
|
|
120
|
+
}
|
|
112
121
|
}
|
|
113
122
|
release(owner, reason) {
|
|
114
123
|
if (!this.#owners.delete(owner)) {
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
const MAX_AGE_MS = 1_000;
|
|
2
2
|
const FRESH_WAIT_MS = 300;
|
|
3
3
|
/**
|
|
4
|
-
* A reader of the display pose, and `locked` for the owner that changes the lock.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* lock never
|
|
4
|
+
* A reader of the display pose, and `locking`/`locked` for the owner that changes the lock.
|
|
5
|
+
* `locking` runs before the lock command, so a reading that overlaps the command is dropped.
|
|
6
|
+
* A locked pose becomes the reading for the next second; null (a free rotation or a failed
|
|
7
|
+
* command) makes the reading stale. A read that started before a lock never replaces the
|
|
8
|
+
* reading, and a caller after a lock never shares that read.
|
|
8
9
|
*/ export function createDisplayOrientationReader({ read, now = ()=>performance.now() }) {
|
|
9
10
|
let orientation = null;
|
|
10
11
|
let readAt = Number.NEGATIVE_INFINITY;
|
|
11
12
|
// Each lock starts a new generation; a read only counts for the generation it started in.
|
|
12
13
|
let generation = 0;
|
|
14
|
+
// Lock commands that have started but not yet reported their pose.
|
|
15
|
+
let inFlight = 0;
|
|
13
16
|
let pending = null;
|
|
14
17
|
const refresh = ()=>{
|
|
15
18
|
if (pending?.generation === generation) return pending.read;
|
|
@@ -22,11 +25,12 @@ const FRESH_WAIT_MS = 300;
|
|
|
22
25
|
entry.read = (async ()=>{
|
|
23
26
|
try {
|
|
24
27
|
const next = await read();
|
|
25
|
-
|
|
28
|
+
// A newer `observe()` reading wins over this older one.
|
|
29
|
+
if (readGeneration === generation && inFlight === 0 && startedAt >= readAt) orientation = next;
|
|
26
30
|
} catch {
|
|
27
31
|
// Keep the last reading.
|
|
28
32
|
} finally{
|
|
29
|
-
if (readGeneration === generation) readAt = startedAt;
|
|
33
|
+
if (readGeneration === generation && startedAt >= readAt) readAt = startedAt;
|
|
30
34
|
if (pending === entry) pending = null;
|
|
31
35
|
}
|
|
32
36
|
return orientation;
|
|
@@ -35,6 +39,26 @@ const FRESH_WAIT_MS = 300;
|
|
|
35
39
|
};
|
|
36
40
|
return {
|
|
37
41
|
reader: {
|
|
42
|
+
async observe () {
|
|
43
|
+
if (inFlight > 0) return null;
|
|
44
|
+
const readGeneration = generation;
|
|
45
|
+
const startedAt = now();
|
|
46
|
+
let next;
|
|
47
|
+
try {
|
|
48
|
+
next = await read();
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
if (readGeneration !== generation || inFlight > 0) return null;
|
|
53
|
+
if (startedAt >= readAt) {
|
|
54
|
+
orientation = next;
|
|
55
|
+
readAt = startedAt;
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
orientation: next,
|
|
59
|
+
generation: readGeneration
|
|
60
|
+
};
|
|
61
|
+
},
|
|
38
62
|
current () {
|
|
39
63
|
if (now() - readAt > MAX_AGE_MS) void refresh();
|
|
40
64
|
return orientation;
|
|
@@ -55,8 +79,13 @@ const FRESH_WAIT_MS = 300;
|
|
|
55
79
|
}
|
|
56
80
|
}
|
|
57
81
|
},
|
|
82
|
+
locking () {
|
|
83
|
+
generation++;
|
|
84
|
+
inFlight++;
|
|
85
|
+
},
|
|
58
86
|
locked (pose) {
|
|
59
87
|
generation++;
|
|
88
|
+
inFlight = Math.max(0, inFlight - 1);
|
|
60
89
|
if (pose) {
|
|
61
90
|
orientation = pose;
|
|
62
91
|
readAt = now();
|
|
@@ -3,7 +3,7 @@ import { dirname, join } from "node:path";
|
|
|
3
3
|
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
4
4
|
import { DEFAULT_IDLE_REPEAT_MS } from "./grpc-session.js";
|
|
5
5
|
import { getFontWeight, getDisplayDensity, getFontScale, getHighTextContrast, getNetworkStatus, getNightMode, getReduceMotion, getSoftwareKeyboard, getUserRotation, listAllDevices, listDevices, screencapPng, setFontWeight, setDisplayDensity, setFontScale, setHighTextContrast, setNetworkEnabled, setNightMode, setReduceMotion, setSoftwareKeyboard, getDisplayOrientation, setUserRotation } from "./adb.js";
|
|
6
|
-
import { screenshotResponse } from "./screenshot-response.js";
|
|
6
|
+
import { captureScreenshot, screenshotResponse } from "./screenshot-response.js";
|
|
7
7
|
import { ClientTouchState, replayTouchInput } from "./client-touch-state.js";
|
|
8
8
|
import { getAccessibilitySnapshot } from "./accessibility.js";
|
|
9
9
|
import { applyFoldRequest, getFoldStatus } from "./fold.js";
|
|
@@ -1330,7 +1330,8 @@ async function createAppInternal(opts, dependencies = {}) {
|
|
|
1330
1330
|
});
|
|
1331
1331
|
}
|
|
1332
1332
|
try {
|
|
1333
|
-
|
|
1333
|
+
const shot = await captureScreenshot(()=>screencapPng(opts.serial), deviceState.orientation);
|
|
1334
|
+
return await screenshotResponse(shot.png, url, shot.metadata);
|
|
1334
1335
|
} catch (err) {
|
|
1335
1336
|
return Response.json({
|
|
1336
1337
|
ok: false,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Screenshot values are unknown until the capture source supplies them. */ export function screenshotMetadata() {
|
|
2
|
+
return {
|
|
3
|
+
width: 0,
|
|
4
|
+
height: 0,
|
|
5
|
+
displayRotation: null
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
export const SCREENSHOT_METADATA_HEADER = "X-Expo-Screenshot-Metadata";
|
|
9
|
+
export function screenshotMetadataHeaders(metadata = screenshotMetadata()) {
|
|
10
|
+
return {
|
|
11
|
+
[SCREENSHOT_METADATA_HEADER]: JSON.stringify(metadata)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -1,11 +1,59 @@
|
|
|
1
|
+
import { SCREENSHOT_METADATA_HEADER, screenshotMetadata, screenshotMetadataHeaders } from "./screenshot-metadata.js";
|
|
1
2
|
import { Buffer } from "node:buffer";
|
|
2
3
|
import { SCREENSHOT_ARTIFACT_ERROR_HEADER, SCREENSHOT_ARTIFACT_HEADER, saveScreenshotArtifact, screenshotArtifactHeaders } from "./screenshot-artifacts.js";
|
|
3
|
-
/**
|
|
4
|
+
/** Width and height from a PNG's IHDR chunk, or null when the bytes are not a PNG. */ export function pngSize(png) {
|
|
5
|
+
const signature = [
|
|
6
|
+
137,
|
|
7
|
+
80,
|
|
8
|
+
78,
|
|
9
|
+
71,
|
|
10
|
+
13,
|
|
11
|
+
10,
|
|
12
|
+
26,
|
|
13
|
+
10
|
|
14
|
+
];
|
|
15
|
+
if (png.byteLength < 24 || signature.some((byte, i)=>png[i] !== byte)) return null;
|
|
16
|
+
const view = new DataView(png.buffer, png.byteOffset, png.byteLength);
|
|
17
|
+
if (view.getUint32(12) !== 0x49484452) return null; // "IHDR"
|
|
18
|
+
const width = view.getUint32(16);
|
|
19
|
+
const height = view.getUint32(20);
|
|
20
|
+
return width > 0 && height > 0 ? {
|
|
21
|
+
width,
|
|
22
|
+
height
|
|
23
|
+
} : null;
|
|
24
|
+
}
|
|
25
|
+
// @ref LLP 0003#action-catalog — the rotation is observed around this capture, as serve-sim's comes with its frame.
|
|
26
|
+
/**
|
|
27
|
+
* Capture between two display-rotation readings: one that finishes before the capture starts
|
|
28
|
+
* and one that starts after it ends. The rotation is reported only when both agree and match
|
|
29
|
+
* the image's shape, with no Hub rotation command between them, so a single turn around the
|
|
30
|
+
* capture, including a 180-degree one, leaves it null. Width and height come from the PNG, which `screencap` does not scale.
|
|
31
|
+
*/ export async function captureScreenshot(capture, orientation) {
|
|
32
|
+
const first = await orientation.observe();
|
|
33
|
+
const png = await capture();
|
|
34
|
+
const after = await orientation.observe();
|
|
35
|
+
const metadata = screenshotMetadata();
|
|
36
|
+
const size = pngSize(png);
|
|
37
|
+
if (size) {
|
|
38
|
+
metadata.width = size.width;
|
|
39
|
+
metadata.height = size.height;
|
|
40
|
+
}
|
|
41
|
+
const pose = first?.orientation;
|
|
42
|
+
if (pose && pose === after?.orientation && first.generation === after.generation && (!size || size.width === size.height || pose.startsWith("portrait") === size.height > size.width)) {
|
|
43
|
+
metadata.displayRotation = pose.replaceAll("_", "-");
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
png,
|
|
47
|
+
metadata
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** Save the capture for session artifacts, then answer `/api/screenshot` with the PNG and the save outcome. */ export async function screenshotResponse(png, url, metadata = screenshotMetadata()) {
|
|
4
51
|
const result = await saveScreenshotArtifact(png);
|
|
5
52
|
const headers = {
|
|
6
53
|
...screenshotArtifactHeaders(result),
|
|
54
|
+
...screenshotMetadataHeaders(metadata),
|
|
7
55
|
// An allowed cross-origin caller can read only the custom headers listed here, as in serve-sim.
|
|
8
|
-
"Access-Control-Expose-Headers": `${SCREENSHOT_ARTIFACT_HEADER}, ${SCREENSHOT_ARTIFACT_ERROR_HEADER}`
|
|
56
|
+
"Access-Control-Expose-Headers": `${SCREENSHOT_ARTIFACT_HEADER}, ${SCREENSHOT_ARTIFACT_ERROR_HEADER}, ${SCREENSHOT_METADATA_HEADER}`
|
|
9
57
|
};
|
|
10
58
|
if (url.searchParams.get("format") === "base64") {
|
|
11
59
|
const artifact = result.status === "failed" ? {
|
|
@@ -18,7 +66,8 @@ import { SCREENSHOT_ARTIFACT_ERROR_HEADER, SCREENSHOT_ARTIFACT_HEADER, saveScree
|
|
|
18
66
|
ok: true,
|
|
19
67
|
mimeType: "image/png",
|
|
20
68
|
data: Buffer.from(png).toString("base64"),
|
|
21
|
-
artifact
|
|
69
|
+
artifact,
|
|
70
|
+
metadata
|
|
22
71
|
};
|
|
23
72
|
return Response.json(body, {
|
|
24
73
|
headers
|
|
@@ -3,7 +3,7 @@ import { dirname, join } from "node:path";
|
|
|
3
3
|
import { timingSafeEqual } from "node:crypto";
|
|
4
4
|
import { DEFAULT_IDLE_REPEAT_MS } from "./grpc-session.js";
|
|
5
5
|
import { CameraInputError, cameraLaunchIsWired, handleCameraRequest, readCameraWiring } from "./camera.js";
|
|
6
|
-
import { screenshotResponse } from "./screenshot-response.js";
|
|
6
|
+
import { captureScreenshot, screenshotResponse } from "./screenshot-response.js";
|
|
7
7
|
import { getExecSnapshot } from "./exec.js";
|
|
8
8
|
import { applyFoldRequest, getFoldStatus } from "./fold.js";
|
|
9
9
|
import { getHardwareEncoderError } from "./h264-encoder.js";
|
|
@@ -1937,8 +1937,8 @@ export async function startServer(opts, dependencies = {}) {
|
|
|
1937
1937
|
});
|
|
1938
1938
|
}
|
|
1939
1939
|
try {
|
|
1940
|
-
const
|
|
1941
|
-
return await screenshotResponse(png, url);
|
|
1940
|
+
const shot = await runForContext(requestContext, (context)=>captureScreenshot(()=>screencapPng(context.serial), context.deviceState.orientation));
|
|
1941
|
+
return await screenshotResponse(shot.png, url, shot.metadata);
|
|
1942
1942
|
} catch (err) {
|
|
1943
1943
|
return errorResponse(err);
|
|
1944
1944
|
}
|
|
@@ -945,15 +945,45 @@ export function parseFileImportResponse(value) {
|
|
|
945
945
|
], "file import response.kind")
|
|
946
946
|
};
|
|
947
947
|
}
|
|
948
|
+
function parseScreenshotMetadata(value) {
|
|
949
|
+
const item = record(value, "screenshot metadata");
|
|
950
|
+
const dimensions = {
|
|
951
|
+
width: number(item.width, "metadata.width"),
|
|
952
|
+
height: number(item.height, "metadata.height")
|
|
953
|
+
};
|
|
954
|
+
if (Object.values(dimensions).some((value)=>!Number.isSafeInteger(value) || value < 0)) {
|
|
955
|
+
fail("screenshot metadata numbers must be nonnegative integers");
|
|
956
|
+
}
|
|
957
|
+
const displayRotation = item.displayRotation === null ? null : oneOf(item.displayRotation, [
|
|
958
|
+
"portrait",
|
|
959
|
+
"portrait-upside-down",
|
|
960
|
+
"landscape-left",
|
|
961
|
+
"landscape-right"
|
|
962
|
+
], "metadata.displayRotation");
|
|
963
|
+
return {
|
|
964
|
+
...dimensions,
|
|
965
|
+
displayRotation,
|
|
966
|
+
...item.screen === undefined ? {} : {
|
|
967
|
+
screen: oneOf(item.screen, [
|
|
968
|
+
"inner",
|
|
969
|
+
"outer"
|
|
970
|
+
], "metadata.screen")
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
}
|
|
948
974
|
export function parseScreenshotBase64Response(value) {
|
|
949
975
|
const root = record(value, "screenshot response");
|
|
950
976
|
if (root.ok !== true) fail("screenshot response.ok must be true");
|
|
951
977
|
if (root.mimeType !== "image/png") fail("screenshot response.mimeType must be image/png");
|
|
952
978
|
const data = string(root.data, "screenshot response.data");
|
|
979
|
+
const metadata = root.metadata === undefined ? {} : {
|
|
980
|
+
metadata: parseScreenshotMetadata(root.metadata)
|
|
981
|
+
};
|
|
953
982
|
if (root.artifact === undefined) return {
|
|
954
983
|
ok: true,
|
|
955
984
|
mimeType: "image/png",
|
|
956
|
-
data
|
|
985
|
+
data,
|
|
986
|
+
...metadata
|
|
957
987
|
};
|
|
958
988
|
const artifact = record(root.artifact, "screenshot response.artifact");
|
|
959
989
|
const status = oneOf(artifact.status, SCREENSHOT_ARTIFACT_STATUSES, "screenshot response.artifact.status");
|
|
@@ -961,6 +991,7 @@ export function parseScreenshotBase64Response(value) {
|
|
|
961
991
|
ok: true,
|
|
962
992
|
mimeType: "image/png",
|
|
963
993
|
data,
|
|
994
|
+
...metadata,
|
|
964
995
|
artifact: status === "failed" ? {
|
|
965
996
|
status,
|
|
966
997
|
error: string(artifact.error, "screenshot response.artifact.error")
|