From 47b63f954354168e6b213d8cef20f6bdc805cfb7 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Thu, 6 Feb 2020 11:12:25 -0800 Subject: [PATCH] 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 --- src/devices/IOSDevice.tsx | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/devices/IOSDevice.tsx b/src/devices/IOSDevice.tsx index aca3046c1..d5dc86790 100644 --- a/src/devices/IOSDevice.tsx +++ b/src/devices/IOSDevice.tsx @@ -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 { + async stopScreenCapture(): Promise { if (this.recordingProcess && this.recordingLocation) { - this.recordingProcess.kill('SIGINT'); - const {recordingLocation} = this; - this.recordingLocation = undefined; - return recordingLocation; + const prom = new Promise((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( + 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; }