mirror of
https://git.vectorsigma.ru/public/immich.git
synced 2026-07-29 00:18:18 +00:00
outdated ios ws code
This commit is contained in:
@@ -145,37 +145,6 @@ data class ClientCertPrompt (
|
||||
|
||||
override fun hashCode(): Int = toList().hashCode()
|
||||
}
|
||||
|
||||
/** Generated class from Pigeon that represents data sent in messages. */
|
||||
data class WebSocketTaskResult (
|
||||
val taskPointer: Long,
|
||||
val taskProtocol: String? = null
|
||||
)
|
||||
{
|
||||
companion object {
|
||||
fun fromList(pigeonVar_list: List<Any?>): WebSocketTaskResult {
|
||||
val taskPointer = pigeonVar_list[0] as Long
|
||||
val taskProtocol = pigeonVar_list[1] as String?
|
||||
return WebSocketTaskResult(taskPointer, taskProtocol)
|
||||
}
|
||||
}
|
||||
fun toList(): List<Any?> {
|
||||
return listOf(
|
||||
taskPointer,
|
||||
taskProtocol,
|
||||
)
|
||||
}
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is WebSocketTaskResult) {
|
||||
return false
|
||||
}
|
||||
if (this === other) {
|
||||
return true
|
||||
}
|
||||
return NetworkPigeonUtils.deepEquals(toList(), other.toList()) }
|
||||
|
||||
override fun hashCode(): Int = toList().hashCode()
|
||||
}
|
||||
private open class NetworkPigeonCodec : StandardMessageCodec() {
|
||||
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
|
||||
return when (type) {
|
||||
@@ -189,11 +158,6 @@ private open class NetworkPigeonCodec : StandardMessageCodec() {
|
||||
ClientCertPrompt.fromList(it)
|
||||
}
|
||||
}
|
||||
131.toByte() -> {
|
||||
return (readValue(buffer) as? List<Any?>)?.let {
|
||||
WebSocketTaskResult.fromList(it)
|
||||
}
|
||||
}
|
||||
else -> super.readValueOfType(type, buffer)
|
||||
}
|
||||
}
|
||||
@@ -207,10 +171,6 @@ private open class NetworkPigeonCodec : StandardMessageCodec() {
|
||||
stream.write(130)
|
||||
writeValue(stream, value.toList())
|
||||
}
|
||||
is WebSocketTaskResult -> {
|
||||
stream.write(131)
|
||||
writeValue(stream, value.toList())
|
||||
}
|
||||
else -> super.writeValue(stream, value)
|
||||
}
|
||||
}
|
||||
@@ -223,8 +183,6 @@ interface NetworkApi {
|
||||
fun selectCertificate(promptText: ClientCertPrompt, callback: (Result<ClientCertData>) -> Unit)
|
||||
fun removeCertificate(callback: (Result<Unit>) -> Unit)
|
||||
fun getClientPointer(): Long
|
||||
/** iOS only - creates a WebSocket task and waits for connection to be established. */
|
||||
fun createWebSocketTask(url: String, protocols: List<String>?, callback: (Result<WebSocketTaskResult>) -> Unit)
|
||||
fun setRequestHeaders(headers: Map<String, String>)
|
||||
|
||||
companion object {
|
||||
@@ -307,27 +265,6 @@ interface NetworkApi {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.createWebSocketTask$separatedMessageChannelSuffix", codec)
|
||||
if (api != null) {
|
||||
channel.setMessageHandler { message, reply ->
|
||||
val args = message as List<Any?>
|
||||
val urlArg = args[0] as String
|
||||
val protocolsArg = args[1] as List<String>?
|
||||
api.createWebSocketTask(urlArg, protocolsArg) { result: Result<WebSocketTaskResult> ->
|
||||
val error = result.exceptionOrNull()
|
||||
if (error != null) {
|
||||
reply.reply(NetworkPigeonUtils.wrapError(error))
|
||||
} else {
|
||||
val data = result.getOrNull()
|
||||
reply.reply(NetworkPigeonUtils.wrapResult(data))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
channel.setMessageHandler(null)
|
||||
}
|
||||
}
|
||||
run {
|
||||
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.immich_mobile.NetworkApi.setRequestHeaders$separatedMessageChannelSuffix", codec)
|
||||
if (api != null) {
|
||||
|
||||
@@ -104,12 +104,6 @@ private class NetworkApiImpl(private val context: Context) : NetworkApi {
|
||||
return NativeBuffer.createGlobalRef(client)
|
||||
}
|
||||
|
||||
// only used on iOS
|
||||
override fun createWebSocketTask(
|
||||
url: String,
|
||||
protocols: List<String>?,
|
||||
callback: (Result<WebSocketTaskResult>) -> Unit
|
||||
) {}
|
||||
|
||||
override fun setRequestHeaders(headers: Map<String, String>) {
|
||||
HttpClientManager.setRequestHeaders(headers)
|
||||
|
||||
@@ -176,35 +176,6 @@ struct ClientCertPrompt: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generated class from Pigeon that represents data sent in messages.
|
||||
struct WebSocketTaskResult: Hashable {
|
||||
var taskPointer: Int64
|
||||
var taskProtocol: String? = nil
|
||||
|
||||
|
||||
// swift-format-ignore: AlwaysUseLowerCamelCase
|
||||
static func fromList(_ pigeonVar_list: [Any?]) -> WebSocketTaskResult? {
|
||||
let taskPointer = pigeonVar_list[0] as! Int64
|
||||
let taskProtocol: String? = nilOrValue(pigeonVar_list[1])
|
||||
|
||||
return WebSocketTaskResult(
|
||||
taskPointer: taskPointer,
|
||||
taskProtocol: taskProtocol
|
||||
)
|
||||
}
|
||||
func toList() -> [Any?] {
|
||||
return [
|
||||
taskPointer,
|
||||
taskProtocol,
|
||||
]
|
||||
}
|
||||
static func == (lhs: WebSocketTaskResult, rhs: WebSocketTaskResult) -> Bool {
|
||||
return deepEqualsNetwork(lhs.toList(), rhs.toList()) }
|
||||
func hash(into hasher: inout Hasher) {
|
||||
deepHashNetwork(value: toList(), hasher: &hasher)
|
||||
}
|
||||
}
|
||||
|
||||
private class NetworkPigeonCodecReader: FlutterStandardReader {
|
||||
override func readValue(ofType type: UInt8) -> Any? {
|
||||
switch type {
|
||||
@@ -212,8 +183,6 @@ private class NetworkPigeonCodecReader: FlutterStandardReader {
|
||||
return ClientCertData.fromList(self.readValue() as! [Any?])
|
||||
case 130:
|
||||
return ClientCertPrompt.fromList(self.readValue() as! [Any?])
|
||||
case 131:
|
||||
return WebSocketTaskResult.fromList(self.readValue() as! [Any?])
|
||||
default:
|
||||
return super.readValue(ofType: type)
|
||||
}
|
||||
@@ -228,9 +197,6 @@ private class NetworkPigeonCodecWriter: FlutterStandardWriter {
|
||||
} else if let value = value as? ClientCertPrompt {
|
||||
super.writeByte(130)
|
||||
super.writeValue(value.toList())
|
||||
} else if let value = value as? WebSocketTaskResult {
|
||||
super.writeByte(131)
|
||||
super.writeValue(value.toList())
|
||||
} else {
|
||||
super.writeValue(value)
|
||||
}
|
||||
@@ -258,8 +224,6 @@ protocol NetworkApi {
|
||||
func selectCertificate(promptText: ClientCertPrompt, completion: @escaping (Result<ClientCertData, Error>) -> Void)
|
||||
func removeCertificate(completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func getClientPointer() throws -> Int64
|
||||
/// iOS only - creates a WebSocket task and waits for connection to be established.
|
||||
func createWebSocketTask(url: String, protocols: [String]?, completion: @escaping (Result<WebSocketTaskResult, Error>) -> Void)
|
||||
func setRequestHeaders(headers: [String: String]) throws
|
||||
}
|
||||
|
||||
@@ -331,25 +295,6 @@ class NetworkApiSetup {
|
||||
} else {
|
||||
getClientPointerChannel.setMessageHandler(nil)
|
||||
}
|
||||
/// iOS only - creates a WebSocket task and waits for connection to be established.
|
||||
let createWebSocketTaskChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.createWebSocketTask\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
createWebSocketTaskChannel.setMessageHandler { message, reply in
|
||||
let args = message as! [Any?]
|
||||
let urlArg = args[0] as! String
|
||||
let protocolsArg: [String]? = nilOrValue(args[1])
|
||||
api.createWebSocketTask(url: urlArg, protocols: protocolsArg) { result in
|
||||
switch result {
|
||||
case .success(let res):
|
||||
reply(wrapResult(res))
|
||||
case .failure(let error):
|
||||
reply(wrapError(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
createWebSocketTaskChannel.setMessageHandler(nil)
|
||||
}
|
||||
let setRequestHeadersChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.immich_mobile.NetworkApi.setRequestHeaders\(channelSuffix)", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
setRequestHeadersChannel.setMessageHandler { message, reply in
|
||||
|
||||
@@ -48,27 +48,6 @@ class NetworkApiImpl: NetworkApi {
|
||||
return Int64(Int(bitPattern: pointer))
|
||||
}
|
||||
|
||||
func createWebSocketTask(
|
||||
url: String,
|
||||
protocols: [String]?,
|
||||
completion: @escaping (Result<WebSocketTaskResult, any Error>) -> Void
|
||||
) {
|
||||
guard let wsUrl = URL(string: url) else {
|
||||
return completion(.failure(WebSocketError.invalidURL(url)))
|
||||
}
|
||||
|
||||
URLSessionManager.shared.createWebSocketTask(url: wsUrl, protocols: protocols) { result in
|
||||
switch result {
|
||||
case .success(let (task, proto)):
|
||||
let pointer = Unmanaged.passUnretained(task).toOpaque()
|
||||
let address = Int64(Int(bitPattern: pointer))
|
||||
completion(.success(WebSocketTaskResult(taskPointer: address, taskProtocol: proto)))
|
||||
case .failure(let error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setRequestHeaders(headers: [String : String]) throws {
|
||||
URLSessionManager.shared.session.configuration.httpAdditionalHeaders = headers
|
||||
}
|
||||
|
||||
@@ -42,85 +42,9 @@ class URLSessionManager: NSObject {
|
||||
session = URLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)
|
||||
super.init()
|
||||
}
|
||||
|
||||
/// Creates a WebSocket task and waits for connection to be established.
|
||||
func createWebSocketTask(
|
||||
url: URL,
|
||||
protocols: [String]?,
|
||||
completion: @escaping (Result<(URLSessionWebSocketTask, String?), Error>) -> Void
|
||||
) {
|
||||
let task: URLSessionWebSocketTask
|
||||
if let protocols = protocols, !protocols.isEmpty {
|
||||
task = session.webSocketTask(with: url, protocols: protocols)
|
||||
} else {
|
||||
task = session.webSocketTask(with: url)
|
||||
}
|
||||
|
||||
delegate.registerWebSocketTask(task) { result in
|
||||
completion(result)
|
||||
}
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
|
||||
enum WebSocketError: Error {
|
||||
case connectionFailed(String)
|
||||
case invalidURL(String)
|
||||
}
|
||||
|
||||
class URLSessionManagerDelegate: NSObject, URLSessionTaskDelegate, URLSessionWebSocketDelegate {
|
||||
private var webSocketCompletions: [Int: (Result<(URLSessionWebSocketTask, String?), Error>) -> Void] = [:]
|
||||
private let lock = {
|
||||
let lock = UnsafeMutablePointer<os_unfair_lock>.allocate(capacity: 1)
|
||||
lock.initialize(to: os_unfair_lock())
|
||||
return lock
|
||||
}()
|
||||
|
||||
func registerWebSocketTask(
|
||||
_ task: URLSessionWebSocketTask,
|
||||
completion: @escaping (Result<(URLSessionWebSocketTask, String?), Error>) -> Void
|
||||
) {
|
||||
os_unfair_lock_lock(lock)
|
||||
webSocketCompletions[task.taskIdentifier] = completion
|
||||
os_unfair_lock_unlock(lock)
|
||||
}
|
||||
|
||||
func urlSession(
|
||||
_ session: URLSession,
|
||||
webSocketTask: URLSessionWebSocketTask,
|
||||
didOpenWithProtocol protocol: String?
|
||||
) {
|
||||
os_unfair_lock_lock(lock)
|
||||
let completion = webSocketCompletions.removeValue(forKey: webSocketTask.taskIdentifier)
|
||||
os_unfair_lock_unlock(lock)
|
||||
completion?(.success((webSocketTask, `protocol`)))
|
||||
}
|
||||
|
||||
func urlSession(
|
||||
_ session: URLSession,
|
||||
webSocketTask: URLSessionWebSocketTask,
|
||||
didCloseWith closeCode: URLSessionWebSocketTask.CloseCode,
|
||||
reason: Data?
|
||||
) {
|
||||
// Close events are handled by CupertinoWebSocket via task.closeCode/closeReason
|
||||
}
|
||||
|
||||
func urlSession(
|
||||
_ session: URLSession,
|
||||
task: URLSessionTask,
|
||||
didCompleteWithError error: Error?
|
||||
) {
|
||||
guard let webSocketTask = task as? URLSessionWebSocketTask else { return }
|
||||
|
||||
os_unfair_lock_lock(lock)
|
||||
let completion = webSocketCompletions.removeValue(forKey: webSocketTask.taskIdentifier)
|
||||
os_unfair_lock_unlock(lock)
|
||||
|
||||
if let error = error {
|
||||
completion?(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
func urlSession(
|
||||
_ session: URLSession,
|
||||
didReceive challenge: URLAuthenticationChallenge,
|
||||
|
||||
71
mobile/lib/platform/network_api.g.dart
generated
71
mobile/lib/platform/network_api.g.dart
generated
@@ -112,43 +112,6 @@ class ClientCertPrompt {
|
||||
int get hashCode => Object.hashAll(_toList());
|
||||
}
|
||||
|
||||
class WebSocketTaskResult {
|
||||
WebSocketTaskResult({required this.taskPointer, this.taskProtocol});
|
||||
|
||||
int taskPointer;
|
||||
|
||||
String? taskProtocol;
|
||||
|
||||
List<Object?> _toList() {
|
||||
return <Object?>[taskPointer, taskProtocol];
|
||||
}
|
||||
|
||||
Object encode() {
|
||||
return _toList();
|
||||
}
|
||||
|
||||
static WebSocketTaskResult decode(Object result) {
|
||||
result as List<Object?>;
|
||||
return WebSocketTaskResult(taskPointer: result[0]! as int, taskProtocol: result[1] as String?);
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
bool operator ==(Object other) {
|
||||
if (other is! WebSocketTaskResult || other.runtimeType != runtimeType) {
|
||||
return false;
|
||||
}
|
||||
if (identical(this, other)) {
|
||||
return true;
|
||||
}
|
||||
return _deepEquals(encode(), other.encode());
|
||||
}
|
||||
|
||||
@override
|
||||
// ignore: avoid_equals_and_hash_code_on_mutable_classes
|
||||
int get hashCode => Object.hashAll(_toList());
|
||||
}
|
||||
|
||||
class _PigeonCodec extends StandardMessageCodec {
|
||||
const _PigeonCodec();
|
||||
@override
|
||||
@@ -162,9 +125,6 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
} else if (value is ClientCertPrompt) {
|
||||
buffer.putUint8(130);
|
||||
writeValue(buffer, value.encode());
|
||||
} else if (value is WebSocketTaskResult) {
|
||||
buffer.putUint8(131);
|
||||
writeValue(buffer, value.encode());
|
||||
} else {
|
||||
super.writeValue(buffer, value);
|
||||
}
|
||||
@@ -177,8 +137,6 @@ class _PigeonCodec extends StandardMessageCodec {
|
||||
return ClientCertData.decode(readValue(buffer)!);
|
||||
case 130:
|
||||
return ClientCertPrompt.decode(readValue(buffer)!);
|
||||
case 131:
|
||||
return WebSocketTaskResult.decode(readValue(buffer)!);
|
||||
default:
|
||||
return super.readValueOfType(type, buffer);
|
||||
}
|
||||
@@ -300,35 +258,6 @@ class NetworkApi {
|
||||
}
|
||||
}
|
||||
|
||||
/// iOS only - creates a WebSocket task and waits for connection to be established.
|
||||
Future<WebSocketTaskResult> createWebSocketTask(String url, List<String>? protocols) async {
|
||||
final String pigeonVar_channelName =
|
||||
'dev.flutter.pigeon.immich_mobile.NetworkApi.createWebSocketTask$pigeonVar_messageChannelSuffix';
|
||||
final BasicMessageChannel<Object?> pigeonVar_channel = BasicMessageChannel<Object?>(
|
||||
pigeonVar_channelName,
|
||||
pigeonChannelCodec,
|
||||
binaryMessenger: pigeonVar_binaryMessenger,
|
||||
);
|
||||
final Future<Object?> pigeonVar_sendFuture = pigeonVar_channel.send(<Object?>[url, protocols]);
|
||||
final List<Object?>? pigeonVar_replyList = await pigeonVar_sendFuture as List<Object?>?;
|
||||
if (pigeonVar_replyList == null) {
|
||||
throw _createConnectionError(pigeonVar_channelName);
|
||||
} else if (pigeonVar_replyList.length > 1) {
|
||||
throw PlatformException(
|
||||
code: pigeonVar_replyList[0]! as String,
|
||||
message: pigeonVar_replyList[1] as String?,
|
||||
details: pigeonVar_replyList[2],
|
||||
);
|
||||
} else if (pigeonVar_replyList[0] == null) {
|
||||
throw PlatformException(
|
||||
code: 'null-error',
|
||||
message: 'Host platform returned null value for non-null return value.',
|
||||
);
|
||||
} else {
|
||||
return (pigeonVar_replyList[0] as WebSocketTaskResult?)!;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> setRequestHeaders(Map<String, String> headers) async {
|
||||
final String pigeonVar_channelName =
|
||||
'dev.flutter.pigeon.immich_mobile.NetworkApi.setRequestHeaders$pigeonVar_messageChannelSuffix';
|
||||
|
||||
@@ -16,13 +16,6 @@ class ClientCertPrompt {
|
||||
ClientCertPrompt(this.title, this.message, this.cancel, this.confirm);
|
||||
}
|
||||
|
||||
class WebSocketTaskResult {
|
||||
int taskPointer;
|
||||
String? taskProtocol;
|
||||
|
||||
WebSocketTaskResult(this.taskPointer, this.taskProtocol);
|
||||
}
|
||||
|
||||
@ConfigurePigeon(
|
||||
PigeonOptions(
|
||||
dartOut: 'lib/platform/network_api.g.dart',
|
||||
@@ -48,9 +41,5 @@ abstract class NetworkApi {
|
||||
|
||||
int getClientPointer();
|
||||
|
||||
/// iOS only - creates a WebSocket task and waits for connection to be established.
|
||||
@async
|
||||
WebSocketTaskResult createWebSocketTask(String url, List<String>? protocols);
|
||||
|
||||
void setRequestHeaders(Map<String, String> headers);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user