| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | // | 
					
						
							|  |  |  | //  FrameProcessorPluginHostObject.mm | 
					
						
							|  |  |  | //  VisionCamera | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | //  Created by Marc Rousavy on 21.07.23. | 
					
						
							|  |  |  | //  Copyright © 2023 mrousavy. All rights reserved. | 
					
						
							|  |  |  | // | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #import "FrameProcessorPluginHostObject.h" | 
					
						
							|  |  |  | #import "FrameHostObject.h" | 
					
						
							|  |  |  | #import "JSINSObjectConversion.h" | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | #import <Foundation/Foundation.h> | 
					
						
							|  |  |  | #import <vector> | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-22 00:15:11 +02:00
										 |  |  | using namespace facebook; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  | std::vector<jsi::PropNameID> FrameProcessorPluginHostObject::getPropertyNames(jsi::Runtime& runtime) { | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |   std::vector<jsi::PropNameID> result; | 
					
						
							|  |  |  |   result.push_back(jsi::PropNameID::forUtf8(runtime, std::string("call"))); | 
					
						
							|  |  |  |   return result; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  | jsi::Value FrameProcessorPluginHostObject::get(jsi::Runtime& runtime, const jsi::PropNameID& propName) { | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |   auto name = propName.utf8(runtime); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (name == "call") { | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  |     return jsi::Function::createFromHostFunction( | 
					
						
							|  |  |  |         runtime, jsi::PropNameID::forUtf8(runtime, "call"), 2, | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  |         [=](jsi::Runtime& runtime, const jsi::Value& thisValue, const jsi::Value* arguments, size_t count) -> jsi::Value { | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  |           // Frame is first argument | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  |           auto frameHostObject = arguments[0].asObject(runtime).asHostObject<FrameHostObject>(runtime); | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  |           Frame* frame = frameHostObject->frame; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Options are second argument (possibly undefined) | 
					
						
							|  |  |  |           NSDictionary* options = nil; | 
					
						
							|  |  |  |           if (count > 1) { | 
					
						
							|  |  |  |             auto optionsObject = arguments[1].asObject(runtime); | 
					
						
							| 
									
										
										
										
											2023-09-01 19:39:25 +02:00
										 |  |  |             options = JSINSObjectConversion::convertJSIObjectToNSDictionary(runtime, optionsObject, _callInvoker); | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  |           } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           // Call actual Frame Processor Plugin | 
					
						
							| 
									
										
										
										
											2023-09-06 02:27:35 -07:00
										 |  |  |           id result = [_plugin callback:frame withArguments:options]; | 
					
						
							| 
									
										
										
										
											2023-09-01 12:58:32 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |           // Convert result value to jsi::Value (possibly undefined) | 
					
						
							|  |  |  |           return JSINSObjectConversion::convertObjCObjectToJSIValue(runtime, result); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2023-07-21 17:52:30 +02:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return jsi::Value::undefined(); | 
					
						
							|  |  |  | } |