@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.
- package/dist/gearn.js.client.js +183 -57
- package/dist/gearn.js.client.min.js +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +183 -57
- package/dist/runtime/GNNetwork.d.ts +1 -1
- package/dist/runtime/helper/GNSupport.d.ts +20 -0
- package/dist/runtime/{entity → helper}/OperationHelper.d.ts +1 -1
- package/dist/runtime/helper/StorageService.d.ts +18 -0
- package/dist/runtime/networking/NetworkingPeer.d.ts +1 -1
- package/dist/runtime/typescript/ServiceUpdate.d.ts +2 -0
- package/docs/COCOS_CREATOR_INTEGRATION.md +116 -0
- package/examples/cocos-creator/GearNExample.ts.txt +176 -0
- package/package.json +3 -2
- package/srcSwift/Package.swift +32 -0
- package/srcSwift/Sources/GearN/runtime/GNNetwork.swift +530 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkAuthenticateApi.swift +178 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkCharacterPlayerApi.swift +1162 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkCloudScriptApi.swift +154 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkContentApi.swift +208 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkDashboardApi.swift +240 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkGamePlayerApi.swift +1369 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkGroupApi.swift +1100 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkInventoryApi.swift +937 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkMasterPlayerApi.swift +2323 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkMultiplayerApi.swift +298 -0
- package/srcSwift/Sources/GearN/runtime/GNNetworkStoreInventoryApi.swift +397 -0
- package/srcSwift/Sources/GearN/runtime/common/Action0.swift +3 -0
- package/srcSwift/Sources/GearN/runtime/common/Action1.swift +3 -0
- package/srcSwift/Sources/GearN/runtime/common/Action2.swift +3 -0
- package/srcSwift/Sources/GearN/runtime/common/Action3.swift +3 -0
- package/srcSwift/Sources/GearN/runtime/common/Action4.swift +3 -0
- package/srcSwift/Sources/GearN/runtime/common/GNArray.swift +204 -0
- package/srcSwift/Sources/GearN/runtime/common/GNData.swift +108 -0
- package/srcSwift/Sources/GearN/runtime/common/GNHashtable.swift +200 -0
- package/srcSwift/Sources/GearN/runtime/config/GNServerSettings.swift +95 -0
- package/srcSwift/Sources/GearN/runtime/constant/Commands.swift +28 -0
- package/srcSwift/Sources/GearN/runtime/constant/EventCode.swift +10 -0
- package/srcSwift/Sources/GearN/runtime/constant/OperationCode.swift +252 -0
- package/srcSwift/Sources/GearN/runtime/constant/ReturnCode.swift +19 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/ExecuteResponseStatus.swift +9 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/FriendStatus.swift +8 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/GoogleLoginType.swift +6 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/GroupStatus.swift +8 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/InvalidMemberType.swift +19 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/ItemType.swift +6 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingMemberStatus.swift +7 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/MatchmakingTicketStatus.swift +9 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/OwnerType.swift +10 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/PermissionDataItem.swift +6 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/PushPlatformType.swift +6 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestRole.swift +7 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/RequestType.swift +16 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreItemType.swift +6 -0
- package/srcSwift/Sources/GearN/runtime/constant/enumType/StoreReceiveType.swift +9 -0
- package/srcSwift/Sources/GearN/runtime/constant/errorCode/ErrorCode.swift +58 -0
- package/srcSwift/Sources/GearN/runtime/constant/parameterCode/ParameterCode.swift +672 -0
- package/srcSwift/Sources/GearN/runtime/entity/DataMember.swift +196 -0
- package/srcSwift/Sources/GearN/runtime/entity/GNMetadata.swift +9 -0
- package/srcSwift/Sources/GearN/runtime/entity/InvalidMember.swift +11 -0
- package/srcSwift/Sources/GearN/runtime/entity/OperationEvent.swift +38 -0
- package/srcSwift/Sources/GearN/runtime/entity/OperationHelper.swift +28 -0
- package/srcSwift/Sources/GearN/runtime/entity/OperationRequest.swift +62 -0
- package/srcSwift/Sources/GearN/runtime/entity/OperationResponse.swift +98 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateModels.swift +351 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateRequestModels.swift +81 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/AuthenticateResponseModels.swift +108 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerModels.swift +1045 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerRequestModels.swift +821 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CharacterPlayerResponseModels.swift +588 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptModels.swift +187 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptRequestModels.swift +84 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/CloudScriptResponseModels.swift +59 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/ContentModels.swift +195 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/ContentRequestModels.swift +116 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/ContentResponseModels.swift +81 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/DashboardModels.swift +426 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/DashboardRequestModels.swift +160 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/DashboardResponseModels.swift +82 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerModels.swift +1334 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerRequestModels.swift +643 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GamePlayerResponseModels.swift +213 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GenericModels.swift +171 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GroupModels.swift +850 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GroupRequestModels.swift +485 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/GroupResponseModels.swift +165 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/InventoryModels.swift +679 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/InventoryRequestModels.swift +413 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/InventoryResponseModels.swift +141 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerModels.swift +378 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerRequestModels.swift +147 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MasterPlayerResponseModels.swift +318 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerModels.swift +319 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerRequestModels.swift +125 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/MultiplayerResponseModels.swift +45 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryModels.swift +633 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryRequestModels.swift +173 -0
- package/srcSwift/Sources/GearN/runtime/entity/models/StoreInventoryResponseModels.swift +61 -0
- package/srcSwift/Sources/GearN/runtime/entity/request/CustomOperationRequest.swift +42 -0
- package/srcSwift/Sources/GearN/runtime/entity/response/CustomOperationResponse.swift +49 -0
- package/srcSwift/Sources/GearN/runtime/entity/response/GetAuthInfoResponse.swift +43 -0
- package/srcSwift/Sources/GearN/runtime/entity/response/HealthCheckResponse.swift +86 -0
- package/srcSwift/Sources/GearN/runtime/entity/response/UploadFileResponse.swift +15 -0
- package/srcSwift/Sources/GearN/runtime/helper/CodeHelper.swift +107 -0
- package/srcSwift/Sources/GearN/runtime/helper/ConverterService.swift +98 -0
- package/srcSwift/Sources/GearN/runtime/helper/EnumUtility.swift +34 -0
- package/srcSwift/Sources/GearN/runtime/helper/GNSupport.swift +41 -0
- package/srcSwift/Sources/GearN/runtime/helper/GNUtils.swift +66 -0
- package/srcSwift/Sources/GearN/runtime/helper/MessagePackConverterService.swift +21 -0
- package/srcSwift/Sources/GearN/runtime/helper/StorageService.swift +29 -0
- package/srcSwift/Sources/GearN/runtime/logger/GNDebug.swift +33 -0
- package/srcSwift/Sources/GearN/runtime/networking/AuthenticateStatus.swift +24 -0
- package/srcSwift/Sources/GearN/runtime/networking/IPeer.swift +8 -0
- package/srcSwift/Sources/GearN/runtime/networking/NetworkingPeer.swift +368 -0
- package/srcSwift/Sources/GearN/runtime/networking/OperationPending.swift +81 -0
- package/srcSwift/Sources/GearN/runtime/networking/PeerBase.swift +228 -0
- package/srcSwift/Sources/GearN/runtime/networking/handler/IServerEventHandler.swift +20 -0
- package/srcSwift/Sources/GearN/runtime/networking/http/HttpPeer.swift +226 -0
- package/srcSwift/Sources/GearN/runtime/networking/http/HttpTypes.swift +24 -0
- package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingHttpPeerBase.swift +13 -0
- package/srcSwift/Sources/GearN/runtime/networking/http/NetworkingPeerUrlSession.swift +125 -0
- package/srcSwift/Sources/GearN/runtime/networking/request/NetRequest.swift +19 -0
- package/srcSwift/Sources/GearN/runtime/networking/response/NetResponse.swift +13 -0
- package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingPeerSocketIOClient.swift +244 -0
- package/srcSwift/Sources/GearN/runtime/networking/socket/NetworkingSocketPeerBase.swift +59 -0
- package/srcSwift/Sources/GearN/runtime/networking/socket/SocketPeer.swift +136 -0
- package/tsconfig-build.cocos.json +31 -0
- package/webpack.config.cocos.mjs +78 -0
package/dist/index.d.ts
CHANGED
|
@@ -136,12 +136,10 @@ import { UploadFileResponse } from "./runtime/entity/response/UploadFileResponse
|
|
|
136
136
|
export { UploadFileResponse };
|
|
137
137
|
import { InvalidMember } from "./runtime/entity/InvalidMember";
|
|
138
138
|
import { OperationEvent } from "./runtime/entity/OperationEvent";
|
|
139
|
-
import { OperationHelper } from "./runtime/entity/OperationHelper";
|
|
140
139
|
import { OperationRequest } from "./runtime/entity/OperationRequest";
|
|
141
140
|
import { OperationResponse } from "./runtime/entity/OperationResponse";
|
|
142
141
|
export { InvalidMember };
|
|
143
142
|
export { OperationEvent };
|
|
144
|
-
export { OperationHelper };
|
|
145
143
|
export { OperationRequest };
|
|
146
144
|
export { OperationResponse };
|
|
147
145
|
import { GNDebug, LogType } from "./runtime/logger/GNDebug";
|
|
@@ -196,10 +194,12 @@ import { GNSupport } from "./runtime/helper/GNSupport";
|
|
|
196
194
|
import { CodeHelper } from "./runtime/helper/CodeHelper";
|
|
197
195
|
import { ConverterService } from "./runtime/helper/ConverterService";
|
|
198
196
|
import { GNUtils } from "./runtime/helper/GNUtils";
|
|
197
|
+
import { OperationHelper } from "./runtime/helper/OperationHelper";
|
|
199
198
|
export { GNSupport };
|
|
200
199
|
export { CodeHelper };
|
|
201
200
|
export { ConverterService };
|
|
202
201
|
export { GNUtils };
|
|
202
|
+
export { OperationHelper };
|
|
203
203
|
import { DataMember, StringDataMember, BooleanDataMember, GNHashtableDataMember, GNArrayDataMember, NumberDataMember } from "./runtime/entity/DataMember";
|
|
204
204
|
export { DataMember, StringDataMember, BooleanDataMember, GNHashtableDataMember, GNArrayDataMember, NumberDataMember };
|
|
205
205
|
import { GNObjectMetadata, AbstractConstructor, Constructor, FieldDataType, GNObjectFieldMetadata } from "./runtime/entity/GNMetadata";
|
package/dist/index.js
CHANGED
|
@@ -312,9 +312,7 @@ class GNHashtable extends GNData {
|
|
|
312
312
|
return Object.keys(this.dict).length;
|
|
313
313
|
}
|
|
314
314
|
containsKey(k) {
|
|
315
|
-
|
|
316
|
-
let kStr = k.toString();
|
|
317
|
-
return keys.indexOf(kStr) != -1;
|
|
315
|
+
return this.dict.hasOwnProperty(k);
|
|
318
316
|
}
|
|
319
317
|
get(k, def) {
|
|
320
318
|
let value = this.dict[k];
|
|
@@ -353,11 +351,11 @@ class GNArrayBuilder {
|
|
|
353
351
|
return this;
|
|
354
352
|
}
|
|
355
353
|
build() {
|
|
356
|
-
let
|
|
354
|
+
let answer = new GNArray();
|
|
357
355
|
this.array.forEach(o => {
|
|
358
|
-
|
|
356
|
+
answer.add(o);
|
|
359
357
|
});
|
|
360
|
-
return
|
|
358
|
+
return answer;
|
|
361
359
|
}
|
|
362
360
|
constructor() {
|
|
363
361
|
this.array = [];
|
|
@@ -26138,32 +26136,6 @@ class CodeHelper {
|
|
|
26138
26136
|
}
|
|
26139
26137
|
}
|
|
26140
26138
|
|
|
26141
|
-
;// ./src/runtime/entity/OperationHelper.ts
|
|
26142
|
-
|
|
26143
|
-
class OperationHelper {
|
|
26144
|
-
static toSocketData(requestType, role, request) {
|
|
26145
|
-
let requestId = request.getRequestId();
|
|
26146
|
-
if (requestId == -1)
|
|
26147
|
-
return [
|
|
26148
|
-
CodeHelper.getRequestTypeName(requestType),
|
|
26149
|
-
CodeHelper.getRequestRoleName(role),
|
|
26150
|
-
request.getOperationCode(),
|
|
26151
|
-
(request.getParameters() == null) ? null : request.getParameters().toData()
|
|
26152
|
-
];
|
|
26153
|
-
else
|
|
26154
|
-
return [
|
|
26155
|
-
CodeHelper.getRequestTypeName(requestType),
|
|
26156
|
-
CodeHelper.getRequestRoleName(role),
|
|
26157
|
-
request.getOperationCode(),
|
|
26158
|
-
(request.getParameters() == null) ? null : request.getParameters().toData(),
|
|
26159
|
-
requestId
|
|
26160
|
-
];
|
|
26161
|
-
}
|
|
26162
|
-
static toHttpData(requestType, role, request) {
|
|
26163
|
-
return null;
|
|
26164
|
-
}
|
|
26165
|
-
}
|
|
26166
|
-
|
|
26167
26139
|
;// ./src/runtime/entity/OperationResponse.ts
|
|
26168
26140
|
|
|
26169
26141
|
|
|
@@ -26255,14 +26227,53 @@ var IServerEventHandler;
|
|
|
26255
26227
|
})(IServerEventHandler || (IServerEventHandler = {}));
|
|
26256
26228
|
|
|
26257
26229
|
;// ./src/runtime/helper/GNSupport.ts
|
|
26230
|
+
// Types from ../types/cocos.d.ts are automatically available
|
|
26258
26231
|
class GNSupport {
|
|
26259
26232
|
static init() {
|
|
26233
|
+
if (this._initialized)
|
|
26234
|
+
return;
|
|
26235
|
+
// Check for Cocos Creator 3.x first (has cc.sys)
|
|
26236
|
+
this._isCocosCreator = (typeof cc !== "undefined" && cc.sys !== undefined);
|
|
26237
|
+
// Browser check (has window but not Node.js)
|
|
26260
26238
|
this._isBrowser = (typeof window !== "undefined");
|
|
26239
|
+
// Determine platform type
|
|
26240
|
+
if (this._isCocosCreator) {
|
|
26241
|
+
this._platformType = "cocos";
|
|
26242
|
+
}
|
|
26243
|
+
else if (this._isBrowser) {
|
|
26244
|
+
this._platformType = "browser";
|
|
26245
|
+
}
|
|
26246
|
+
else {
|
|
26247
|
+
this._platformType = "nodejs";
|
|
26248
|
+
}
|
|
26249
|
+
this._initialized = true;
|
|
26261
26250
|
}
|
|
26251
|
+
/**
|
|
26252
|
+
* Check if running in standard browser environment
|
|
26253
|
+
*/
|
|
26262
26254
|
static isBrowser() {
|
|
26263
26255
|
return this._isBrowser;
|
|
26264
26256
|
}
|
|
26257
|
+
/**
|
|
26258
|
+
* Check if running in Cocos Creator 3.x environment
|
|
26259
|
+
*/
|
|
26260
|
+
static isCocosCreator() {
|
|
26261
|
+
return this._isCocosCreator;
|
|
26262
|
+
}
|
|
26263
|
+
/**
|
|
26264
|
+
* Check if running in Node.js environment
|
|
26265
|
+
*/
|
|
26266
|
+
static isNodeJS() {
|
|
26267
|
+
return this._platformType === "nodejs";
|
|
26268
|
+
}
|
|
26269
|
+
/**
|
|
26270
|
+
* Get the current platform type
|
|
26271
|
+
*/
|
|
26272
|
+
static getPlatformType() {
|
|
26273
|
+
return this._platformType;
|
|
26274
|
+
}
|
|
26265
26275
|
}
|
|
26276
|
+
GNSupport._initialized = false;
|
|
26266
26277
|
|
|
26267
26278
|
;// external "@msgpack/msgpack"
|
|
26268
26279
|
const msgpack_namespaceObject = require("@msgpack/msgpack");
|
|
@@ -26444,6 +26455,32 @@ class NetworkingSocketPeerBase {
|
|
|
26444
26455
|
}
|
|
26445
26456
|
}
|
|
26446
26457
|
|
|
26458
|
+
;// ./src/runtime/helper/OperationHelper.ts
|
|
26459
|
+
|
|
26460
|
+
class OperationHelper {
|
|
26461
|
+
static toSocketData(requestType, role, request) {
|
|
26462
|
+
let requestId = request.getRequestId();
|
|
26463
|
+
if (requestId == -1)
|
|
26464
|
+
return [
|
|
26465
|
+
CodeHelper.getRequestTypeName(requestType),
|
|
26466
|
+
CodeHelper.getRequestRoleName(role),
|
|
26467
|
+
request.getOperationCode(),
|
|
26468
|
+
(request.getParameters() == null) ? null : request.getParameters().toData()
|
|
26469
|
+
];
|
|
26470
|
+
else
|
|
26471
|
+
return [
|
|
26472
|
+
CodeHelper.getRequestTypeName(requestType),
|
|
26473
|
+
CodeHelper.getRequestRoleName(role),
|
|
26474
|
+
request.getOperationCode(),
|
|
26475
|
+
(request.getParameters() == null) ? null : request.getParameters().toData(),
|
|
26476
|
+
requestId
|
|
26477
|
+
];
|
|
26478
|
+
}
|
|
26479
|
+
static toHttpData(requestType, role, request) {
|
|
26480
|
+
return null;
|
|
26481
|
+
}
|
|
26482
|
+
}
|
|
26483
|
+
|
|
26447
26484
|
;// external "socket.io-client"
|
|
26448
26485
|
const external_socket_io_client_namespaceObject = require("socket.io-client");
|
|
26449
26486
|
;// ./src/runtime/networking/socket/NetworkingPeerSocketIOClient.ts
|
|
@@ -26584,7 +26621,7 @@ class OperationPending {
|
|
|
26584
26621
|
constructor(requestType, role, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId) {
|
|
26585
26622
|
this.operationRequest = operationRequest;
|
|
26586
26623
|
this.onOperationResponse = onOperationResponse;
|
|
26587
|
-
this.timeout = Date.now()
|
|
26624
|
+
this.timeout = Date.now() + OperationRequest.defaultTimeOut * 1000;
|
|
26588
26625
|
this.firstSend = 0;
|
|
26589
26626
|
this.secondsSend = 0;
|
|
26590
26627
|
this.requestType = requestType;
|
|
@@ -26613,17 +26650,17 @@ class OperationPending {
|
|
|
26613
26650
|
return this.customTags;
|
|
26614
26651
|
}
|
|
26615
26652
|
onSend() {
|
|
26616
|
-
this.firstSend = Date.now()
|
|
26617
|
-
this.timeout = this.firstSend + this.operationRequest.getTimeout();
|
|
26653
|
+
this.firstSend = Date.now();
|
|
26654
|
+
this.timeout = this.firstSend + this.operationRequest.getTimeout() * 1000;
|
|
26618
26655
|
}
|
|
26619
26656
|
onRecv() {
|
|
26620
|
-
this.secondsSend = Date.now()
|
|
26657
|
+
this.secondsSend = Date.now();
|
|
26621
26658
|
}
|
|
26622
26659
|
getExecuteTimerInMs() {
|
|
26623
26660
|
return (this.secondsSend - this.firstSend);
|
|
26624
26661
|
}
|
|
26625
26662
|
isTimeout() {
|
|
26626
|
-
return this.timeout < Date.now()
|
|
26663
|
+
return this.timeout < Date.now();
|
|
26627
26664
|
}
|
|
26628
26665
|
getOperationRequest() {
|
|
26629
26666
|
return this.operationRequest;
|
|
@@ -26636,6 +26673,70 @@ class OperationPending {
|
|
|
26636
26673
|
;// external "store"
|
|
26637
26674
|
const external_store_namespaceObject = require("store");
|
|
26638
26675
|
var external_store_default = /*#__PURE__*/__webpack_require__.n(external_store_namespaceObject);
|
|
26676
|
+
;// ./src/runtime/helper/StorageService.ts
|
|
26677
|
+
/**
|
|
26678
|
+
* StorageService - Cross-platform storage abstraction for GearN SDK
|
|
26679
|
+
* Supports: Browser localStorage, Node.js, Cocos Creator 3.x
|
|
26680
|
+
*/
|
|
26681
|
+
|
|
26682
|
+
|
|
26683
|
+
// Types from ../types/cocos.d.ts are automatically available
|
|
26684
|
+
class StorageService {
|
|
26685
|
+
/**
|
|
26686
|
+
* Get a value from storage
|
|
26687
|
+
* @param key Storage key
|
|
26688
|
+
* @param defaultValue Default value if key doesn't exist
|
|
26689
|
+
*/
|
|
26690
|
+
static getString(key, defaultValue = "") {
|
|
26691
|
+
try {
|
|
26692
|
+
const _platform = GNSupport.getPlatformType();
|
|
26693
|
+
let value = null;
|
|
26694
|
+
switch (_platform) {
|
|
26695
|
+
case "cocos":
|
|
26696
|
+
value = cc.sys.localStorage.getItem(key);
|
|
26697
|
+
break;
|
|
26698
|
+
case "browser":
|
|
26699
|
+
value = window.localStorage.getItem(key);
|
|
26700
|
+
break;
|
|
26701
|
+
case "nodejs":
|
|
26702
|
+
return external_store_default().get(key, defaultValue);
|
|
26703
|
+
}
|
|
26704
|
+
if (value === null || value === undefined) {
|
|
26705
|
+
return defaultValue;
|
|
26706
|
+
}
|
|
26707
|
+
return value;
|
|
26708
|
+
}
|
|
26709
|
+
catch (error) {
|
|
26710
|
+
console.warn("[StorageService] Error getting value for key:", key, error);
|
|
26711
|
+
return defaultValue;
|
|
26712
|
+
}
|
|
26713
|
+
}
|
|
26714
|
+
/**
|
|
26715
|
+
* Set a value in storage
|
|
26716
|
+
* @param key Storage key
|
|
26717
|
+
* @param value Value to store
|
|
26718
|
+
*/
|
|
26719
|
+
static setString(key, value) {
|
|
26720
|
+
try {
|
|
26721
|
+
const _platform = GNSupport.getPlatformType();
|
|
26722
|
+
switch (_platform) {
|
|
26723
|
+
case "cocos":
|
|
26724
|
+
cc.sys.localStorage.setItem(key, value);
|
|
26725
|
+
break;
|
|
26726
|
+
case "browser":
|
|
26727
|
+
window.localStorage.setItem(key, value);
|
|
26728
|
+
break;
|
|
26729
|
+
case "nodejs":
|
|
26730
|
+
external_store_default().set(key, value);
|
|
26731
|
+
break;
|
|
26732
|
+
}
|
|
26733
|
+
}
|
|
26734
|
+
catch (error) {
|
|
26735
|
+
console.warn("[StorageService] Error setting value for key:", key, error);
|
|
26736
|
+
}
|
|
26737
|
+
}
|
|
26738
|
+
}
|
|
26739
|
+
|
|
26639
26740
|
;// ./src/runtime/networking/PeerBase.ts
|
|
26640
26741
|
|
|
26641
26742
|
|
|
@@ -26674,7 +26775,7 @@ class PeerBase {
|
|
|
26674
26775
|
this.setSendRate(gnServerSettings.getSendRate());
|
|
26675
26776
|
}
|
|
26676
26777
|
enqueue(requestType, role, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId) {
|
|
26677
|
-
if (!this.
|
|
26778
|
+
if (!this.isUse) {
|
|
26678
26779
|
GNDebug.logError("[GearN] Server Settings dont setup to use this to send operation request.");
|
|
26679
26780
|
return;
|
|
26680
26781
|
}
|
|
@@ -26688,7 +26789,7 @@ class PeerBase {
|
|
|
26688
26789
|
return this.isUse;
|
|
26689
26790
|
}
|
|
26690
26791
|
service() {
|
|
26691
|
-
if (!this.
|
|
26792
|
+
if (!this.isUse)
|
|
26692
26793
|
return;
|
|
26693
26794
|
let nowSecond = Date.now() / 1000;
|
|
26694
26795
|
if (this.checkTimeoutOperationPending < nowSecond) {
|
|
@@ -26751,12 +26852,12 @@ class PeerBase {
|
|
|
26751
26852
|
if (parameters.containsKey(ParameterCode.AuthToken)) {
|
|
26752
26853
|
let authToken = parameters.getString(ParameterCode.AuthToken);
|
|
26753
26854
|
GNNetwork.getAuthenticateStatus().setAuthToken(authToken);
|
|
26754
|
-
|
|
26855
|
+
StorageService.setString(GNNetwork.AUTH_TOKEN_KEY, authToken);
|
|
26755
26856
|
}
|
|
26756
26857
|
if (parameters.containsKey(ParameterCode.UserId)) {
|
|
26757
26858
|
let userId = parameters.getString(ParameterCode.UserId);
|
|
26758
26859
|
GNNetwork.getAuthenticateStatus().setUserId(userId);
|
|
26759
|
-
|
|
26860
|
+
StorageService.setString(GNNetwork.USER_ID_KEY, userId);
|
|
26760
26861
|
}
|
|
26761
26862
|
if (parameters.containsKey(ParameterCode.Ts)) {
|
|
26762
26863
|
GNNetwork.peer.setServerTimeMilliseconds(parameters.getNumber(ParameterCode.Ts, new Date().getUTCMilliseconds()));
|
|
@@ -26937,6 +27038,8 @@ class NetworkingPeer {
|
|
|
26937
27038
|
count++;
|
|
26938
27039
|
totalPing += this.socketPeer.ping;
|
|
26939
27040
|
}
|
|
27041
|
+
if (count == 0)
|
|
27042
|
+
return -1;
|
|
26940
27043
|
return totalPing / count;
|
|
26941
27044
|
}
|
|
26942
27045
|
getClientId() {
|
|
@@ -26944,13 +27047,13 @@ class NetworkingPeer {
|
|
|
26944
27047
|
}
|
|
26945
27048
|
setServerTimeMilliseconds(currentServerMilliseconds) {
|
|
26946
27049
|
this.lastCurrentServerMilliseconds = currentServerMilliseconds;
|
|
26947
|
-
this.lastGetCurrentMilliseconds = Date.now()
|
|
27050
|
+
this.lastGetCurrentMilliseconds = Date.now();
|
|
26948
27051
|
}
|
|
26949
27052
|
getServerTimestamp() {
|
|
26950
|
-
return this.lastCurrentServerMilliseconds + ((Date.now()
|
|
27053
|
+
return this.lastCurrentServerMilliseconds + ((Date.now() - this.lastGetCurrentMilliseconds) * 1000);
|
|
26951
27054
|
}
|
|
26952
27055
|
initPeer() {
|
|
26953
|
-
this.setServerTimeMilliseconds(
|
|
27056
|
+
this.setServerTimeMilliseconds(Date.now());
|
|
26954
27057
|
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
26955
27058
|
if (gnServerSettings == null)
|
|
26956
27059
|
throw new Error("Null GN Server Settings, please find it now");
|
|
@@ -27128,12 +27231,22 @@ NetworkingPeer.API_MSG_PACK = "api/" + Commands.RequestCmd_MsgPack;
|
|
|
27128
27231
|
|
|
27129
27232
|
;// ./src/runtime/typescript/ServiceUpdate.ts
|
|
27130
27233
|
class ServiceUpdate {
|
|
27234
|
+
constructor() {
|
|
27235
|
+
this.intervalId = null;
|
|
27236
|
+
}
|
|
27131
27237
|
run() {
|
|
27132
|
-
|
|
27133
|
-
|
|
27134
|
-
|
|
27238
|
+
if (this.intervalId)
|
|
27239
|
+
return;
|
|
27240
|
+
this.intervalId = setInterval(() => {
|
|
27241
|
+
this.update();
|
|
27135
27242
|
}, 50);
|
|
27136
27243
|
}
|
|
27244
|
+
stop() {
|
|
27245
|
+
if (!this.intervalId)
|
|
27246
|
+
return;
|
|
27247
|
+
clearInterval(this.intervalId);
|
|
27248
|
+
this.intervalId = null;
|
|
27249
|
+
}
|
|
27137
27250
|
update() {
|
|
27138
27251
|
if (this.peer != null)
|
|
27139
27252
|
this.peer.service();
|
|
@@ -33035,7 +33148,20 @@ class GNNetwork {
|
|
|
33035
33148
|
return GNNetwork.peer.gameId;
|
|
33036
33149
|
}
|
|
33037
33150
|
static getPlatform() {
|
|
33038
|
-
|
|
33151
|
+
const platform = GNSupport.getPlatformType();
|
|
33152
|
+
// if (platform == "browser" || platform == "nodejs") {
|
|
33153
|
+
// return platform;
|
|
33154
|
+
// }
|
|
33155
|
+
// else if (platform == "cocos") {
|
|
33156
|
+
// if (cc.sys.platform === cc.sys.ANDROID) {
|
|
33157
|
+
// console.log('Running on Android');
|
|
33158
|
+
// } else if (cc.sys.platform === cc.sys.IPHONE) {
|
|
33159
|
+
// console.log('Running on iOS');
|
|
33160
|
+
// } else if (cc.sys.isBrowser) {
|
|
33161
|
+
// console.log('Running in a Web Browser');
|
|
33162
|
+
// }
|
|
33163
|
+
// }
|
|
33164
|
+
return platform;
|
|
33039
33165
|
}
|
|
33040
33166
|
static init(gnServerSettings) {
|
|
33041
33167
|
if (GNNetwork.gnServerSettings != null) {
|
|
@@ -33050,9 +33176,9 @@ class GNNetwork {
|
|
|
33050
33176
|
GNNetwork.initGNDebug();
|
|
33051
33177
|
GNDebug.log("GNNetwork init on " + (GNSupport.isBrowser() ? "browser." : "server.") + " Version: " + GNNetwork.getClientSdkVersion());
|
|
33052
33178
|
GNNetwork.initGNSocketObject();
|
|
33053
|
-
GNNetwork.peer.authenticateStatus.setAuthToken(
|
|
33054
|
-
GNNetwork.peer.authenticateStatus.setUserId(
|
|
33055
|
-
GNNetwork.peer.gameId =
|
|
33179
|
+
GNNetwork.peer.authenticateStatus.setAuthToken(StorageService.getString(GNNetwork.AUTH_TOKEN_KEY, ""));
|
|
33180
|
+
GNNetwork.peer.authenticateStatus.setUserId(StorageService.getString(GNNetwork.USER_ID_KEY, ""));
|
|
33181
|
+
GNNetwork.peer.gameId = StorageService.getString(GNNetwork.GAME_ID_KEY, "");
|
|
33056
33182
|
GNNetwork.authenticate = new AuthenticateApi();
|
|
33057
33183
|
GNNetwork.characterPlayer = new CharacterPlayerApi();
|
|
33058
33184
|
GNNetwork.content = new ContentApi();
|
|
@@ -33066,13 +33192,13 @@ class GNNetwork {
|
|
|
33066
33192
|
GNNetwork.cloudScript = new CloudScriptApi();
|
|
33067
33193
|
}
|
|
33068
33194
|
static setNewAuthenticateStatus(authenticateStatus) {
|
|
33069
|
-
|
|
33070
|
-
|
|
33195
|
+
StorageService.setString(GNNetwork.AUTH_TOKEN_KEY, authenticateStatus.getAuthToken());
|
|
33196
|
+
StorageService.setString(GNNetwork.USER_ID_KEY, authenticateStatus.getUserId());
|
|
33071
33197
|
GNNetwork.peer.authenticateStatus.setAuthToken(authenticateStatus.getAuthToken());
|
|
33072
33198
|
GNNetwork.peer.authenticateStatus.setUserId(authenticateStatus.getUserId());
|
|
33073
33199
|
}
|
|
33074
33200
|
static setGameId(gameId) {
|
|
33075
|
-
|
|
33201
|
+
StorageService.setString(GNNetwork.GAME_ID_KEY, gameId);
|
|
33076
33202
|
GNNetwork.peer.gameId = gameId;
|
|
33077
33203
|
}
|
|
33078
33204
|
static getClientSdkVersion() {
|
|
@@ -33351,7 +33477,7 @@ class NetworkingPeerAxiosRequest extends NetworkingHttpPeerBase {
|
|
|
33351
33477
|
}
|
|
33352
33478
|
else if (postType == PostType.MsgPack) {
|
|
33353
33479
|
let content = param.toData();
|
|
33354
|
-
body =
|
|
33480
|
+
body = new Uint8Array(MessagePackConverterService.serialize(content));
|
|
33355
33481
|
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_MSGPACK;
|
|
33356
33482
|
headers[Commands.ACCEPT] = Commands.APPLICATION_MSGPACK;
|
|
33357
33483
|
if (!GNSupport.isBrowser())
|
|
@@ -34021,8 +34147,6 @@ OnGroupMessageUpdateEventHandler = OnGroupMessageUpdateEventHandler_1 = OnGroupM
|
|
|
34021
34147
|
|
|
34022
34148
|
|
|
34023
34149
|
|
|
34024
|
-
|
|
34025
|
-
|
|
34026
34150
|
|
|
34027
34151
|
|
|
34028
34152
|
|
|
@@ -34100,6 +34224,8 @@ OnGroupMessageUpdateEventHandler = OnGroupMessageUpdateEventHandler_1 = OnGroupM
|
|
|
34100
34224
|
|
|
34101
34225
|
|
|
34102
34226
|
|
|
34227
|
+
|
|
34228
|
+
|
|
34103
34229
|
|
|
34104
34230
|
|
|
34105
34231
|
|
|
@@ -41,7 +41,7 @@ export declare class GNNetwork {
|
|
|
41
41
|
static getServerTimestamp(): number;
|
|
42
42
|
static getAuthenticateStatus(): AuthenticateStatus;
|
|
43
43
|
static getGameId(): string;
|
|
44
|
-
static getPlatform():
|
|
44
|
+
static getPlatform(): string;
|
|
45
45
|
static authenticate: AuthenticateApi;
|
|
46
46
|
static characterPlayer: CharacterPlayerApi;
|
|
47
47
|
static content: ContentApi;
|
|
@@ -1,5 +1,25 @@
|
|
|
1
|
+
type PlatformType = "cocos" | "browser" | "nodejs";
|
|
1
2
|
export declare class GNSupport {
|
|
2
3
|
private static _isBrowser;
|
|
4
|
+
private static _isCocosCreator;
|
|
5
|
+
private static _platformType;
|
|
6
|
+
private static _initialized;
|
|
3
7
|
static init(): void;
|
|
8
|
+
/**
|
|
9
|
+
* Check if running in standard browser environment
|
|
10
|
+
*/
|
|
4
11
|
static isBrowser(): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Check if running in Cocos Creator 3.x environment
|
|
14
|
+
*/
|
|
15
|
+
static isCocosCreator(): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Check if running in Node.js environment
|
|
18
|
+
*/
|
|
19
|
+
static isNodeJS(): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Get the current platform type
|
|
22
|
+
*/
|
|
23
|
+
static getPlatformType(): PlatformType;
|
|
5
24
|
}
|
|
25
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RequestRole } from "./../constant/enumType/RequestRole";
|
|
2
2
|
import { RequestType } from "./../constant/enumType/RequestType";
|
|
3
|
-
import { OperationRequest } from "
|
|
3
|
+
import { OperationRequest } from "./../entity/OperationRequest";
|
|
4
4
|
export declare class OperationHelper {
|
|
5
5
|
static toSocketData(requestType: RequestType, role: RequestRole, request: OperationRequest): any;
|
|
6
6
|
static toHttpData(requestType: RequestType, role: RequestRole, request: OperationRequest): any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageService - Cross-platform storage abstraction for GearN SDK
|
|
3
|
+
* Supports: Browser localStorage, Node.js, Cocos Creator 3.x
|
|
4
|
+
*/
|
|
5
|
+
export declare class StorageService {
|
|
6
|
+
/**
|
|
7
|
+
* Get a value from storage
|
|
8
|
+
* @param key Storage key
|
|
9
|
+
* @param defaultValue Default value if key doesn't exist
|
|
10
|
+
*/
|
|
11
|
+
static getString(key: string, defaultValue?: string): any;
|
|
12
|
+
/**
|
|
13
|
+
* Set a value in storage
|
|
14
|
+
* @param key Storage key
|
|
15
|
+
* @param value Value to store
|
|
16
|
+
*/
|
|
17
|
+
static setString(key: string, value: string): void;
|
|
18
|
+
}
|
|
@@ -10,7 +10,7 @@ import { RequestType } from "./../constant/enumType/RequestType";
|
|
|
10
10
|
import { RequestRole } from "./../constant/enumType/RequestRole";
|
|
11
11
|
import { GetAuthInfoResponse } from "./../entity/response/GetAuthInfoResponse";
|
|
12
12
|
import { UploadFileResponse } from "./../entity/response/UploadFileResponse";
|
|
13
|
-
import { HealthCheckResponse } from "
|
|
13
|
+
import { HealthCheckResponse } from "./../entity/response/HealthCheckResponse";
|
|
14
14
|
export declare class NetworkingPeer {
|
|
15
15
|
static readonly SYNC_TS: string;
|
|
16
16
|
static readonly GET_AUTH_INFO: string;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# GearN SDK - Cocos Creator 3.x Integration Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
GearN TypeScript SDK hỗ trợ đầy đủ Cocos Creator 3.x thông qua npm package.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
### 1. Cài đặt qua npm
|
|
10
|
+
|
|
11
|
+
Trong thư mục project Cocos Creator của bạn:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @xmobitea/gn-typescript-client
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. TypeScript Configuration
|
|
18
|
+
|
|
19
|
+
Đảm bảo `tsconfig.json` của Cocos Creator project có cài đặt tương thích:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"compilerOptions": {
|
|
24
|
+
"esModuleInterop": true,
|
|
25
|
+
"experimentalDecorators": true,
|
|
26
|
+
"emitDecoratorMetadata": true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Basic Usage
|
|
32
|
+
|
|
33
|
+
### Initialize SDK
|
|
34
|
+
|
|
35
|
+
```typescript
|
|
36
|
+
import { GNNetwork, GNServerSettings, LogType, MessageType } from '@xmobitea/gn-typescript-client';
|
|
37
|
+
|
|
38
|
+
// Tạo server settings
|
|
39
|
+
const settings = new GNServerSettings({
|
|
40
|
+
httpUrl: "http://your-server:8080",
|
|
41
|
+
socketUrl: "ws://your-server:8080",
|
|
42
|
+
secretKey: "your-secret-key",
|
|
43
|
+
useSocket: true,
|
|
44
|
+
useHttp: true,
|
|
45
|
+
logType: LogType.All,
|
|
46
|
+
sendRate: 30,
|
|
47
|
+
messageType: MessageType.MsgPack,
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
// Initialize
|
|
51
|
+
GNNetwork.init(settings);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Authentication
|
|
55
|
+
|
|
56
|
+
```typescript
|
|
57
|
+
// Login với Device ID
|
|
58
|
+
const response = await GNNetwork.authenticate.loginDeviceIdAsync({
|
|
59
|
+
deviceId: "unique-device-id",
|
|
60
|
+
createAccount: true,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (!response.hasError()) {
|
|
64
|
+
console.log("User ID:", GNNetwork.getAuthenticateStatus().getUserId());
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Socket Connection
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// Subscribe events
|
|
72
|
+
GNNetwork.subscriberOnConnectHandler(() => {
|
|
73
|
+
console.log("Connected!");
|
|
74
|
+
GNNetwork.sendRequestAuthSocket();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
GNNetwork.subscriberOnDisconnectHandler(() => {
|
|
78
|
+
console.log("Disconnected!");
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// Connect
|
|
82
|
+
GNNetwork.connectSocket();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Example Component
|
|
86
|
+
|
|
87
|
+
Xem file mẫu hoàn chỉnh tại: [examples/cocos-creator/GearNExample.ts](../examples/cocos-creator/GearNExample.ts)
|
|
88
|
+
|
|
89
|
+
## Platform Detection
|
|
90
|
+
|
|
91
|
+
SDK tự động phát hiện Cocos Creator environment:
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
import { GNSupport } from '@xmobitea/gn-typescript-client';
|
|
95
|
+
|
|
96
|
+
if (GNSupport.isCocosCreator()) {
|
|
97
|
+
console.log("Running in Cocos Creator");
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Storage
|
|
102
|
+
|
|
103
|
+
SDK tự động sử dụng `cc.sys.localStorage` trong Cocos Creator để lưu auth token.
|
|
104
|
+
|
|
105
|
+
## Troubleshooting
|
|
106
|
+
|
|
107
|
+
### Module not found
|
|
108
|
+
Đảm bảo đã chạy `npm install` trong project folder.
|
|
109
|
+
|
|
110
|
+
### Build errors
|
|
111
|
+
Kiểm tra `tsconfig.json` có `esModuleInterop: true`.
|
|
112
|
+
|
|
113
|
+
## Support
|
|
114
|
+
|
|
115
|
+
- GitHub Issues: https://github.com/XmobiTea-Family/GearN-typescript-client-sdk/issues
|
|
116
|
+
- Homepage: https://gearn.net
|