Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
/** Был поворот экрана: дальше --size не передаём никогда — wm size застыл в нативной
* ориентации, а реальный буфер повёрнут (летербокс/рассинхрон тапов). До конца сессии. */
private
=
false
;
/** Webview сообщил, что WebCodecs (VideoDecoder) доступен. */
private
=
false
;
private
?
:
;
private
=
0
;
private
=
0
;
/** Поколение видеозапуска: stop/kill его инвалидирует — проснувшийся после await startVideo не должен спавнить осиротевший screenrecord. */
private
=
0
;
/** Поколение image-лупа: fallbackToImages инвалидирует предыдущий, чтобы не появилось два параллельных тика. */
private
=
0
;
/** Webview загрузился и прислал 'ready' — старт потока только после рукопожатия. */
private
=
false
;
/** Не разбитые на кадры остатки h264-потока (NAL могут приходить кусками). */
private
:
=
.
alloc
(
0
)
;
private
=
''
;
private
=
0
;
private
:
.
|
undefined
;
constructor
(
private
readonly
:
,
private
readonly
:
string
,
onDispose
:
(
)
=>
void
,
)
{
this
.
=
.
.
createWebviewPanel
(
'auraKotlin.deviceScreen'
,
`${device}`
,
.
.
,
// Поток всё равно ставится на паузу, пока панель скрыта — удерживать webview незачем.
{
:
true
,
:
false
}
,
)
;
this
.
.
=
new
vscode
.
ThemeIcon
(
'device-mobile'
)
;
this
.
.
.
=
this
.
html
(
)
;
this
.
.
.
onDidReceiveMessage
(
=>
void
this
.
onMessage
(
)
)
;
this
.
.
onDidChangeViewState
(
(
)
=>
{
// Обязательная пауза потока: скрытая панель не должна жечь CPU и дёргать adb.
if
(
this
.
.
)
{
this
.
start
(
)
;
}
else
{
this
.
stop
(
)
;
}
}
)
;
this
.
.
onDidDispose
(
(
)
=>
{
this
.
=
true
;
this
.
stop
(
)
;
onDispose
(
)
;
}
)
;
}
dispose
(
)
:
void
{
this
.
=
true
;
this
.
stop
(
)
;
this
.
.
dispose
(
)
;
}
reveal
(
)
:
void
{
// Старт не нужен: после показа webview пересоздаётся и сам присылает 'ready'.
this
.
.
reveal
(
)
;
}
/** Запустить поток в текущем режиме (идемпотентно: повторный вызов ничего не делает). */
private
start
(
)
:
void
{
if
(
this
.
||
this
.
||
!
this
.
.
||
!
this
.
)
{
return
;
}
this
.
=
true
;
if
(
this
.
===
'video'
&&
this
.
)
{
void
this
.
startVideo
(
)
;
}
else
{
this
.
startImageLoop
(
)
;
}
}
private
stop
(
)
:
void
{
this
.
=
false
;
this
.
=
false
;
// следующий show пересоздаст webview — ждём новый 'ready'
if
(
this
.
)
{
clearTimeout
(
this
.
)
;
this
.
=
undefined
;
}
this
.
killVideo
(
)
;
this
.
=
.
alloc
(
0
)
;
}
private
killVideo
(
)
:
void
{
this
.
++
;
const
=
this
.
;
this
.
=
undefined
;
// exit-обработчик увидит «уже не текущий» и не станет перезапускать
// stdout и завершается сам на следующей записи кадра.
?.
kill
(
)
;
}
/** Живой поток: adb exec-out screenrecord --output-format=h264 - (raw Annex-B).
* @paramskipSize — после поворота не передаём --size: screenrecord сам берёт текущий размер дисплея. */
private
async
startVideo
(
?
:
boolean
)
:
Promise
<
void
>
{
const
=
++
this
.
;
this
.
=
.
alloc
(
0
)
;
this
.
=
0
;
this
.
=
''
;
// webview (пере)создан — конфиг декодера всегда посылаем заново
const
=
[
'-s'
,
this
.
,
'exec-out'
,
'screenrecord'
,
'--output-format=h264'
,
'--bit-rate'
,
String
(
VIDEO_BITRATE
)
]
;
const
=
await
this
.
.
screenSize
(
this
.
)
;
if
(
this
.
||
!
this
.
||
!==
this
.
)
{
return
;
}
if
(
&&
!
)
{
// Ограничение энкодера screenrecord — 1920 по длинной стороне; размеры чётные.
const
=
.
min
(
1
,
1920
/
.
max
(
.
,
.
)
)
;
const
=
.
max
(
2
,
.
round
(
.
*
/
2
)
*
2
)
;
const
=
.
max
(
2
,
.
round
(
.
*
/
2
)
*
2
)
;
.
push
(
'--size'
,
`${w}x${h}`
)
;
}
.
push
(
'-'
)
;
let
:
;
try
{
=
spawn
(
this
.
.
adbPath
(
)
??
'adb'
,
,
{
:
true
}
)
;
}
catch
{
this
.
fallbackToImages
(
)
;
return
;
}
this
.
=
;
this
.
=
.
now
(
)
;
.
?.
on
(
'data'
,
(
:
)
=>
{
if
(
this
.
===
)
{
this
.
onVideoData
(
)
;
}
}
)
;
.
on
(
'error'
,
(
)
=>
{
if
(
this
.
===
)
{
this
.
fallbackToImages
(
)
;
}
}
)
;
.
on
(
'exit'
,
(
)
=>
{
if
(
this
.
!==
)
{
return
;
}
this
.
=
undefined
;
if
(
this
.
||
!
this
.
)
{
return
;
}
// Быстрый выход = screenrecord недоступен; обычный — лимит 180 с или ручной перезапуск при повороте.
if
(
.
now
(
)
-
this
.
<
3000
)
{
this
.
++
;
}
else
{
this
.
=
0
;
}
if
(
this
.
>=
VIDEO_MAX_FAST_FAILS
)
{
this
.
fallbackToImages
(
)
;
return
;
}
this
.
=
setTimeout
(
(
)
=>
{
this
.
=
undefined
;
if
(
this
.
&&
!
this
.
&&
this
.
===
'video'
)
{
void
this
.
startVideo
(
this
.
)
;
}
}
,
VIDEO_RESTART_DELAY_MS
)
;
}
)
;
}
/** Видеопоток не сложился (нет screenrecord/WebCodecs, упал декодер) — скриншоты до конца сессии панели. */
private
fallbackToImages
(
)
:
void
{
this
.
=
'image'
;
this
.
killVideo
(
)
;
if
(
this
.
&&
!
this
.
)
{
this
.
startImageLoop
(
)
;
}
}
/**
* Фолбэк AURA-007: screencap → base64 → webview без временных файлов.
* Следующий кадр запрашивается сразу после доставки предыдущего (не раз в 800 мс);
* ошибка = «устройство офлайн», ретраи раз в 3 с.
*/
private
startImageLoop
(
)
:
void
{
const
=
++
this
.
;
const
=
async
(
)
:
Promise
<
void
>
=>
{
if
(
!
this
.
||
this
.
||
this
.
!==
)
{
return
;
}
try
{
const
=
await
this
.
.
captureScreen
(
this
.
)
;
if
(
!
this
.
||
this
.
||
this
.
!==
)
{
return
;
}
if
(
.
>
100
)
{
await
this
.
.
.
postMessage
(
{
:
'frame'
,
:
.
toString
(
'base64'
)
}
)
;
}
}
catch
{
if
(
!
this
.
||
this
.
||
this
.
!==
)
{
return
;
}
void
this
.
.
.
postMessage
(
{
:
'offline'
}
)
;
this
.
=
setTimeout
(
(
)
=>
{
this
.
=
undefined
;
void
tick
(
)
;
}
,
IMAGE_RETRY_MS
)
;
return
;
}
if
(
!
this
.
||
this
.
||
this
.
!==
)
{
return
;
}
this
.
=
setTimeout
(
(
)
=>
{
this
.
=
undefined
;
void
tick
(
)
;
}
,
IMAGE_MIN_DELAY_MS
)
;
}
;
void
tick
(
)
;
}
/** Следующий NAL Annex-B потока: позиция start code, конец заголовка и тип. */
private
static
nextNal
(
:
,
:
number
)
:
{
:
number
;
:
number
;
:
number
}
|
undefined
{
for
(
let
=
.
max
(
0
,
)
;
+
4
<=
.
;
++
)
{
if
(
[
]
!==
0
||
[
+
1
]
!==
0
)
{
continue
;
}
if
(
[
+
2
]
===
1
)
{
return
{
:
,
:
+
3
,
:
[
+
3
]
&
0x1f
}
;
}
if
(
[
+
2
]
===
0
&&
+
5
<=
.
&&
[
+
3
]
===
1
)
{
return
{
:
,
:
+
4
,
:
[
+
4
]
&
0x1f
}
;
}
}
return
undefined
;
}
/** Является ли VCL NAL первым слайсом кадра: first_mb_in_slice (ue(v)) == 0 → бит '1'.
* headerEnd — индекс байта NAL-заголовка (F|NRI|Type, RFC 6184 §1.3); slice header
* с first_mb_in_slice начинается байтом позже — читаем buf[headerEnd + 1]. */
private
static
isFirstSlice
(
:
,
:
number
)
:
boolean
{
return
+
1
<
.
&&
(
[
+
1
]
&
0x80
)
!==
0
;
}
/**
* Разбивка сырого h264 на кадры (access unit): граница кадра — VCL NAL с first_mb_in_slice == 0
* (начало первого слайса нового кадра). Без этого многослайсные кадры резались бы на части.
*/
private
onVideoData
(
:
)
:
void
{
this
.
=
this
.
.
?
.
concat
(
[
this
.
,
]
)
:
;
for
(
;
;
)
{
let
=
-
1
;
let
=
false
;
let
=
.
nextNal
(
this
.
,
0
)
;
while
(
)
{
// type 1..5 — coded slice (кадр); SPS/PPS/SEI идут префиксом того же кадра.
if
(
.
>=
1
&&
.
<=
5
)
{
if
(
&&
.
isFirstSlice
(
this
.
,
.
)
)
{
=
.
;
break
;
}
=
true
;
}
=
.
nextNal
(
this
.
,
.
)
;
}
if
(
<
0
)
{
break
;
}
const
=
this
.
.
subarray
(
0
,
)
;
this
.
=
this
.
.
subarray
(
)
;
this
.
emitVideo
(
)
;
}
if
(
this
.
.
>
16
*
1024
*
1024
)
{
this
.
=
.
alloc
(
0
)
;
}
// защита от мусора в потоке
}
/** Отправить кадр в webview: сначала (пере)конфиг декодера по SPS, потом сам чанк. */
private
emitVideo
(
:
)
:
void
{
let
=
false
;
let
:
|
undefined
;
let
=
.
nextNal
(
,
0
)
;
while
(
)
{
if
(
.
===
7
)
{
=
true
;
=
.
subarray
(
.
)
;
}
else
if
(
.
===
5
)
{
=
true
;
}
=
.
nextNal
(
,
.
)
;
}
if
(
)
{
const
=
.
codecFromSps
(
)
;
if
(
&&
!==
this
.
)
{
this
.
=
;
void
this
.
.
.
postMessage
(
{
:
'video-config'
,
}
)
;
}
}
if
(
!
this
.
)
{
return
;
}
// до SPS кадры не шлём: декодеру не с чем конфигурироваться
this
.
+=
33_333
;
// ~30 fps: для живого отображения важна монотонность, не точность
void
this
.
.
.
postMessage
(
{
:
'video-chunk'
,
:
.
toString
(
'base64'
)
,
,
:
this
.
}
)
;
}
/** Кодек-строка avc1.PPCCLL для VideoDecoder.configure из первых байт SPS. */