@xmobitea/gn-typescript-client 2.6.12-tsc → 2.6.13-tsc
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/LICENSE +1 -1
- package/README.MD +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/runtime/GNNetwork.d.ts +1 -1
- package/dist/runtime/GNNetwork.js +21 -8
- package/dist/runtime/common/GNData.js +4 -6
- package/dist/runtime/helper/GNSupport.d.ts +20 -0
- package/dist/runtime/helper/GNSupport.js +39 -0
- package/dist/runtime/{entity → helper}/OperationHelper.d.ts +1 -1
- package/dist/runtime/{entity → helper}/OperationHelper.js +1 -1
- package/dist/runtime/helper/StorageService.d.ts +18 -0
- package/dist/runtime/helper/StorageService.js +62 -0
- package/dist/runtime/networking/NetworkingPeer.d.ts +1 -1
- package/dist/runtime/networking/NetworkingPeer.js +5 -3
- package/dist/runtime/networking/OperationPending.js +5 -5
- package/dist/runtime/networking/PeerBase.js +5 -5
- package/dist/runtime/networking/http/NetworkingPeerAxiosRequest.js +1 -1
- package/dist/runtime/networking/socket/NetworkingPeerSocketIOClient.js +1 -1
- package/dist/runtime/typescript/ServiceUpdate.d.ts +2 -0
- package/dist/runtime/typescript/ServiceUpdate.js +13 -3
- package/docs/COCOS_CREATOR_INTEGRATION.md +116 -0
- package/examples/cocos-creator/GearNExample.ts.txt +176 -0
- package/package.json +12 -11
- 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/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright [2020 -
|
|
189
|
+
Copyright [2020 - 2026] [XmobiTea Family]
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
package/README.MD
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is GearN-typescript-client-sdk use for GearN-server
|
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
|
@@ -125,11 +125,9 @@ export { HealthCheckResponse };
|
|
|
125
125
|
import { UploadFileResponse } from "./runtime/entity/response/UploadFileResponse";
|
|
126
126
|
export { UploadFileResponse };
|
|
127
127
|
import { OperationEvent } from "./runtime/entity/OperationEvent";
|
|
128
|
-
import { OperationHelper } from "./runtime/entity/OperationHelper";
|
|
129
128
|
import { OperationRequest } from "./runtime/entity/OperationRequest";
|
|
130
129
|
import { OperationResponse } from "./runtime/entity/OperationResponse";
|
|
131
130
|
export { OperationEvent };
|
|
132
|
-
export { OperationHelper };
|
|
133
131
|
export { OperationRequest };
|
|
134
132
|
export { OperationResponse };
|
|
135
133
|
import { GNDebug, LogType } from "./runtime/logger/GNDebug";
|
|
@@ -190,10 +188,12 @@ import { GNSupport } from "./runtime/helper/GNSupport";
|
|
|
190
188
|
import { CodeHelper } from "./runtime/helper/CodeHelper";
|
|
191
189
|
import { ConverterService } from "./runtime/helper/ConverterService";
|
|
192
190
|
import { GNUtils } from "./runtime/helper/GNUtils";
|
|
191
|
+
import { OperationHelper } from "./runtime/helper/OperationHelper";
|
|
193
192
|
export { GNSupport };
|
|
194
193
|
export { CodeHelper };
|
|
195
194
|
export { ConverterService };
|
|
196
195
|
export { GNUtils };
|
|
196
|
+
export { OperationHelper };
|
|
197
197
|
import { DataMember, StringDataMember, BooleanDataMember, GNHashtableDataMember, GNArrayDataMember, NumberDataMember } from "./runtime/entity/DataMember";
|
|
198
198
|
export { DataMember, StringDataMember, BooleanDataMember, GNHashtableDataMember, GNArrayDataMember, NumberDataMember };
|
|
199
199
|
import { FieldDataType } from "./runtime/entity/GNMetadata";
|
|
@@ -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;
|
|
@@ -3,7 +3,7 @@ import { GNDebug } from "./logger/GNDebug";
|
|
|
3
3
|
import { GNSupport } from "./helper/GNSupport";
|
|
4
4
|
import { NetworkingPeer } from "./networking/NetworkingPeer";
|
|
5
5
|
import { CodeHelper } from "./helper/CodeHelper";
|
|
6
|
-
import
|
|
6
|
+
import { StorageService } from "./helper/StorageService";
|
|
7
7
|
import { ServiceUpdate } from "./typescript/ServiceUpdate";
|
|
8
8
|
import { AuthenticateApi } from "./GNNetworkAuthenticateApi";
|
|
9
9
|
import { CharacterPlayerApi } from "./GNNetworkCharacterPlayerApi";
|
|
@@ -46,7 +46,20 @@ export class GNNetwork {
|
|
|
46
46
|
return GNNetwork.peer.gameId;
|
|
47
47
|
}
|
|
48
48
|
static getPlatform() {
|
|
49
|
-
|
|
49
|
+
const platform = GNSupport.getPlatformType();
|
|
50
|
+
// if (platform == "browser" || platform == "nodejs") {
|
|
51
|
+
// return platform;
|
|
52
|
+
// }
|
|
53
|
+
// else if (platform == "cocos") {
|
|
54
|
+
// if (cc.sys.platform === cc.sys.ANDROID) {
|
|
55
|
+
// console.log('Running on Android');
|
|
56
|
+
// } else if (cc.sys.platform === cc.sys.IPHONE) {
|
|
57
|
+
// console.log('Running on iOS');
|
|
58
|
+
// } else if (cc.sys.isBrowser) {
|
|
59
|
+
// console.log('Running in a Web Browser');
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
return platform;
|
|
50
63
|
}
|
|
51
64
|
static init(gnServerSettings) {
|
|
52
65
|
if (GNNetwork.gnServerSettings != null) {
|
|
@@ -61,9 +74,9 @@ export class GNNetwork {
|
|
|
61
74
|
GNNetwork.initGNDebug();
|
|
62
75
|
GNDebug.log("GNNetwork init on " + (GNSupport.isBrowser() ? "browser." : "server.") + " Version: " + GNNetwork.getClientSdkVersion());
|
|
63
76
|
GNNetwork.initGNSocketObject();
|
|
64
|
-
GNNetwork.peer.authenticateStatus.setAuthToken(
|
|
65
|
-
GNNetwork.peer.authenticateStatus.setUserId(
|
|
66
|
-
GNNetwork.peer.gameId =
|
|
77
|
+
GNNetwork.peer.authenticateStatus.setAuthToken(StorageService.getString(GNNetwork.AUTH_TOKEN_KEY, ""));
|
|
78
|
+
GNNetwork.peer.authenticateStatus.setUserId(StorageService.getString(GNNetwork.USER_ID_KEY, ""));
|
|
79
|
+
GNNetwork.peer.gameId = StorageService.getString(GNNetwork.GAME_ID_KEY, "");
|
|
67
80
|
GNNetwork.authenticate = new AuthenticateApi();
|
|
68
81
|
GNNetwork.characterPlayer = new CharacterPlayerApi();
|
|
69
82
|
GNNetwork.content = new ContentApi();
|
|
@@ -77,13 +90,13 @@ export class GNNetwork {
|
|
|
77
90
|
GNNetwork.cloudScript = new CloudScriptApi();
|
|
78
91
|
}
|
|
79
92
|
static setNewAuthenticateStatus(authenticateStatus) {
|
|
80
|
-
|
|
81
|
-
|
|
93
|
+
StorageService.setString(GNNetwork.AUTH_TOKEN_KEY, authenticateStatus.getAuthToken());
|
|
94
|
+
StorageService.setString(GNNetwork.USER_ID_KEY, authenticateStatus.getUserId());
|
|
82
95
|
GNNetwork.peer.authenticateStatus.setAuthToken(authenticateStatus.getAuthToken());
|
|
83
96
|
GNNetwork.peer.authenticateStatus.setUserId(authenticateStatus.getUserId());
|
|
84
97
|
}
|
|
85
98
|
static setGameId(gameId) {
|
|
86
|
-
|
|
99
|
+
StorageService.setString(GNNetwork.GAME_ID_KEY, gameId);
|
|
87
100
|
GNNetwork.peer.gameId = gameId;
|
|
88
101
|
}
|
|
89
102
|
static getClientSdkVersion() {
|
|
@@ -115,9 +115,7 @@ export class GNHashtable extends GNData {
|
|
|
115
115
|
return Object.keys(this.dict).length;
|
|
116
116
|
}
|
|
117
117
|
containsKey(k) {
|
|
118
|
-
|
|
119
|
-
let kStr = k.toString();
|
|
120
|
-
return keys.indexOf(kStr) != -1;
|
|
118
|
+
return this.dict.hasOwnProperty(k);
|
|
121
119
|
}
|
|
122
120
|
get(k, def) {
|
|
123
121
|
let value = this.dict[k];
|
|
@@ -156,11 +154,11 @@ export class GNArrayBuilder {
|
|
|
156
154
|
return this;
|
|
157
155
|
}
|
|
158
156
|
build() {
|
|
159
|
-
let
|
|
157
|
+
let answer = new GNArray();
|
|
160
158
|
this.array.forEach(o => {
|
|
161
|
-
|
|
159
|
+
answer.add(o);
|
|
162
160
|
});
|
|
163
|
-
return
|
|
161
|
+
return answer;
|
|
164
162
|
}
|
|
165
163
|
constructor() {
|
|
166
164
|
this.array = [];
|
|
@@ -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,8 +1,47 @@
|
|
|
1
|
+
// Types from ../types/cocos.d.ts are automatically available
|
|
1
2
|
export class GNSupport {
|
|
2
3
|
static init() {
|
|
4
|
+
if (this._initialized)
|
|
5
|
+
return;
|
|
6
|
+
// Check for Cocos Creator 3.x first (has cc.sys)
|
|
7
|
+
this._isCocosCreator = (typeof cc !== "undefined" && cc.sys !== undefined);
|
|
8
|
+
// Browser check (has window but not Node.js)
|
|
3
9
|
this._isBrowser = (typeof window !== "undefined");
|
|
10
|
+
// Determine platform type
|
|
11
|
+
if (this._isCocosCreator) {
|
|
12
|
+
this._platformType = "cocos";
|
|
13
|
+
}
|
|
14
|
+
else if (this._isBrowser) {
|
|
15
|
+
this._platformType = "browser";
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
this._platformType = "nodejs";
|
|
19
|
+
}
|
|
20
|
+
this._initialized = true;
|
|
4
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Check if running in standard browser environment
|
|
24
|
+
*/
|
|
5
25
|
static isBrowser() {
|
|
6
26
|
return this._isBrowser;
|
|
7
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Check if running in Cocos Creator 3.x environment
|
|
30
|
+
*/
|
|
31
|
+
static isCocosCreator() {
|
|
32
|
+
return this._isCocosCreator;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Check if running in Node.js environment
|
|
36
|
+
*/
|
|
37
|
+
static isNodeJS() {
|
|
38
|
+
return this._platformType === "nodejs";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get the current platform type
|
|
42
|
+
*/
|
|
43
|
+
static getPlatformType() {
|
|
44
|
+
return this._platformType;
|
|
45
|
+
}
|
|
8
46
|
}
|
|
47
|
+
GNSupport._initialized = false;
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StorageService - Cross-platform storage abstraction for GearN SDK
|
|
3
|
+
* Supports: Browser localStorage, Node.js, Cocos Creator 3.x
|
|
4
|
+
*/
|
|
5
|
+
import store from "store";
|
|
6
|
+
import { GNSupport } from "./GNSupport";
|
|
7
|
+
// Types from ../types/cocos.d.ts are automatically available
|
|
8
|
+
export class StorageService {
|
|
9
|
+
/**
|
|
10
|
+
* Get a value from storage
|
|
11
|
+
* @param key Storage key
|
|
12
|
+
* @param defaultValue Default value if key doesn't exist
|
|
13
|
+
*/
|
|
14
|
+
static getString(key, defaultValue = "") {
|
|
15
|
+
try {
|
|
16
|
+
const _platform = GNSupport.getPlatformType();
|
|
17
|
+
let value = null;
|
|
18
|
+
switch (_platform) {
|
|
19
|
+
case "cocos":
|
|
20
|
+
value = cc.sys.localStorage.getItem(key);
|
|
21
|
+
break;
|
|
22
|
+
case "browser":
|
|
23
|
+
value = window.localStorage.getItem(key);
|
|
24
|
+
break;
|
|
25
|
+
case "nodejs":
|
|
26
|
+
return store.get(key, defaultValue);
|
|
27
|
+
}
|
|
28
|
+
if (value === null || value === undefined) {
|
|
29
|
+
return defaultValue;
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
console.warn("[StorageService] Error getting value for key:", key, error);
|
|
35
|
+
return defaultValue;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Set a value in storage
|
|
40
|
+
* @param key Storage key
|
|
41
|
+
* @param value Value to store
|
|
42
|
+
*/
|
|
43
|
+
static setString(key, value) {
|
|
44
|
+
try {
|
|
45
|
+
const _platform = GNSupport.getPlatformType();
|
|
46
|
+
switch (_platform) {
|
|
47
|
+
case "cocos":
|
|
48
|
+
cc.sys.localStorage.setItem(key, value);
|
|
49
|
+
break;
|
|
50
|
+
case "browser":
|
|
51
|
+
window.localStorage.setItem(key, value);
|
|
52
|
+
break;
|
|
53
|
+
case "nodejs":
|
|
54
|
+
store.set(key, value);
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
catch (error) {
|
|
59
|
+
console.warn("[StorageService] Error setting value for key:", key, error);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -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;
|
|
@@ -18,6 +18,8 @@ export class NetworkingPeer {
|
|
|
18
18
|
count++;
|
|
19
19
|
totalPing += this.socketPeer.ping;
|
|
20
20
|
}
|
|
21
|
+
if (count == 0)
|
|
22
|
+
return -1;
|
|
21
23
|
return totalPing / count;
|
|
22
24
|
}
|
|
23
25
|
getClientId() {
|
|
@@ -25,13 +27,13 @@ export class NetworkingPeer {
|
|
|
25
27
|
}
|
|
26
28
|
setServerTimeMilliseconds(currentServerMilliseconds) {
|
|
27
29
|
this.lastCurrentServerMilliseconds = currentServerMilliseconds;
|
|
28
|
-
this.lastGetCurrentMilliseconds = Date.now()
|
|
30
|
+
this.lastGetCurrentMilliseconds = Date.now();
|
|
29
31
|
}
|
|
30
32
|
getServerTimestamp() {
|
|
31
|
-
return this.lastCurrentServerMilliseconds + ((Date.now()
|
|
33
|
+
return this.lastCurrentServerMilliseconds + ((Date.now() - this.lastGetCurrentMilliseconds) * 1000);
|
|
32
34
|
}
|
|
33
35
|
initPeer() {
|
|
34
|
-
this.setServerTimeMilliseconds(
|
|
36
|
+
this.setServerTimeMilliseconds(Date.now());
|
|
35
37
|
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
36
38
|
if (gnServerSettings == null)
|
|
37
39
|
throw new Error("Null GN Server Settings, please find it now");
|
|
@@ -3,7 +3,7 @@ export class OperationPending {
|
|
|
3
3
|
constructor(requestType, role, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId) {
|
|
4
4
|
this.operationRequest = operationRequest;
|
|
5
5
|
this.onOperationResponse = onOperationResponse;
|
|
6
|
-
this.timeout = Date.now()
|
|
6
|
+
this.timeout = Date.now() + OperationRequest.defaultTimeOut * 1000;
|
|
7
7
|
this.firstSend = 0;
|
|
8
8
|
this.secondsSend = 0;
|
|
9
9
|
this.requestType = requestType;
|
|
@@ -32,17 +32,17 @@ export class OperationPending {
|
|
|
32
32
|
return this.customTags;
|
|
33
33
|
}
|
|
34
34
|
onSend() {
|
|
35
|
-
this.firstSend = Date.now()
|
|
36
|
-
this.timeout = this.firstSend + this.operationRequest.getTimeout();
|
|
35
|
+
this.firstSend = Date.now();
|
|
36
|
+
this.timeout = this.firstSend + this.operationRequest.getTimeout() * 1000;
|
|
37
37
|
}
|
|
38
38
|
onRecv() {
|
|
39
|
-
this.secondsSend = Date.now()
|
|
39
|
+
this.secondsSend = Date.now();
|
|
40
40
|
}
|
|
41
41
|
getExecuteTimerInMs() {
|
|
42
42
|
return (this.secondsSend - this.firstSend);
|
|
43
43
|
}
|
|
44
44
|
isTimeout() {
|
|
45
|
-
return this.timeout < Date.now()
|
|
45
|
+
return this.timeout < Date.now();
|
|
46
46
|
}
|
|
47
47
|
getOperationRequest() {
|
|
48
48
|
return this.operationRequest;
|
|
@@ -5,7 +5,7 @@ import { OperationResponse } from "./../entity/OperationResponse";
|
|
|
5
5
|
import { GNNetwork } from "./../GNNetwork";
|
|
6
6
|
import { GNDebug } from "./../logger/GNDebug";
|
|
7
7
|
import { OperationPending } from "./OperationPending";
|
|
8
|
-
import
|
|
8
|
+
import { StorageService } from "./../helper/StorageService";
|
|
9
9
|
export class PeerBase {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.perMsgTimer = 0;
|
|
@@ -35,7 +35,7 @@ export class PeerBase {
|
|
|
35
35
|
this.setSendRate(gnServerSettings.getSendRate());
|
|
36
36
|
}
|
|
37
37
|
enqueue(requestType, role, operationRequest, onOperationResponse, authToken, secretKey, customTags, gameId) {
|
|
38
|
-
if (!this.
|
|
38
|
+
if (!this.isUse) {
|
|
39
39
|
GNDebug.logError("[GearN] Server Settings dont setup to use this to send operation request.");
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
@@ -49,7 +49,7 @@ export class PeerBase {
|
|
|
49
49
|
return this.isUse;
|
|
50
50
|
}
|
|
51
51
|
service() {
|
|
52
|
-
if (!this.
|
|
52
|
+
if (!this.isUse)
|
|
53
53
|
return;
|
|
54
54
|
let nowSecond = Date.now() / 1000;
|
|
55
55
|
if (this.checkTimeoutOperationPending < nowSecond) {
|
|
@@ -112,12 +112,12 @@ export class PeerBase {
|
|
|
112
112
|
if (parameters.containsKey(ParameterCode.AuthToken)) {
|
|
113
113
|
let authToken = parameters.getString(ParameterCode.AuthToken);
|
|
114
114
|
GNNetwork.getAuthenticateStatus().setAuthToken(authToken);
|
|
115
|
-
|
|
115
|
+
StorageService.setString(GNNetwork.AUTH_TOKEN_KEY, authToken);
|
|
116
116
|
}
|
|
117
117
|
if (parameters.containsKey(ParameterCode.UserId)) {
|
|
118
118
|
let userId = parameters.getString(ParameterCode.UserId);
|
|
119
119
|
GNNetwork.getAuthenticateStatus().setUserId(userId);
|
|
120
|
-
|
|
120
|
+
StorageService.setString(GNNetwork.USER_ID_KEY, userId);
|
|
121
121
|
}
|
|
122
122
|
if (parameters.containsKey(ParameterCode.Ts)) {
|
|
123
123
|
GNNetwork.peer.setServerTimeMilliseconds(parameters.getNumber(ParameterCode.Ts, new Date().getUTCMilliseconds()));
|
|
@@ -86,7 +86,7 @@ export class NetworkingPeerAxiosRequest extends NetworkingHttpPeerBase {
|
|
|
86
86
|
}
|
|
87
87
|
else if (postType == PostType.MsgPack) {
|
|
88
88
|
let content = param.toData();
|
|
89
|
-
body =
|
|
89
|
+
body = new Uint8Array(MessagePackConverterService.serialize(content));
|
|
90
90
|
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_MSGPACK;
|
|
91
91
|
headers[Commands.ACCEPT] = Commands.APPLICATION_MSGPACK;
|
|
92
92
|
if (!GNSupport.isBrowser())
|
|
@@ -2,7 +2,7 @@ import { Commands } from "./../../constant/Commands";
|
|
|
2
2
|
import { GNDebug } from "./../../logger/GNDebug";
|
|
3
3
|
import { NetworkingSocketPeerBase, SocketPacket } from "./NetworkingSocketPeerBase";
|
|
4
4
|
import { GNNetwork } from "./../../GNNetwork";
|
|
5
|
-
import { OperationHelper } from "./../../
|
|
5
|
+
import { OperationHelper } from "./../../helper/OperationHelper";
|
|
6
6
|
import { Manager } from "socket.io-client";
|
|
7
7
|
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
8
8
|
import { MessagePackConverterService } from "./../../helper/MessagePackConverterService";
|
|
@@ -1,10 +1,20 @@
|
|
|
1
1
|
export class ServiceUpdate {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.intervalId = null;
|
|
4
|
+
}
|
|
2
5
|
run() {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
+
if (this.intervalId)
|
|
7
|
+
return;
|
|
8
|
+
this.intervalId = setInterval(() => {
|
|
9
|
+
this.update();
|
|
6
10
|
}, 50);
|
|
7
11
|
}
|
|
12
|
+
stop() {
|
|
13
|
+
if (!this.intervalId)
|
|
14
|
+
return;
|
|
15
|
+
clearInterval(this.intervalId);
|
|
16
|
+
this.intervalId = null;
|
|
17
|
+
}
|
|
8
18
|
update() {
|
|
9
19
|
if (this.peer != null)
|
|
10
20
|
this.peer.service();
|
|
@@ -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
|