Skip to content

Commit b04182e

Browse files
Matthew ThompsonMatthew Thompson
authored andcommitted
basic screen recording, stopping and listing of the .mp4 urls in the /Replays folder
1 parent b13fcc5 commit b04182e

File tree

7 files changed

+54
-12
lines changed

7 files changed

+54
-12
lines changed

ios/RNReactNativeReplaykit.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#endif
77

88
#import <ReplayKit/ReplayKit.h>
9+
#import "RNReactNativeReplaykit-Swift.h"
910
//#import "RNReactNativeReplaykit-Swift.h"
1011
//@class ReplayFileUtil;
1112

@@ -16,6 +17,7 @@
1617
@property (strong, nonatomic) AVAssetWriter *assetWriter; // TODO
1718
@property (strong, nonatomic) AVAssetWriterInput *assetWriterInput; // TODO
1819
@property (strong, nonatomic) RPPreviewViewController *previewViewController;
20+
@property (strong, nonatomic) ScreenRecordCoordinator *screenRecordCoordinator;
1921

2022
@end
2123

ios/RNReactNativeReplaykit.m

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
#import "RNReactNativeReplaykit.h"
33
#import <React/RCTLog.h>
4+
//#import <AVAssetWriter>
45

56
#import "RNReactNativeReplaykit-Swift.h"
67

@@ -12,20 +13,46 @@ - (dispatch_queue_t)methodQueue
1213
return dispatch_get_main_queue();
1314
}
1415

15-
RCT_EXPORT_METHOD(startRecording)
16+
RCT_EXPORT_METHOD(initt)
17+
{
18+
self.screenRecordCoordinator = [[ScreenRecordCoordinator alloc] init];
19+
}
20+
21+
RCT_EXPORT_METHOD(startRecording:(RCTResponseSenderBlock)callback)
1622
{
1723
[ReplayFileUtil createReplaysFolder];
18-
// [ScreenRecorder start]
24+
static NSString *letters = @"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
25+
NSMutableString *randomString = [NSMutableString stringWithCapacity: 15];
26+
for (int i=0; i<15; i++) {
27+
[randomString appendFormat: @"%C", [letters characterAtIndex: arc4random() % [letters length]]];
28+
}
29+
30+
[self.screenRecordCoordinator
31+
startRecordingWithFileName:randomString
32+
recordingHandler:^(NSError *error) {
33+
34+
if(error)
35+
{
36+
37+
}
38+
}
39+
onCompletion:^(NSError *error) {
40+
41+
if(error)
42+
{
43+
}
44+
}];
1945
}
2046

2147
RCT_EXPORT_METHOD(getRecordings:(RCTResponseSenderBlock)callback)
2248
{
23-
NSArray *recordings = [ReplayFileUtil fetchAllReplays];
24-
callback(@[[NSNull null], recordings]);
49+
NSArray *recordings = [self.screenRecordCoordinator listAllReplays];
50+
callback(@[recordings]);
2551
}
2652

2753
RCT_EXPORT_METHOD(stopRecording)
2854
{
55+
[self.screenRecordCoordinator stopRecording];
2956
}
3057

3158
RCT_EXPORT_MODULE()

ios/RNReactNativeReplaykit.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,21 @@
5656
name = Products;
5757
sourceTree = "<group>";
5858
};
59-
58B511D21A9E6C8500147676 = {
59+
52ECF58A2148AE6400301CC6 /* ScreenRecord */ = {
6060
isa = PBXGroup;
6161
children = (
6262
52ECF5882148A75700301CC6 /* WindowUtil.swift */,
6363
52ECF5862148A74600301CC6 /* ScreenRecorder.swift */,
6464
52ECF5842148A73500301CC6 /* ScreenRecordCoordinator.swift */,
6565
52ECF57F21487E1500301CC6 /* FileUtil.swift */,
66+
);
67+
path = ScreenRecord;
68+
sourceTree = "<group>";
69+
};
70+
58B511D21A9E6C8500147676 = {
71+
isa = PBXGroup;
72+
children = (
73+
52ECF58A2148AE6400301CC6 /* ScreenRecord */,
6674
B3E7B5881CC2AC0600A0062D /* RNReactNativeReplaykit.h */,
6775
B3E7B5891CC2AC0600A0062D /* RNReactNativeReplaykit.m */,
6876
134814211AA4EA7D00B7C361 /* Products */,
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ import Foundation
4242
return filePath
4343
}
4444

45-
class func fetchAllReplays() -> Array<URL>
45+
class func fetchAllReplays() -> Array<String>
4646
{
4747
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
4848
let replayPath = documentsDirectory?.appendingPathComponent("/Replays")
4949
let directoryContents = try! FileManager.default.contentsOfDirectory(at: replayPath!, includingPropertiesForKeys: nil, options: [])
50-
return directoryContents
50+
let urls = directoryContents.map({
51+
(url: URL) -> String in
52+
return url.absoluteString
53+
})
54+
return urls
5155
}
5256
}
5357

ios/ScreenRecordCoordinator.swift renamed to ios/ScreenRecord/ScreenRecordCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import Foundation
4242
}
4343
}
4444

45-
class func listAllReplays() -> Array<URL>
45+
func listAllReplays() -> Array<String>
4646
{
4747
return ReplayFileUtil.fetchAllReplays()
4848
}
Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ import AVKit
1818

1919
let viewOverlay = WindowUtil()
2020

21-
let mp4: AVFileType = ""
22-
let video: AVFileType = ""
21+
public func pewpew () {
22+
23+
}
2324

2425
//MARK: Screen Recording
2526
public func startRecording(withFileName fileName: String, recordingHandler:@escaping (Error?)-> Void)
@@ -28,14 +29,14 @@ import AVKit
2829
{
2930
let fileURL = URL(fileURLWithPath: ReplayFileUtil.filePath(fileName))
3031
assetWriter = try! AVAssetWriter(outputURL: fileURL, fileType:
31-
mp4 as String)
32+
AVFileTypeMPEG4)
3233
let videoOutputSettings: Dictionary<String, Any> = [
3334
AVVideoCodecKey : AVVideoCodecType.h264,
3435
AVVideoWidthKey : UIScreen.main.bounds.size.width,
3536
AVVideoHeightKey : UIScreen.main.bounds.size.height
3637
];
3738

38-
videoInput = AVAssetWriterInput (mediaType: video as String, outputSettings: videoOutputSettings)
39+
videoInput = AVAssetWriterInput (mediaType: AVMediaTypeVideo as String, outputSettings: videoOutputSettings)
3940
videoInput.expectsMediaDataInRealTime = true
4041
assetWriter.add(videoInput)
4142

0 commit comments

Comments
 (0)