Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

fix(emulator): reset partial JPEG state when reconnecting (#35593)

OrcaWin7ad81415e736
diff --git a/src/main/emulator/mjpeg-frame-stream.test.ts b/src/main/emulator/mjpeg-frame-stream.test.ts
index fb68201399b..b2329d1da45 100644
--- a/src/main/emulator/mjpeg-frame-stream.test.ts
+++ b/src/main/emulator/mjpeg-frame-stream.test.ts
@@ -27,6 +27,31 @@ function listen(serverToStart: Server): Promise<number> {
}
describe('MjpegFrameStream', () => {
+ it('discards an unfinished frame when reconnecting to a new response', async () => {
+ let attempts = 0
+ const framePromise = new Promise<Buffer>((resolve, reject) => {
+ const httpServer = createServer((_req, res) => {
+ attempts += 1
+ res.writeHead(200, { 'content-type': 'application/octet-stream' })
+ res.end(attempts === 1 ? JPEG.subarray(0, 3) : JPEG)
+ })
+ server = httpServer
+ void listen(httpServer).then((port) => {
+ const stream = new MjpegFrameStream(`http://127.0.0.1:${port}/stream.mjpeg`, {
+ onError: reject,
+ onFrame: (frame) => {
+ stream.stop()
+ resolve(frame)
+ }
+ })
+ stream.start()
+ })
+ })
+
+ await expect(framePromise).resolves.toEqual(JPEG)
+ expect(attempts).toBe(2)
+ })
+
it('reads raw MJPEG frames through Node HTTP', async () => {
let requestUrl = ''
const framePromise = new Promise<Buffer>((resolve, reject) => {
diff --git a/src/main/emulator/mjpeg-frame-stream.ts b/src/main/emulator/mjpeg-frame-stream.ts
index d8ca91cb720..bc4958221c3 100644
--- a/src/main/emulator/mjpeg-frame-stream.ts
+++ b/src/main/emulator/mjpeg-frame-stream.ts
@@ -85,6 +85,7 @@ export class MjpegFrameStream {
return
}
+ this.accumulator.reset()
const req = requestForUrl(this.streamUrl, (res) => {
if (res.statusCode && res.statusCode >= 400) {
this.callbacks.onError(`Simulator stream returned HTTP ${res.statusCode}.`)