Fix the broken video recording feature for iOS

Summary:
This diff fixes the broken video recording feature for iOS.
 There were two bugs, the `stopScreenCapture` was misspelled and one with the codec, ReactPlayer was not able to render with the default codec of hevc

Reviewed By: jknoxville

Differential Revision: D19746904

fbshipit-source-id: f951b016be5f5aec5d4e6bcea4c9c246a62b37a3
This commit is contained in:
Pritesh Nandgaonkar
2020-02-06 11:12:25 -08:00
committed by Facebook Github Bot
parent 1b6ce47be2
commit 47b63f9543

View File

@@ -18,6 +18,7 @@ import uuid from 'uuid/v1';
import path from 'path';
import {promisify} from 'util';
import {exec} from 'child_process';
import {default as promiseTimeout} from '../utils/promiseTimeout';
type IOSLogLevel = 'Default' | 'Info' | 'Debug' | 'Error' | 'Fault';
@@ -185,17 +186,39 @@ export default class IOSDevice extends BaseDevice {
async startScreenCapture(destination: string) {
this.recordingProcess = exec(
`xcrun simctl io booted recordVideo "${destination}"`,
`xcrun simctl io booted recordVideo --codec=h264 --force ${destination}`,
);
this.recordingLocation = destination;
}
async stopScreenCaputre(): Promise<string | null> {
async stopScreenCapture(): Promise<string | null> {
if (this.recordingProcess && this.recordingLocation) {
this.recordingProcess.kill('SIGINT');
const {recordingLocation} = this;
this.recordingLocation = undefined;
return recordingLocation;
const prom = new Promise<void>((resolve, _reject) => {
this.recordingProcess!.on(
'exit',
async (_code: number | null, _signal: NodeJS.Signals | null) => {
resolve();
},
);
this.recordingProcess!.kill('SIGINT');
});
const output: string | null = await promiseTimeout<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.error(_e);
return null;
});
return output;
}
return null;
}