StikDebug/StikJIT/MiniToolSupport/JSSupport/IDeviceJSBridgeAdapter.m
Huge_Black dca36d5c00
Heartbeat Rework + Mini Tool (#299)
* Heartbeat rework

* remove some debug loggings

* stik mini tool poc

* Saperate JITEnableContext into extensions and put each feature into their own files.
Fix local pairing file is removed after switched to external device by directly loading the remote device's pairing file in place.

* custom origin & xmlhttprequest

* Fix some memory leak

* allow background script access idevice (codes are from the old JSSupport branch)

Tests are not carried out but most of the js api should work.

Do we need to obfuscate some functions' name?

* Fix JITEnableContext singleton initializer race condition

* Fix instprox callback

---------

Co-authored-by: Stephen B <158498287+StephenDev0@users.noreply.github.com>
2025-12-14 11:35:32 -05:00

37 lines
1.1 KiB
Objective-C

//
// IDeviceJSBridgeAdapter.m
// StikJIT
//
// Created by s s on 2025/4/25.
//
@import Foundation;
#import "JSSupport.h"
@implementation IDeviceJSBridge (Adapter)
- (void)adapter_connectWithBody:(NSDictionary *)body replyHandler:(nonnull void (^)(id _Nullable, NSString * _Nullable))replyHandler {
int clientId = [body[@"adapter"] intValue];
if(!handles[@(clientId)] || handles[@(clientId)].freeFunc != adapter_free) {
replyHandler(nil, @"Invalid adapter handle");
return;
}
int port = [body[@"port"] intValue];
if(port < 0 || port > 65536 ) {
replyHandler(nil, @"Invalid port");
return;
}
IDeviceHandle* clientHandleObj = handles[@(clientId)];
AdapterHandle* handle = clientHandleObj.handle;
AdapterStreamHandle *stream = NULL;
IdeviceFfiError* err = adapter_connect(handle, port, (ReadWriteOpaque **)&stream);
if (err) {
replyHandler(nil, [self errFreeFromIdeviceFfiError:err]);
return;
}
int handleId = [self registerIdeviceHandle:stream freeFunc:(void *)adapter_stream_close];
replyHandler(@(handleId), nil);
}
@end