@@ -10,6 +10,7 @@ import { deviceKeyboard, deviceModel } from "./deviceModels";
1010import { fitDeviceFrame } from "./deviceFrameLayout" ;
1111import { DeviceDuoViewport } from "./DeviceDuoViewport" ;
1212import { DeviceDuoControls } from "./DeviceDuoControls" ;
13+ import { DeviceAndroidFoldControls } from "./DeviceAndroidFoldControls" ;
1314import type { DuoControlState } from "@t3tools/client-runtime/device/duo-control" ;
1415import { DevicePhoneViewport } from "./DevicePhoneViewport" ;
1516import { DeviceLoadingView } from "./DeviceLoadingView" ;
@@ -94,7 +95,9 @@ export function DeviceStreamView(props: {
9495 const clientRef = useRef < DeviceStreamClient | null > ( null ) ;
9596 const [ status , setStatus ] = useState < DeviceStreamStatus > ( "connecting" ) ;
9697 const [ detail , setDetail ] = useState < string | undefined > ( undefined ) ;
98+ const [ showRestartNotice , setShowRestartNotice ] = useState ( false ) ;
9799 const [ screen , setScreen ] = useState < DeviceScreenSize | null > ( null ) ;
100+ const [ foldAngle , setFoldAngle ] = useState < number | null > ( null ) ;
98101 const [ mjpegUrl , setMjpegUrl ] = useState < string | null > ( null ) ;
99102 const [ mjpegGeneration , setMjpegGeneration ] = useState ( 0 ) ;
100103 const attachMjpegImage = useCallback ( ( image : HTMLImageElement | null ) => {
@@ -121,6 +124,7 @@ export function DeviceStreamView(props: {
121124 onStatus : ( next , nextDetail ) => {
122125 setStatus ( next ) ;
123126 setDetail ( nextDetail ) ;
127+ if ( next !== "connecting" ) setShowRestartNotice ( false ) ;
124128 } ,
125129 onScreen : ( next ) => {
126130 setScreen ( next ) ;
@@ -136,6 +140,7 @@ export function DeviceStreamView(props: {
136140 } ,
137141 onInputConnected : ( connected , detail ) => {
138142 setInputState ( { connected, ...( detail ? { detail } : { } ) } ) ;
143+ if ( ! connected ) setShowRestartNotice ( false ) ;
139144 onHandle ?.( {
140145 pressButton : client . pressButton ,
141146 rotate : client . rotate ,
@@ -183,15 +188,27 @@ export function DeviceStreamView(props: {
183188 return w / h ;
184189 } , [ props . platform , screen ] ) ;
185190
191+ // Android restarts its encoder when a fold changes the framebuffer size.
192+ // Keep the last decoded frame and viewer mounted while the next keyframe arrives.
193+ const retainingAndroidFrame =
194+ props . platform === "android" &&
195+ status === "connecting" &&
196+ inputState . connected &&
197+ screen !== null ;
186198 const showPhone =
187199 props . allowPhoneView &&
188- status === "streaming" &&
200+ ( status === "streaming" || retainingAndroidFrame ) &&
189201 props . visible &&
190202 presentation === "phone" &&
191203 ! phoneUnavailable &&
192204 ! mjpegUrl &&
193205 ! props . axOverlay &&
194206 ( ! isDuo || screen ?. supportsHingeAngle === true ) ;
207+ useEffect ( ( ) => {
208+ if ( ! retainingAndroidFrame || ! showPhone ) return ;
209+ const timeout = window . setTimeout ( ( ) => setShowRestartNotice ( true ) , 2_000 ) ;
210+ return ( ) => window . clearTimeout ( timeout ) ;
211+ } , [ retainingAndroidFrame , showPhone ] ) ;
195212 const controlsInset = props . renderControls && ! showPhone ? CONTROLS_RAIL_WIDTH : 0 ;
196213
197214 // The frame is the largest box at `aspect` that fits the container, so a
@@ -330,7 +347,18 @@ export function DeviceStreamView(props: {
330347 streaming : status === "streaming" ,
331348 phoneUnavailableReason,
332349 foldingControls :
333- showPhone && isDuo && screen ?. supportsHingeAngle ? (
350+ props . platform === "android" && access ? (
351+ < DeviceAndroidFoldControls
352+ key = { `${ props . hostId } :${ props . deviceId } ` }
353+ access = { access }
354+ deviceId = { props . deviceId }
355+ visible = { props . visible }
356+ enabled = { status === "streaming" }
357+ screenWidth = { screen ?. width }
358+ screenHeight = { screen ?. height }
359+ onFoldAngle = { setFoldAngle }
360+ />
361+ ) : showPhone && isDuo && screen ?. supportsHingeAngle ? (
334362 < DeviceDuoControls
335363 screen = { screen }
336364 state = { duoControl }
@@ -471,6 +499,7 @@ export function DeviceStreamView(props: {
471499 onInputCancel = { onInputCancel }
472500 onResetReady = { onResetReady }
473501 screen = { screen }
502+ foldAngle = { foldAngle }
474503 onUnavailable = { onPhoneUnavailable }
475504 />
476505 ) : null }
@@ -503,7 +532,14 @@ export function DeviceStreamView(props: {
503532 </ span >
504533 </ div >
505534 ) : null }
506- { status !== "streaming" ? (
535+ { retainingAndroidFrame && showPhone && showRestartNotice ? (
536+ < div className = "pointer-events-none absolute inset-x-0 bottom-0 flex justify-center p-2" >
537+ < span className = "rounded-md bg-background/85 px-2 py-1 text-xs text-muted-foreground" >
538+ Waiting for device video…
539+ </ span >
540+ </ div >
541+ ) : null }
542+ { status !== "streaming" && ! ( retainingAndroidFrame && showPhone ) ? (
507543 < div className = "absolute inset-0" >
508544 < DeviceLoadingView
509545 name = { props . deviceName ?? "Device" }
0 commit comments