Remove recording invariants
Summary: The state of the destination and the process are coupled together. As a result it makes sense to move these to an object type. This prevents destination and process being independently settable. No change in behaviour, just a removal of invariants that need to be checked Reviewed By: passy Differential Revision: D33913213 fbshipit-source-id: ed18650cac4f72d40e82d20254674f7fa12cbb48
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d807183eb6
commit
7d34c86f78
@@ -18,8 +18,7 @@ import {iOSLogListener} from './iOSLogListener';
|
|||||||
export default class IOSDevice extends ServerDevice {
|
export default class IOSDevice extends ServerDevice {
|
||||||
log?: child_process.ChildProcessWithoutNullStreams;
|
log?: child_process.ChildProcessWithoutNullStreams;
|
||||||
buffer: string;
|
buffer: string;
|
||||||
private recordingProcess?: ChildProcess;
|
private recording?: {process: ChildProcess; destination: string};
|
||||||
private recordingLocation?: string;
|
|
||||||
private iOSBridge: IOSBridge;
|
private iOSBridge: IOSBridge;
|
||||||
readonly logListener: iOSLogListener;
|
readonly logListener: iOSLogListener;
|
||||||
readonly crashWatcher: iOSCrashWatcher;
|
readonly crashWatcher: iOSCrashWatcher;
|
||||||
@@ -82,47 +81,44 @@ export default class IOSDevice extends ServerDevice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async startScreenCapture(destination: string) {
|
async startScreenCapture(destination: string) {
|
||||||
this.recordingProcess = this.iOSBridge.recordVideo(
|
const process = this.iOSBridge.recordVideo(this.serial, destination);
|
||||||
this.serial,
|
this.recording = {process, destination};
|
||||||
destination,
|
|
||||||
);
|
|
||||||
this.recordingLocation = destination;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async stopScreenCapture(): Promise<string> {
|
async stopScreenCapture(): Promise<string> {
|
||||||
if (this.recordingProcess && this.recordingLocation) {
|
const recording = this.recording;
|
||||||
const prom = new Promise<void>((resolve, _reject) => {
|
if (!recording) {
|
||||||
this.recordingProcess!.on(
|
throw new Error('No recording in progress');
|
||||||
'exit',
|
|
||||||
async (_code: number | null, _signal: NodeJS.Signals | null) => {
|
|
||||||
resolve();
|
|
||||||
},
|
|
||||||
);
|
|
||||||
this.recordingProcess!.kill('SIGINT');
|
|
||||||
});
|
|
||||||
|
|
||||||
const output: string = await timeout<void>(
|
|
||||||
5000,
|
|
||||||
prom,
|
|
||||||
'Timed out to stop a screen capture.',
|
|
||||||
)
|
|
||||||
.then(() => {
|
|
||||||
const {recordingLocation} = this;
|
|
||||||
this.recordingLocation = undefined;
|
|
||||||
return recordingLocation!;
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
this.recordingLocation = undefined;
|
|
||||||
console.warn('Failed to terminate iOS screen recording:', e);
|
|
||||||
throw e;
|
|
||||||
});
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
throw new Error('No recording in progress');
|
const prom = new Promise<void>((resolve, _reject) => {
|
||||||
|
recording.process.on(
|
||||||
|
'exit',
|
||||||
|
async (_code: number | null, _signal: NodeJS.Signals | null) => {
|
||||||
|
resolve();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
recording.process.kill('SIGINT');
|
||||||
|
});
|
||||||
|
|
||||||
|
const output: string = await timeout<void>(
|
||||||
|
5000,
|
||||||
|
prom,
|
||||||
|
'Timed out to stop a screen capture.',
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
this.recording = undefined;
|
||||||
|
return recording.destination;
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
this.recording = undefined;
|
||||||
|
console.warn('Failed to terminate iOS screen recording:', e);
|
||||||
|
throw e;
|
||||||
|
});
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
disconnect() {
|
disconnect() {
|
||||||
if (this.recordingProcess && this.recordingLocation) {
|
if (this.recording) {
|
||||||
this.stopScreenCapture();
|
this.stopScreenCapture();
|
||||||
}
|
}
|
||||||
super.disconnect();
|
super.disconnect();
|
||||||
|
|||||||
Reference in New Issue
Block a user