@xmobitea/gn-typescript-client 2.6.12 → 2.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/gearn.js.client.js +183 -57
  2. package/dist/gearn.js.client.min.js +1 -1
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +183 -57
  5. package/dist/runtime/GNNetwork.d.ts +1 -1
  6. package/dist/runtime/helper/GNSupport.d.ts +20 -0
  7. package/dist/runtime/{entity → helper}/OperationHelper.d.ts +1 -1
  8. package/dist/runtime/helper/StorageService.d.ts +18 -0
  9. package/dist/runtime/networking/NetworkingPeer.d.ts +1 -1
  10. package/dist/runtime/typescript/ServiceUpdate.d.ts +2 -0
  11. package/docs/COCOS_CREATOR_INTEGRATION.md +116 -0
  12. package/examples/cocos-creator/GearNExample.ts.txt +176 -0
  13. package/package.json +3 -2
  14. package/srcSwift/Package.swift +32 -0
  15. package/srcSwift/Sources/GearN/runtime/GNNetwork.swift +530 -0
  16. package/srcSwift/Sources/GearN/runtime/GNNetworkAuthenticateApi.swift +178 -0
  17. package/srcSwift/Sources/GearN/runtime/GNNetworkCharacterPlayerApi.swift +1162 -0
  18. package/srcSwift/Sources/GearN/runtime/GNNetworkCloudScriptApi.swift +154 -0
  19. package/srcSwift/Sources/GearN/runtime/GNNetworkContentApi.swift +208 -0
  20. package/srcSwift/Sources/GearN/runtime/GNNetworkDashboardApi.swift +240 -0
  21. package/srcSwift/Sources/GearN/runtime/GNNetworkGamePlayerApi.swift +1369 -0
  22. package/srcSwift/Sources/GearN/runtime/GNNetworkGroupApi.swift +1100 -0
  23. package/srcSwift/Sources/GearN/runtime/GNNetworkInventoryApi.swift +937 -0
  24. package/srcSwift/Sources/GearN/runtime/GNNetworkMasterPlayerApi.swift +2323 -0
  25. package/srcSwift/Sources/GearN/runtime/GNNetworkMultiplayerApi.swift +298 -0
  26. package/srcSwift/Sources/GearN/runtime/GNNetworkStoreInventoryApi.swift +397 -0
  27. package/srcSwift/Sources/GearN/runtime/common/Action0.swift +3 -0
  28. package/srcSwift/Sources/GearN/runtime/common/Action1.swift +3 -0
  29. package/srcSwift/Sources/GearN/runtime/common/Action2.swift +3 -0
  30. package/srcSwift/Sources/GearN/runtime/common/Action3.swift +3 -0
  31. package/srcSwift/Sources/GearN/runtime/common/Action4.swift +3 -0
  32. package/srcSwift/Sources/GearN/runtime/common/GNArray.swift +204 -0
  33. package/srcSwift/Sources/GearN/runtime/common/GNData.swift +108 -0
  34. package/srcSwift/Sources/GearN/runtime/common/GNHashtable.swift +200 -0
  35. package/srcSwift/Sources/GearN/runtime/config/GNServerSettings.swift +95 -0
  36. package/srcSwift/Sources/GearN/runtime/constant/Commands.swift +28 -0
  37. package/srcSwift/Sources/GearN/runtime/constant/EventCode.swift +10 -0
  38. package/srcSwift/Sources/GearN/runtime/constant/OperationCode.swift +252 -0
  39. package/srcSwift/Sources/GearN/runtime/constant/ReturnCode.swift +19 -0
  40. package/srcSwift/Sources/GearN/runtime/constant/enumType/ExecuteResponseStatus.swift +9 -0
  41. package/srcSwift/Sources/GearN/runtime/constant/enumType/FriendStatus.swift +8 -0
  42. package/srcSwift/Sources/GearN/runtime/constant/enumType/GoogleLoginType.swift +6 -0
  43. package/srcSwift/Sources/GearN/runtime/constant/enumType/GroupStatus.swift +8 -0
  44. package/srcSwift/Sources/GearN/runtime/constant/enumType/InvalidMemberType.swift +19 -0
  45. package/srcSwift/Sources/GearN/runtime/constant/enumType/ItemType.swift +6 -0
  46. package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingMemberStatus.swift +7 -0
  47. package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingTicketStatus.swift +9 -0
  48. package/srcSwift/Sources/GearN/runtime/constant/enumType/OwnerType.swift +10 -0
  49. package/srcSwift/Sources/GearN/runtime/constant/enumType/PermissionDataItem.swift +6 -0
  50. package/srcSwift/Sources/GearN/runtime/constant/enumType/PushPlatformType.swift +6 -0
  51. package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestRole.swift +7 -0
  52. package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestType.swift +16 -0
  53. package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreItemType.swift +6 -0
  54. package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreReceiveType.swift +9 -0
  55. package/srcSwift/Sources/GearN/runtime/constant/errorCode/ErrorCode.swift +58 -0
  56. package/srcSwift/Sources/GearN/runtime/constant/parameterCode/ParameterCode.swift +672 -0
  57. package/srcSwift/Sources/GearN/runtime/entity/DataMember.swift +196 -0
  58. package/srcSwift/Sources/GearN/runtime/entity/GNMetadata.swift +9 -0
  59. package/srcSwift/Sources/GearN/runtime/entity/InvalidMember.swift +11 -0
  60. package/srcSwift/Sources/GearN/runtime/entity/OperationEvent.swift +38 -0
  61. package/srcSwift/Sources/GearN/runtime/entity/OperationHelper.swift +28 -0
  62. package/srcSwift/Sources/GearN/runtime/entity/OperationRequest.swift +62 -0
  63. package/srcSwift/Sources/GearN/runtime/entity/OperationResponse.swift +98 -0
  64. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateModels.swift +351 -0
  65. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateRequestModels.swift +81 -0
  66. package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateResponseModels.swift +108 -0
  67. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerModels.swift +1045 -0
  68. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerRequestModels.swift +821 -0
  69. package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerResponseModels.swift +588 -0
  70. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptModels.swift +187 -0
  71. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptRequestModels.swift +84 -0
  72. package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptResponseModels.swift +59 -0
  73. package/srcSwift/Sources/GearN/runtime/entity/models/ContentModels.swift +195 -0
  74. package/srcSwift/Sources/GearN/runtime/entity/models/ContentRequestModels.swift +116 -0
  75. package/srcSwift/Sources/GearN/runtime/entity/models/ContentResponseModels.swift +81 -0
  76. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardModels.swift +426 -0
  77. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardRequestModels.swift +160 -0
  78. package/srcSwift/Sources/GearN/runtime/entity/models/DashboardResponseModels.swift +82 -0
  79. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerModels.swift +1334 -0
  80. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerRequestModels.swift +643 -0
  81. package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerResponseModels.swift +213 -0
  82. package/srcSwift/Sources/GearN/runtime/entity/models/GenericModels.swift +171 -0
  83. package/srcSwift/Sources/GearN/runtime/entity/models/GroupModels.swift +850 -0
  84. package/srcSwift/Sources/GearN/runtime/entity/models/GroupRequestModels.swift +485 -0
  85. package/srcSwift/Sources/GearN/runtime/entity/models/GroupResponseModels.swift +165 -0
  86. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryModels.swift +679 -0
  87. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryRequestModels.swift +413 -0
  88. package/srcSwift/Sources/GearN/runtime/entity/models/InventoryResponseModels.swift +141 -0
  89. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerModels.swift +378 -0
  90. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerRequestModels.swift +147 -0
  91. package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerResponseModels.swift +318 -0
  92. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerModels.swift +319 -0
  93. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerRequestModels.swift +125 -0
  94. package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerResponseModels.swift +45 -0
  95. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryModels.swift +633 -0
  96. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryRequestModels.swift +173 -0
  97. package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryResponseModels.swift +61 -0
  98. package/srcSwift/Sources/GearN/runtime/entity/request/CustomOperationRequest.swift +42 -0
  99. package/srcSwift/Sources/GearN/runtime/entity/response/CustomOperationResponse.swift +49 -0
  100. package/srcSwift/Sources/GearN/runtime/entity/response/GetAuthInfoResponse.swift +43 -0
  101. package/srcSwift/Sources/GearN/runtime/entity/response/HealthCheckResponse.swift +86 -0
  102. package/srcSwift/Sources/GearN/runtime/entity/response/UploadFileResponse.swift +15 -0
  103. package/srcSwift/Sources/GearN/runtime/helper/CodeHelper.swift +107 -0
  104. package/srcSwift/Sources/GearN/runtime/helper/ConverterService.swift +98 -0
  105. package/srcSwift/Sources/GearN/runtime/helper/EnumUtility.swift +34 -0
  106. package/srcSwift/Sources/GearN/runtime/helper/GNSupport.swift +41 -0
  107. package/srcSwift/Sources/GearN/runtime/helper/GNUtils.swift +66 -0
  108. package/srcSwift/Sources/GearN/runtime/helper/MessagePackConverterService.swift +21 -0
  109. package/srcSwift/Sources/GearN/runtime/helper/StorageService.swift +29 -0
  110. package/srcSwift/Sources/GearN/runtime/logger/GNDebug.swift +33 -0
  111. package/srcSwift/Sources/GearN/runtime/networking/AuthenticateStatus.swift +24 -0
  112. package/srcSwift/Sources/GearN/runtime/networking/IPeer.swift +8 -0
  113. package/srcSwift/Sources/GearN/runtime/networking/NetworkingPeer.swift +368 -0
  114. package/srcSwift/Sources/GearN/runtime/networking/OperationPending.swift +81 -0
  115. package/srcSwift/Sources/GearN/runtime/networking/PeerBase.swift +228 -0
  116. package/srcSwift/Sources/GearN/runtime/networking/handler/IServerEventHandler.swift +20 -0
  117. package/srcSwift/Sources/GearN/runtime/networking/http/HttpPeer.swift +226 -0
  118. package/srcSwift/Sources/GearN/runtime/networking/http/HttpTypes.swift +24 -0
  119. package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingHttpPeerBase.swift +13 -0
  120. package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingPeerUrlSession.swift +125 -0
  121. package/srcSwift/Sources/GearN/runtime/networking/request/NetRequest.swift +19 -0
  122. package/srcSwift/Sources/GearN/runtime/networking/response/NetResponse.swift +13 -0
  123. package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingPeerSocketIOClient.swift +244 -0
  124. package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingSocketPeerBase.swift +59 -0
  125. package/srcSwift/Sources/GearN/runtime/networking/socket/SocketPeer.swift +136 -0
  126. package/tsconfig-build.cocos.json +31 -0
  127. package/webpack.config.cocos.mjs +78 -0
