Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/core/src/ios-mirror-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ export class IosMirrorHub {
subscriber.dropped += dropped;
this.dropped += dropped;
this.invalidate(subscriber);
// The panel forgets its pointer on the new generation, so lift its held gesture here.
this.releasePointer(device, subscriber).catch(error => { if (error instanceof Error) this.failed(error); });
}
if (subscriber.waitingKey && frame.key === false) continue;
if (frame.data.length > 4 * 1024 * 1024) continue;
Expand Down Expand Up @@ -191,7 +193,8 @@ export class IosMirrorHub {
if (device.pointer && device.pointer.owner !== subscriber) throw new IosMirrorInputBusyError();
const nativeGeneration = device.generation;
await device.capture.touch(samples, nativeGeneration);
if (subscriber.delivered !== generation || device.generation !== nativeGeneration) return;
// Record the pointer even if this panel was invalidated meanwhile; its queued release lifts it.
if (device.generation !== nativeGeneration) return;
const last = samples.at(-1);
if (last === undefined || last.phase === 2) device.pointer = undefined;
else device.pointer = { owner: subscriber, sample: last, generation: device.generation };
Expand Down
70 changes: 70 additions & 0 deletions packages/core/test/ios-mirror-hub.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,76 @@ test("joining and another subscriber's reset preserve a held gesture", async t =
assert.equal(f.touches.at(-1)?.samples[0].phase, 2);
});

test("subscriber overflow releases its held gesture without interrupting other panels", async t => {
const f = fixture();
t.after(() => f.hub.close());
const a = await f.hub.open("phone");
const b = await f.hub.open("phone");
await f.frame();
const first = await a.read();
const second = await b.read();
const down = [{ phase: 0, x: 10, y: 20, width: 400, height: 800 }];
await a.touch(down, first.generation);
for (let index = 0; index < 10; index++) {
await f.frame(false);
const batch = await b.read();
assert.equal(batch.generation, second.generation);
}
await b.touch(down, second.generation);
assert.deepEqual(f.touches.map(touch => touch.samples[0].phase), [0, 2, 0]);
assert.deepEqual(f.touches[1], { samples: [{ ...down[0], phase: 2 }], generation: 1 });
const reading = a.read();
await f.frame();
const recovered = await reading;
assert.equal(recovered.generation, first.generation + 1);
await assert.rejects(a.touch(down, recovered.generation), /Another panel/);
await b.touch([{ ...down[0], phase: 2 }], second.generation);
await a.touch(down, recovered.generation);
assert.deepEqual(f.touches.map(touch => touch.samples[0].phase), [0, 2, 0, 2, 0]);
});

test("subscriber overflow during a touch releases the gesture after the touch lands", async t => {
const f = fixture();
t.after(() => f.hub.close());
const a = await f.hub.open("phone");
const b = await f.hub.open("phone");
await f.frame();
const first = await a.read();
const second = await b.read();
const send = f.capture.touch;
let land!: () => void;
const landed = new Promise<void>(resolve => { land = resolve; });
f.capture.touch = async (samples, generation) => { await landed; await send(samples, generation); };
const down = [{ phase: 0, x: 10, y: 20, width: 400, height: 800 }];
const pressing = a.touch(down, first.generation);
await tick();
for (let index = 0; index < 9; index++) {
await f.frame(false);
await b.read();
}
land();
await pressing;
await b.touch(down, second.generation);
assert.deepEqual(f.touches.map(touch => touch.samples[0].phase), [0, 2, 0]);
});

test("another subscriber's overflow preserves a healthy held gesture", async t => {
const f = fixture();
t.after(() => f.hub.close());
const a = await f.hub.open("phone");
const b = await f.hub.open("phone");
await f.frame();
await a.read();
const second = await b.read();
await b.touch([{ phase: 0, x: 10, y: 20, width: 400, height: 800 }], second.generation);
for (let index = 0; index < 10; index++) {
await f.frame(false);
await b.read();
}
await b.touch([{ phase: 1, x: 20, y: 30, width: 400, height: 800 }], second.generation);
assert.deepEqual(f.touches.map(touch => touch.samples[0].phase), [0, 1]);
});

test("empty native reads during recovery coalesce keyframe requests", async t => {
const f = fixture();
t.after(() => f.hub.close());
Expand Down
16 changes: 8 additions & 8 deletions packages/shared/test/android-startup-diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,23 +72,23 @@ function completion(messages: StartupMessage[]) {
return message;
}

test("successful startup aggregates stage timings and emits no content or per-poll events", async () => {
test("successful startup aggregates stage timings and emits no content or per-poll events", async t => {
// A valid duration can have the same digits as the fixture's forwarded port.
let now = 0;
t.mock.method(performance, "now", () => now += 28000);
const f = fixture();
const session = await startScrcpy({ serial: "private-device-id", onStartupDiagnostics: f.report }, f.dependencies);
t.after(() => session.close());
const summary = completion(f.messages);
assert.equal(summary.outcome, "ready");
const poll = summary.stages.find(value => value.stage === "socket-poll");
assert.equal(poll?.timedSamples, 1);
assert.equal(poll?.queueMs, 3);
assert.equal(poll?.executionMs, 7);
assert.equal(poll?.spawnedSamples, 1);
const parsed = androidStartupMessageSchema.safeParse(summary);
assert.equal(parsed.success, true);
const serialized = JSON.stringify(f.messages);
for (const content of ["private-device-id", "/private", "12345678", "Private device name", "@scrcpy", "28000"]) {
const included = serialized.includes(content);
assert.equal(included, false);
}
assert.equal(summary.stages[0].totalMs, 28000);
// The strict schema permits only known categories and numeric measurements, never raw content.
for (const message of f.messages) androidStartupMessageSchema.parse(message);
const count = f.messages.length;
await session.close();
assert.equal(f.messages.length, count, "Later session cleanup is outside startup diagnostics.");
Expand Down
Loading