format identation
This commit is contained in:
parent
20f8fa2937
commit
621bfe333c
@ -10,18 +10,18 @@ import UIKit
|
||||
|
||||
|
||||
enum RCTLogLevel: String {
|
||||
case trace
|
||||
case info
|
||||
case warning
|
||||
case error
|
||||
case trace
|
||||
case info
|
||||
case warning
|
||||
case error
|
||||
}
|
||||
|
||||
enum RCTLogSource {
|
||||
case native
|
||||
case native
|
||||
}
|
||||
|
||||
func RCTDefaultLogFunction(_ level: RCTLogLevel, _ source: RCTLogSource, _ file: String, _ line: NSNumber, _ message: String) {
|
||||
print(level.rawValue, "-", message)
|
||||
print(level.rawValue, "-", message)
|
||||
}
|
||||
|
||||
typealias RCTDirectEventBlock = (Any?) -> Void
|
||||
@ -30,53 +30,53 @@ typealias RCTPromiseRejectBlock = (String, String, NSError?) -> Void
|
||||
typealias RCTResponseSenderBlock = (Any) -> Void
|
||||
|
||||
func NSNull() -> [String: String] {
|
||||
return [:]
|
||||
return [:]
|
||||
}
|
||||
|
||||
|
||||
func makeReactError(_ cameraError: CameraError, cause: NSError?) -> [String: Any] {
|
||||
var causeDictionary: [String: Any]?
|
||||
if let cause = cause {
|
||||
causeDictionary = [
|
||||
"cause": "\(cause.domain): \(cause.code) \(cause.description)",
|
||||
"userInfo": cause.userInfo
|
||||
]
|
||||
}
|
||||
return [
|
||||
"error": "\(cameraError.code): \(cameraError.message)",
|
||||
"extra": [
|
||||
"code": cameraError.code,
|
||||
"message": cameraError.message,
|
||||
"cause": causeDictionary ?? NSNull(),
|
||||
]
|
||||
var causeDictionary: [String: Any]?
|
||||
if let cause = cause {
|
||||
causeDictionary = [
|
||||
"cause": "\(cause.domain): \(cause.code) \(cause.description)",
|
||||
"userInfo": cause.userInfo
|
||||
]
|
||||
}
|
||||
return [
|
||||
"error": "\(cameraError.code): \(cameraError.message)",
|
||||
"extra": [
|
||||
"code": cameraError.code,
|
||||
"message": cameraError.message,
|
||||
"cause": causeDictionary ?? NSNull(),
|
||||
]
|
||||
]
|
||||
}
|
||||
|
||||
func makeReactError(_ cameraError: CameraError) -> [String: Any] {
|
||||
return makeReactError(cameraError, cause: nil)
|
||||
return makeReactError(cameraError, cause: nil)
|
||||
}
|
||||
|
||||
|
||||
class RCTFPSGraph: UIView {
|
||||
convenience init(frame: CGRect, color: UIColor) {
|
||||
self.init(frame: frame)
|
||||
}
|
||||
convenience init(frame: CGRect, color: UIColor) {
|
||||
self.init(frame: frame)
|
||||
}
|
||||
|
||||
func onTick(_ tick: CFTimeInterval) {
|
||||
func onTick(_ tick: CFTimeInterval) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func RCTTempFilePath(_ ext: String, _ error: ErrorPointer) -> String? {
|
||||
let directory = NSTemporaryDirectory().appending("ReactNative")
|
||||
let fm = FileManager.default
|
||||
if fm.fileExists(atPath: directory) {
|
||||
try! fm.removeItem(atPath: directory)
|
||||
}
|
||||
if !fm.fileExists(atPath: directory) {
|
||||
try! fm.createDirectory(atPath: directory, withIntermediateDirectories: true)
|
||||
}
|
||||
return directory
|
||||
.appending("/").appending(UUID().uuidString)
|
||||
.appending(".").appending(ext)
|
||||
let directory = NSTemporaryDirectory().appending("ReactNative")
|
||||
let fm = FileManager.default
|
||||
if fm.fileExists(atPath: directory) {
|
||||
try! fm.removeItem(atPath: directory)
|
||||
}
|
||||
if !fm.fileExists(atPath: directory) {
|
||||
try! fm.createDirectory(atPath: directory, withIntermediateDirectories: true)
|
||||
}
|
||||
return directory
|
||||
.appending("/").appending(UUID().uuidString)
|
||||
.appending(".").appending(ext)
|
||||
}
|
||||
|
@ -11,101 +11,101 @@ import AVFoundation
|
||||
|
||||
class ViewController: UIViewController {
|
||||
|
||||
@IBOutlet weak var recordButton: UIButton!
|
||||
@IBOutlet weak var recordButton: UIButton!
|
||||
|
||||
let cameraView = CameraView()
|
||||
let cameraView = CameraView()
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
|
||||
cameraView.translatesAutoresizingMaskIntoConstraints = false;
|
||||
view.insertSubview(cameraView, at: 0)
|
||||
NSLayoutConstraint.activate([
|
||||
cameraView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
cameraView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
cameraView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
cameraView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
cameraView.translatesAutoresizingMaskIntoConstraints = false;
|
||||
view.insertSubview(cameraView, at: 0)
|
||||
NSLayoutConstraint.activate([
|
||||
cameraView.topAnchor.constraint(equalTo: view.topAnchor),
|
||||
cameraView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
|
||||
cameraView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
|
||||
cameraView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
|
||||
])
|
||||
|
||||
recordButton.isHidden = true
|
||||
cameraView.onInitialized = { _ in
|
||||
DispatchQueue.main.async {
|
||||
self.recordButton.isHidden = false
|
||||
}
|
||||
}
|
||||
cameraView.onInitReady = { json in
|
||||
print("onInitReady:", json ?? "nil")
|
||||
}
|
||||
cameraView.onVideoChunkReady = { json in
|
||||
print("onVideoChunkReady:", json ?? "nil")
|
||||
}
|
||||
|
||||
Task { @MainActor in
|
||||
await requestAuthorizations()
|
||||
|
||||
cameraView.photo = true
|
||||
cameraView.video = true
|
||||
cameraView.audio = false
|
||||
cameraView.isActive = true
|
||||
cameraView.cameraId = getCameraDeviceId() as NSString?
|
||||
cameraView.didSetProps([])
|
||||
}
|
||||
recordButton.isHidden = true
|
||||
cameraView.onInitialized = { _ in
|
||||
DispatchQueue.main.async {
|
||||
self.recordButton.isHidden = false
|
||||
}
|
||||
}
|
||||
cameraView.onInitReady = { json in
|
||||
print("onInitReady:", json ?? "nil")
|
||||
}
|
||||
cameraView.onVideoChunkReady = { json in
|
||||
print("onVideoChunkReady:", json ?? "nil")
|
||||
}
|
||||
|
||||
func isAuthorized(for mediaType: AVMediaType) async -> Bool {
|
||||
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
||||
var isAuthorized = status == .authorized
|
||||
if status == .notDetermined {
|
||||
isAuthorized = await AVCaptureDevice.requestAccess(for: mediaType)
|
||||
}
|
||||
return isAuthorized
|
||||
}
|
||||
|
||||
|
||||
func requestAuthorizations() async {
|
||||
guard await isAuthorized(for: .video) else { return }
|
||||
guard await isAuthorized(for: .audio) else { return }
|
||||
// Set up the capture session.
|
||||
}
|
||||
|
||||
private func getCameraDeviceId() -> String? {
|
||||
let deviceTypes: [AVCaptureDevice.DeviceType] = [
|
||||
.builtInWideAngleCamera
|
||||
]
|
||||
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: .back)
|
||||
|
||||
let device = discoverySession.devices.first
|
||||
|
||||
return device?.uniqueID
|
||||
}
|
||||
|
||||
@IBAction
|
||||
func toggleRecord(_ button: UIButton) {
|
||||
if button.title(for: .normal) == "Stop" {
|
||||
|
||||
cameraView.stopRecording(promise: Promise(
|
||||
resolver: { result in
|
||||
print("result")
|
||||
}, rejecter: { code, message, cause in
|
||||
print("error")
|
||||
}))
|
||||
|
||||
button.setTitle("Record", for: .normal)
|
||||
button.configuration = .filled()
|
||||
|
||||
} else {
|
||||
cameraView.startRecording(
|
||||
options: [
|
||||
"fileType": "mp4",
|
||||
"videoCodec": "h265",
|
||||
]) { callback in
|
||||
print("callback", callback)
|
||||
}
|
||||
|
||||
button.setTitle("Stop", for: .normal)
|
||||
button.configuration = .bordered()
|
||||
Task { @MainActor in
|
||||
await requestAuthorizations()
|
||||
|
||||
cameraView.photo = true
|
||||
cameraView.video = true
|
||||
cameraView.audio = false
|
||||
cameraView.isActive = true
|
||||
cameraView.cameraId = getCameraDeviceId() as NSString?
|
||||
cameraView.didSetProps([])
|
||||
}
|
||||
}
|
||||
|
||||
func isAuthorized(for mediaType: AVMediaType) async -> Bool {
|
||||
let status = AVCaptureDevice.authorizationStatus(for: mediaType)
|
||||
var isAuthorized = status == .authorized
|
||||
if status == .notDetermined {
|
||||
isAuthorized = await AVCaptureDevice.requestAccess(for: mediaType)
|
||||
}
|
||||
return isAuthorized
|
||||
}
|
||||
|
||||
|
||||
func requestAuthorizations() async {
|
||||
guard await isAuthorized(for: .video) else { return }
|
||||
guard await isAuthorized(for: .audio) else { return }
|
||||
// Set up the capture session.
|
||||
}
|
||||
|
||||
private func getCameraDeviceId() -> String? {
|
||||
let deviceTypes: [AVCaptureDevice.DeviceType] = [
|
||||
.builtInWideAngleCamera
|
||||
]
|
||||
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: deviceTypes, mediaType: .video, position: .back)
|
||||
|
||||
let device = discoverySession.devices.first
|
||||
|
||||
return device?.uniqueID
|
||||
}
|
||||
|
||||
@IBAction
|
||||
func toggleRecord(_ button: UIButton) {
|
||||
if button.title(for: .normal) == "Stop" {
|
||||
|
||||
cameraView.stopRecording(promise: Promise(
|
||||
resolver: { result in
|
||||
print("result")
|
||||
}, rejecter: { code, message, cause in
|
||||
print("error")
|
||||
}))
|
||||
|
||||
button.setTitle("Record", for: .normal)
|
||||
button.configuration = .filled()
|
||||
|
||||
} else {
|
||||
cameraView.startRecording(
|
||||
options: [
|
||||
"fileType": "mp4",
|
||||
"videoCodec": "h265",
|
||||
]) { callback in
|
||||
print("callback", callback)
|
||||
}
|
||||
|
||||
button.setTitle("Stop", for: .normal)
|
||||
button.configuration = .bordered()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user