@@ -0,0 +1,530 @@
1
+ import Foundation
2
+
3
+ private let VERSION: String = "2.6"
4
+
5
+ public class GNNetwork {
6
+
7
+ // MARK: - Constants
8
+ public static let AUTH_TOKEN_KEY: String = "[GearN]_AUTH_TOKEN_KEY"
9
+ public static let USER_ID_KEY: String = "[GearN]_USER_ID_KEY"
10
+ public static let GAME_ID_KEY: String = "[GearN]_GAME_ID_KEY"
11
+
12
+ // MARK: - Private Properties
13
+ private static var gnServerSettings: GNServerSettings!
14
+ private static var _peer: NetworkingPeer!
15
+
16
+ // MARK: - Public Properties
17
+ public static var serverTimeOffset: Double = 0
18
+
19
+ // MARK: - API Instances
20
+ public static var authenticate: AuthenticateApi!
21
+ public static var characterPlayer: CharacterPlayerApi!
22
+ public static var content: ContentApi!
23
+ public static var dashboard: DashboardApi!
24
+ public static var gamePlayer: GamePlayerApi!
25
+ public static var group: GroupApi!
26
+ public static var inventory: InventoryApi!
27
+ public static var masterPlayer: MasterPlayerApi!
28
+ public static var storeInventory: StoreInventoryApi!
29
+ public static var multiplayer: MultiplayerApi!
30
+ public static var cloudScript: CloudScriptApi!
31
+ // public static var generic: GenericApi!
32
+
33
+ // MARK: - Getters
34
+ public static func getGNServerSettings() -> GNServerSettings? {
35
+ return gnServerSettings
36
+ }
37
+
38
+ public static func getPeer() -> NetworkingPeer? {
39
+ return _peer
40
+ }
41
+
42
+ public static func getPing() -> Int {
43
+ return _peer != nil ? _peer.getPing() : -1
44
+ }
45
+
46
+ public static func getSocketSId() -> String {
47
+ return _peer != nil ? _peer.getClientId() : ""
48
+ }
49
+
50
+ public static func isSocketConnected() -> Bool {
51
+ let socketSId = getSocketSId()
52
+ return !socketSId.isEmpty
53
+ }
54
+
55
+ public static func getServerTimestamp() -> Int64 {
56
+ return _peer != nil ? _peer.getServerTimestamp() : Int64(Date().timeIntervalSince1970 * 1000)
57
+ }
58
+
59
+ public static func getAuthenticateStatus() -> AuthenticateStatus? {
60
+ return _peer?.authenticateStatus
61
+ }
62
+
63
+ public static func getGameId() -> String {
64
+ return _peer?.gameId ?? ""
65
+ }
66
+
67
+ public static func getPlatform() -> Int {
68
+ #if os(iOS)
69
+ return 18 // iOS platform code
70
+ #elseif os(macOS)
71
+ return 19 // macOS platform code
72
+ #else
73
+ return 17 // Default platform code
74
+ #endif
75
+ }
76
+
77
+ public static func getClientSdkVersion() -> String {
78
+ return VERSION
79
+ }
80
+
81
+ // MARK: - Initialization
82
+ public static func initialize(gnServerSettings: GNServerSettings) {
83
+ if self.gnServerSettings != nil {
84
+ GNDebug.log("GNNetwork has been initialized!")
85
+ return
86
+ }
87
+
88
+ GNSupport.initialize()
89
+ CodeHelper.initialize()
90
+ ConverterService.initialize()
91
+
92
+ self.gnServerSettings = gnServerSettings
93
+
94
+ initServerSettings()
95
+ initGNDebug()
96
+
97
+ GNDebug.log("GNNetwork initialized. Version: \(getClientSdkVersion())")
98
+
99
+ initNetworkPeer()
100
+
101
+ // Restore auth status
102
+ _peer.authenticateStatus.setAuthToken(authToken: StorageService.get(key: AUTH_TOKEN_KEY) as? String ?? "")
103
+ _peer.authenticateStatus.setUserId(userId: StorageService.get(key: USER_ID_KEY) as? String ?? "")
104
+ _peer.gameId = StorageService.get(key: GAME_ID_KEY) as? String ?? ""
105
+
106
+ // Initialize API instances
107
+ authenticate = AuthenticateApi()
108
+ characterPlayer = CharacterPlayerApi()
109
+ content = ContentApi()
110
+ dashboard = DashboardApi()
111
+ gamePlayer = GamePlayerApi()
112
+ group = GroupApi()
113
+ inventory = InventoryApi()
114
+ masterPlayer = MasterPlayerApi()
115
+ storeInventory = StoreInventoryApi()
116
+ multiplayer = MultiplayerApi()
117
+ cloudScript = CloudScriptApi()
118
+ // generic = GenericApi()
119
+ }
120
+
121
+ private static func initServerSettings() {
122
+ // Server settings initialization handled externally
123
+ }
124
+
125
+ private static func initGNDebug() {
126
+ guard gnServerSettings != nil else {
127
+ fatalError("Null GN Server Settings, please configure first")
128
+ }
129
+ GNDebug.setLogType(logType: gnServerSettings.getLogType())
130
+ }
131
+
132
+ private static func initNetworkPeer() {
133
+ let peer = NetworkingPeer()
134
+ peer.initPeer()
135
+ _peer = peer
136
+ }
137
+
138
+ // MARK: - Authentication Management
139
+ public static func setNewAuthenticateStatus(authenticateStatus: AuthenticateStatus) {
140
+ StorageService.set(key: AUTH_TOKEN_KEY, value: authenticateStatus.getAuthToken())
141
+ StorageService.set(key: USER_ID_KEY, value: authenticateStatus.getUserId())
142
+
143
+ _peer.authenticateStatus.setAuthToken(authToken: authenticateStatus.getAuthToken())
144
+ _peer.authenticateStatus.setUserId(userId: authenticateStatus.getUserId())
145
+ }
146
+
147
+ public static func setGameId(gameId: String) {
148
+ StorageService.set(key: GAME_ID_KEY, value: gameId)
149
+ _peer.gameId = gameId
150
+ }
151
+
152
+ // MARK: - Service Loop
153
+ public static func service() {
154
+ _peer?.service()
155
+ }
156
+
157
+ // MARK: - Socket Methods
158
+ public static func sendRequestAuthSocket() {
159
+ _peer?.sendRequestAuthSocket()
160
+ }
161
+
162
+ public static func connectSocket(onSocketConnect: Action0? = nil) {
163
+ _peer?.connectSocket(onSocketConnect: onSocketConnect)
164
+ }
165
+
166
+ public static func disconnectSocket(onSocketDisconnect: Action0? = nil) {
167
+ _peer?.disconnectSocket(onSocketDisconnect: onSocketDisconnect)
168
+ }
169
+
170
+ // MARK: - Event Handlers
171
+ public static func setOnEventHandler(onEventHandler: Action1<OperationEvent>?) {
172
+ _peer?.setOnEventHandler(onEventHandler: onEventHandler)
173
+ }
174
+
175
+ public static func subscribeOnConnectHandler(onConnectHandler: @escaping Action0) {
176
+ _peer?.setOnConnectHandler(onConnectHandler: onConnectHandler)
177
+ }
178
+
179
+ public static func subscribeOnDisconnectHandler(onDisconnectHandler: @escaping Action0) {
180
+ _peer?.setOnDisconnectHandler(onDisconnectHandler: onDisconnectHandler)
181
+ }
182
+
183
+ public static func unsubscribeOnConnectHandler(onConnectHandler: @escaping Action0) {
184
+ _peer?.removeOnConnectHandler(onConnectHandler: onConnectHandler)
185
+ }
186
+
187
+ public static func unsubscribeOnDisconnectHandler(onDisconnectHandler: @escaping Action0) {
188
+ _peer?.removeOnDisconnectHandler(onDisconnectHandler: onDisconnectHandler)
189
+ }
190
+
191
+ public static func subscribeServerEventHandler(serverEventHandler: IServerEventHandler) {
192
+ _peer?.subscribeServerEventHandler(serverEventHandler: serverEventHandler)
193
+ }
194
+
195
+ // MARK: - Raw Send Methods
196
+ public static func sendViaSocket(
197
+ requestType: RequestType,
198
+ role: RequestRole,
199
+ request: OperationRequest,
200
+ onResponse: Action1<OperationResponse>?,
201
+ overrideAuthToken: String? = nil,
202
+ overrideSecretKey: String? = nil,
203
+ customTags: GNHashtable? = nil
204
+ ) {
205
+ _peer?.sendViaSocket(
206
+ requestType: requestType,
207
+ role: role,
208
+ request: request,
209
+ onResponse: onResponse,
210
+ overrideAuthToken: overrideAuthToken ?? "",
211
+ overrideSecretKey: overrideSecretKey ?? "",
212
+ customTags: customTags
213
+ )
214
+ }
215
+
216
+ public static func sendViaSocketAsync(
217
+ requestType: RequestType,
218
+ role: RequestRole,
219
+ request: OperationRequest,
220
+ overrideAuthToken: String? = nil,
221
+ overrideSecretKey: String? = nil,
222
+ customTags: GNHashtable? = nil
223
+ ) async -> OperationResponse {
224
+ return await withCheckedContinuation { continuation in
225
+ sendViaSocket(
226
+ requestType: requestType,
227
+ role: role,
228
+ request: request,
229
+ onResponse: { response in
230
+ continuation.resume(returning: response)
231
+ },
232
+ overrideAuthToken: overrideAuthToken,
233
+ overrideSecretKey: overrideSecretKey,
234
+ customTags: customTags
235
+ )
236
+ }
237
+ }
238
+
239
+ public static func sendViaHttp(
240
+ requestType: RequestType,
241
+ role: RequestRole,
242
+ request: OperationRequest,
243
+ onResponse: Action1<OperationResponse>?,
244
+ overrideAuthToken: String? = nil,
245
+ overrideSecretKey: String? = nil,
246
+ customTags: GNHashtable? = nil
247
+ ) {
248
+ _peer?.sendViaHttp(
249
+ requestType: requestType,
250
+ role: role,
251
+ request: request,
252
+ onResponse: onResponse,
253
+ overrideAuthToken: overrideAuthToken ?? "",
254
+ overrideSecretKey: overrideSecretKey ?? "",
255
+ customTags: customTags
256
+ )
257
+ }
258
+
259
+ public static func sendViaHttpAsync(
260
+ requestType: RequestType,
261
+ role: RequestRole,
262
+ request: OperationRequest,
263
+ overrideAuthToken: String? = nil,
264
+ overrideSecretKey: String? = nil,
265
+ customTags: GNHashtable? = nil
266
+ ) async -> OperationResponse {
267
+ return await withCheckedContinuation { continuation in
268
+ sendViaHttp(
269
+ requestType: requestType,
270
+ role: role,
271
+ request: request,
272
+ onResponse: { response in
273
+ continuation.resume(returning: response)
274
+ },
275
+ overrideAuthToken: overrideAuthToken,
276
+ overrideSecretKey: overrideSecretKey,
277
+ customTags: customTags
278
+ )
279
+ }
280
+ }
281
+
282
+ // MARK: - Typed Send Methods (Socket)
283
+ public static func sendViaSocketTRequestTResponse<TReq: CustomOperationRequest, TRes: CustomOperationResponse>(
284
+ request: TReq,
285
+ onResponse: Action1<TRes>?,
286
+ overrideAuthToken: String? = nil,
287
+ overrideSecretKey: String? = nil,
288
+ customTags: GNHashtable? = nil,
289
+ responseType: TRes.Type
290
+ ) {
291
+ sendViaSocketTResponse(
292
+ requestType: request.getRequestType(),
293
+ role: request.getRole(),
294
+ request: request.build(),
295
+ onResponse: onResponse,
296
+ overrideAuthToken: overrideAuthToken,
297
+ overrideSecretKey: overrideSecretKey,
298
+ customTags: customTags,
299
+ responseType: responseType
300
+ )
301
+ }
302
+
303
+ public static func sendViaSocketTRequestTResponseAsync<TReq: CustomOperationRequest, TRes: CustomOperationResponse>(
304
+ request: TReq,
305
+ overrideAuthToken: String? = nil,
306
+ overrideSecretKey: String? = nil,
307
+ customTags: GNHashtable? = nil,
308
+ responseType: TRes.Type
309
+ ) async -> TRes {
310
+ return await withCheckedContinuation { continuation in
311
+ sendViaSocketTRequestTResponse(
312
+ request: request,
313
+ onResponse: { response in
314
+ continuation.resume(returning: response)
315
+ },
316
+ overrideAuthToken: overrideAuthToken,
317
+ overrideSecretKey: overrideSecretKey,
318
+ customTags: customTags,
319
+ responseType: responseType
320
+ )
321
+ }
322
+ }
323
+
324
+ public static func sendViaSocketTResponse<TRes: CustomOperationResponse>(
325
+ requestType: RequestType,
326
+ role: RequestRole,
327
+ request: OperationRequest,
328
+ onResponse: Action1<TRes>?,
329
+ overrideAuthToken: String? = nil,
330
+ overrideSecretKey: String? = nil,
331
+ customTags: GNHashtable? = nil,
332
+ responseType: TRes.Type
333
+ ) {
334
+ sendViaSocket(
335
+ requestType: requestType,
336
+ role: role,
337
+ request: request,
338
+ onResponse: { response in
339
+ let customResponse = TRes()
340
+ customResponse.setupOperationResponse(operationResponse: response)
341
+ onResponse?(customResponse)
342
+ },
343
+ overrideAuthToken: overrideAuthToken,
344
+ overrideSecretKey: overrideSecretKey,
345
+ customTags: customTags
346
+ )
347
+ }
348
+
349
+ public static func sendViaSocketTResponseAsync<TRes: CustomOperationResponse>(
350
+ requestType: RequestType,
351
+ role: RequestRole,
352
+ request: OperationRequest,
353
+ overrideAuthToken: String? = nil,
354
+ overrideSecretKey: String? = nil,
355
+ customTags: GNHashtable? = nil,
356
+ responseType: TRes.Type
357
+ ) async -> TRes {
358
+ return await withCheckedContinuation { continuation in
359
+ sendViaSocketTResponse(
360
+ requestType: requestType,
361
+ role: role,
362
+ request: request,
363
+ onResponse: { (response: TRes) in
364
+ continuation.resume(returning: response)
365
+ },
366
+ overrideAuthToken: overrideAuthToken,
367
+ overrideSecretKey: overrideSecretKey,
368
+ customTags: customTags,
369
+ responseType: responseType
370
+ )
371
+ }
372
+ }
373
+
374
+ // MARK: - Typed Send Methods (HTTP)
375
+ public static func sendViaHttpTRequestTResponse<TReq: CustomOperationRequest, TRes: CustomOperationResponse>(
376
+ request: TReq,
377
+ onResponse: Action1<TRes>?,
378
+ overrideAuthToken: String? = nil,
379
+ overrideSecretKey: String? = nil,
380
+ customTags: GNHashtable? = nil,
381
+ responseType: TRes.Type
382
+ ) {
383
+ sendViaHttpTResponse(
384
+ requestType: request.getRequestType(),
385
+ role: request.getRole(),
386
+ request: request.build(),
387
+ onResponse: onResponse,
388
+ overrideAuthToken: overrideAuthToken,
389
+ overrideSecretKey: overrideSecretKey,
390
+ customTags: customTags,
391
+ responseType: responseType
392
+ )
393
+ }
394
+
395
+ public static func sendViaHttpTRequestTResponseAsync<TReq: CustomOperationRequest, TRes: CustomOperationResponse>(
396
+ request: TReq,
397
+ overrideAuthToken: String? = nil,
398
+ overrideSecretKey: String? = nil,
399
+ customTags: GNHashtable? = nil,
400
+ responseType: TRes.Type
401
+ ) async -> TRes {
402
+ return await withCheckedContinuation { continuation in
403
+ sendViaHttpTRequestTResponse(
404
+ request: request,
405
+ onResponse: { response in
406
+ continuation.resume(returning: response)
407
+ },
408
+ overrideAuthToken: overrideAuthToken,
409
+ overrideSecretKey: overrideSecretKey,
410
+ customTags: customTags,
411
+ responseType: responseType
412
+ )
413
+ }
414
+ }
415
+
416
+ public static func sendViaHttpTResponse<TRes: CustomOperationResponse>(
417
+ requestType: RequestType,
418
+ role: RequestRole,
419
+ request: OperationRequest,
420
+ onResponse: Action1<TRes>?,
421
+ overrideAuthToken: String? = nil,
422
+ overrideSecretKey: String? = nil,
423
+ customTags: GNHashtable? = nil,
424
+ responseType: TRes.Type
425
+ ) {
426
+ sendViaHttp(
427
+ requestType: requestType,
428
+ role: role,
429
+ request: request,
430
+ onResponse: { response in
431
+ let customResponse = TRes()
432
+ customResponse.setupOperationResponse(operationResponse: response)
433
+ onResponse?(customResponse)
434
+ },
435
+ overrideAuthToken: overrideAuthToken,
436
+ overrideSecretKey: overrideSecretKey,
437
+ customTags: customTags
438
+ )
439
+ }
440
+
441
+ public static func sendViaHttpTResponseAsync<TRes: CustomOperationResponse>(
442
+ requestType: RequestType,
443
+ role: RequestRole,
444
+ request: OperationRequest,
445
+ overrideAuthToken: String? = nil,
446
+ overrideSecretKey: String? = nil,
447
+ customTags: GNHashtable? = nil,
448
+ responseType: TRes.Type
449
+ ) async -> TRes {
450
+ return await withCheckedContinuation { continuation in
451
+ sendViaHttpTResponse(
452
+ requestType: requestType,
453
+ role: role,
454
+ request: request,
455
+ onResponse: { (response: TRes) in
456
+ continuation.resume(returning: response)
457
+ },
458
+ overrideAuthToken: overrideAuthToken,
459
+ overrideSecretKey: overrideSecretKey,
460
+ customTags: customTags,
461
+ responseType: responseType
462
+ )
463
+ }
464
+ }
465
+
466
+ // MARK: - Utility Methods
467
+ public static func syncTs(onResponse: Action1<Int64>? = nil) {
468
+ _peer?.syncTs(onResponse: onResponse)
469
+ }
470
+
471
+ public static func syncTsAsync() async -> Int64 {
472
+ return await withCheckedContinuation { continuation in
473
+ syncTs { response in
474
+ continuation.resume(returning: response)
475
+ }
476
+ }
477
+ }
478
+
479
+ public static func getAuthInfo(authToken: String, onResponse: Action1<GetAuthInfoResponse>? = nil) {
480
+ _peer?.getAuthInfo(authToken: authToken, onResponse: onResponse)
481
+ }
482
+
483
+ public static func getAuthInfoAsync(authToken: String) async -> GetAuthInfoResponse {
484
+ return await withCheckedContinuation { continuation in
485
+ getAuthInfo(authToken: authToken) { response in
486
+ continuation.resume(returning: response)
487
+ }
488
+ }
489
+ }
490
+
491
+ public static func healthCheck(onResponse: Action1<HealthCheckResponse>? = nil) {
492
+ _peer?.healthCheck(onResponse: onResponse)
493
+ }
494
+
495
+ public static func healthCheckAsync() async -> HealthCheckResponse {
496
+ return await withCheckedContinuation { continuation in
497
+ healthCheck { response in
498
+ continuation.resume(returning: response)
499
+ }
500
+ }
501
+ }
502
+
503
+ public static func uploadFile(
504
+ fileId: String,
505
+ content: Data,
506
+ filename: String,
507
+ mimetype: String,
508
+ onResponse: Action1<UploadFileResponse>? = nil
509
+ ) {
510
+ _peer?.uploadFile(fileId: fileId, content: content, filename: filename, mimetype: mimetype, onResponse: onResponse)
511
+ }
512
+
513
+ public static func uploadFileAsync(
514
+ fileId: String,
515
+ content: Data,
516
+ filename: String,
517
+ mimetype: String
518
+ ) async -> UploadFileResponse {
519
+ return await withCheckedContinuation { continuation in
520
+ uploadFile(fileId: fileId, content: content, filename: filename, mimetype: mimetype) { response in
521
+ continuation.resume(returning: response)
522
+ }
523
+ }
524
+ }
525
+
526
+ public static func getDownloadFileUrl(downloadToken: String) -> String {
527
+ guard let settings = gnServerSettings else { return "" }
528
+ return "\(settings.getHttpUrl())/\(NetworkingPeer.DOWNLOAD_FILE)/\(downloadToken)"
529
+ }
530
+ }