@xmobitea/gn-typescript-client 2.6.12 → 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/dist/index.d.ts +2 -2
- package/dist/index.js +339 -34236
- package/dist/runtime/GNNetwork.d.ts +1 -1
- package/dist/runtime/GNNetwork.js +273 -0
- package/dist/runtime/GNNetworkAuthenticateApi.js +122 -0
- package/dist/runtime/GNNetworkCharacterPlayerApi.js +968 -0
- package/dist/runtime/GNNetworkCloudScriptApi.js +104 -0
- package/dist/runtime/GNNetworkContentApi.js +140 -0
- package/dist/runtime/GNNetworkDashboardApi.js +170 -0
- package/dist/runtime/GNNetworkGamePlayerApi.js +950 -0
- package/dist/runtime/GNNetworkGroupApi.js +734 -0
- package/dist/runtime/GNNetworkInventoryApi.js +626 -0
- package/dist/runtime/GNNetworkMasterPlayerApi.js +1550 -0
- package/dist/runtime/GNNetworkMultiplayerApi.js +194 -0
- package/dist/runtime/GNNetworkStoreInventoryApi.js +266 -0
- package/dist/runtime/common/Action0.js +1 -0
- package/dist/runtime/common/Action1.js +1 -0
- package/dist/runtime/common/Action2.js +1 -0
- package/dist/runtime/common/Action3.js +1 -0
- package/dist/runtime/common/Action4.js +1 -0
- package/dist/runtime/common/GNData.js +209 -0
- package/dist/runtime/config/GNServerSettings.js +156 -0
- package/dist/runtime/constant/Commands.js +20 -0
- package/dist/runtime/constant/EventCode.js +8 -0
- package/dist/runtime/constant/OperationCode.js +221 -0
- package/dist/runtime/constant/ReturnCode.js +14 -0
- package/dist/runtime/constant/enumType/ExecuteResponseStatus.js +8 -0
- package/dist/runtime/constant/enumType/FriendStatus.js +7 -0
- package/dist/runtime/constant/enumType/GoogleLoginType.js +5 -0
- package/dist/runtime/constant/enumType/GroupStatus.js +7 -0
- package/dist/runtime/constant/enumType/InvalidMemberType.js +18 -0
- package/dist/runtime/constant/enumType/ItemType.js +5 -0
- package/dist/runtime/constant/enumType/MatchmakingMemberStatus.js +6 -0
- package/dist/runtime/constant/enumType/MatchmakingTicketStatus.js +8 -0
- package/dist/runtime/constant/enumType/OwnerType.js +9 -0
- package/dist/runtime/constant/enumType/PermissionDataItem.js +5 -0
- package/dist/runtime/constant/enumType/PushPlatformType.js +5 -0
- package/dist/runtime/constant/enumType/RequestRole.js +6 -0
- package/dist/runtime/constant/enumType/RequestType.js +15 -0
- package/dist/runtime/constant/enumType/StoreItemType.js +5 -0
- package/dist/runtime/constant/enumType/StoreReceiveType.js +8 -0
- package/dist/runtime/constant/errorCode/ErrorCode.js +52 -0
- package/dist/runtime/constant/parameterCode/ParameterCode.js +617 -0
- package/dist/runtime/entity/DataMember.js +208 -0
- package/dist/runtime/entity/GNMetadata.js +11 -0
- package/dist/runtime/entity/InvalidMember.js +1 -0
- package/dist/runtime/entity/OperationEvent.js +24 -0
- package/dist/runtime/entity/OperationRequest.js +42 -0
- package/dist/runtime/entity/OperationResponse.js +73 -0
- package/dist/runtime/entity/models/AuthenticateModels.js +426 -0
- package/dist/runtime/entity/models/AuthenticateRequestModels.js +188 -0
- package/dist/runtime/entity/models/AuthenticateResponseModels.js +131 -0
- package/dist/runtime/entity/models/CharacterPlayerModels.js +1433 -0
- package/dist/runtime/entity/models/CharacterPlayerRequestModels.js +1386 -0
- package/dist/runtime/entity/models/CharacterPlayerResponseModels.js +376 -0
- package/dist/runtime/entity/models/CloudScriptModels.js +197 -0
- package/dist/runtime/entity/models/CloudScriptRequestModels.js +138 -0
- package/dist/runtime/entity/models/CloudScriptResponseModels.js +40 -0
- package/dist/runtime/entity/models/ContentModels.js +203 -0
- package/dist/runtime/entity/models/ContentRequestModels.js +190 -0
- package/dist/runtime/entity/models/ContentResponseModels.js +54 -0
- package/dist/runtime/entity/models/DashboardModels.js +3002 -0
- package/dist/runtime/entity/models/DashboardRequestModels.js +268 -0
- package/dist/runtime/entity/models/DashboardResponseModels.js +187 -0
- package/dist/runtime/entity/models/GamePlayerModels.js +1591 -0
- package/dist/runtime/entity/models/GamePlayerRequestModels.js +1360 -0
- package/dist/runtime/entity/models/GamePlayerResponseModels.js +369 -0
- package/dist/runtime/entity/models/GenericModels.js +177 -0
- package/dist/runtime/entity/models/GroupModels.js +1135 -0
- package/dist/runtime/entity/models/GroupRequestModels.js +1048 -0
- package/dist/runtime/entity/models/GroupResponseModels.js +285 -0
- package/dist/runtime/entity/models/InventoryModels.js +915 -0
- package/dist/runtime/entity/models/InventoryRequestModels.js +892 -0
- package/dist/runtime/entity/models/InventoryResponseModels.js +243 -0
- package/dist/runtime/entity/models/MasterPlayerModels.js +2573 -0
- package/dist/runtime/entity/models/MasterPlayerRequestModels.js +2228 -0
- package/dist/runtime/entity/models/MasterPlayerResponseModels.js +607 -0
- package/dist/runtime/entity/models/MultiplayerModels.js +404 -0
- package/dist/runtime/entity/models/MultiplayerRequestModels.js +268 -0
- package/dist/runtime/entity/models/MultiplayerResponseModels.js +75 -0
- package/dist/runtime/entity/models/StoreInventoryModels.js +797 -0
- package/dist/runtime/entity/models/StoreInventoryRequestModels.js +372 -0
- package/dist/runtime/entity/models/StoreInventoryResponseModels.js +103 -0
- package/dist/runtime/entity/request/CustomOperationRequest.js +24 -0
- package/dist/runtime/entity/response/CustomOperationResponse.js +29 -0
- package/dist/runtime/entity/response/GetAuthInfoResponse.js +2 -0
- package/dist/runtime/entity/response/HealthCheckResponse.js +2 -0
- package/dist/runtime/entity/response/UploadFileResponse.js +2 -0
- package/dist/runtime/helper/CodeHelper.js +63 -0
- package/dist/runtime/helper/ConverterService.js +275 -0
- package/dist/runtime/helper/EnumUtility.js +33 -0
- package/dist/runtime/helper/GNSupport.d.ts +20 -0
- package/dist/runtime/helper/GNSupport.js +47 -0
- package/dist/runtime/helper/GNUtils.js +72 -0
- package/dist/runtime/helper/MessagePackConverterService.js +9 -0
- package/dist/runtime/{entity → helper}/OperationHelper.d.ts +1 -1
- package/dist/runtime/helper/OperationHelper.js +24 -0
- package/dist/runtime/helper/StorageService.d.ts +18 -0
- package/dist/runtime/helper/StorageService.js +62 -0
- package/dist/runtime/logger/GNDebug.js +29 -0
- package/dist/runtime/networking/AuthenticateStatus.js +14 -0
- package/dist/runtime/networking/IPeer.js +1 -0
- package/dist/runtime/networking/NetworkingPeer.d.ts +1 -1
- package/dist/runtime/networking/NetworkingPeer.js +210 -0
- package/dist/runtime/networking/OperationPending.js +53 -0
- package/dist/runtime/networking/PeerBase.js +161 -0
- package/dist/runtime/networking/handler/IServerEventHandler.js +13 -0
- package/dist/runtime/networking/handler/OnCharacterPlayerFriendUpdateEventHandler.js +39 -0
- package/dist/runtime/networking/handler/OnCharacterPlayerGroupUpdateEventHandler.js +39 -0
- package/dist/runtime/networking/handler/OnGamePlayerFriendUpdateEventHandler.js +39 -0
- package/dist/runtime/networking/handler/OnGamePlayerGroupUpdateEventHandler.js +39 -0
- package/dist/runtime/networking/handler/OnGroupMemberUpdateEventHandler.js +35 -0
- package/dist/runtime/networking/handler/OnGroupMessageUpdateEventHandler.js +43 -0
- package/dist/runtime/networking/http/HttpPeer.js +123 -0
- package/dist/runtime/networking/http/NetworkingHttpPeerBase.js +9 -0
- package/dist/runtime/networking/http/NetworkingPeerAxiosRequest.js +179 -0
- package/dist/runtime/networking/socket/NetworkingPeerSocketIOClient.js +130 -0
- package/dist/runtime/networking/socket/NetworkingSocketPeerBase.js +165 -0
- package/dist/runtime/networking/socket/SocketPeer.js +115 -0
- package/dist/runtime/typescript/ServiceUpdate.d.ts +2 -0
- package/dist/runtime/typescript/ServiceUpdate.js +22 -0
- package/docs/COCOS_CREATOR_INTEGRATION.md +116 -0
- package/examples/cocos-creator/GearNExample.ts.txt +176 -0
- package/package.json +4 -3
- 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/gearn.js.client.js +0 -47228
- package/dist/gearn.js.client.min.js +0 -2
- package/dist/gearn.js.client.min.js.LICENSE.txt +0 -14
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
var OnGroupMessageUpdateEventHandler_1;
|
|
11
|
+
import { EventCode } from "./../../constant/EventCode";
|
|
12
|
+
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
13
|
+
import { GNArrayDataMember, StringDataMember } from "./../../entity/DataMember";
|
|
14
|
+
import { GroupModels } from "./../../entity/models/GroupModels";
|
|
15
|
+
import { ConverterService } from "./../../helper/ConverterService";
|
|
16
|
+
import { IServerEventHandler } from "./IServerEventHandler";
|
|
17
|
+
export class GroupMessageUpdate {
|
|
18
|
+
}
|
|
19
|
+
__decorate([
|
|
20
|
+
GNArrayDataMember({ code: ParameterCode.GroupMessages, elementCls: GroupModels.GroupMessageResponseData }),
|
|
21
|
+
__metadata("design:type", Array)
|
|
22
|
+
], GroupMessageUpdate.prototype, "groupMessages", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
StringDataMember({ code: ParameterCode.GroupId }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], GroupMessageUpdate.prototype, "groupId", void 0);
|
|
27
|
+
__decorate([
|
|
28
|
+
StringDataMember({ code: ParameterCode.CharacterId, isOptional: true }),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], GroupMessageUpdate.prototype, "characterId", void 0);
|
|
31
|
+
let OnGroupMessageUpdateEventHandler = OnGroupMessageUpdateEventHandler_1 = class OnGroupMessageUpdateEventHandler {
|
|
32
|
+
getEventCode() {
|
|
33
|
+
return EventCode.OnGroupMessageUpdate;
|
|
34
|
+
}
|
|
35
|
+
handle(operationEvent) {
|
|
36
|
+
if (OnGroupMessageUpdateEventHandler_1.onUpdate != null)
|
|
37
|
+
OnGroupMessageUpdateEventHandler_1.onUpdate(ConverterService.deserializeObject(operationEvent.getParameters(), GroupMessageUpdate));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
OnGroupMessageUpdateEventHandler = OnGroupMessageUpdateEventHandler_1 = __decorate([
|
|
41
|
+
IServerEventHandler.registerEvent
|
|
42
|
+
], OnGroupMessageUpdateEventHandler);
|
|
43
|
+
export { OnGroupMessageUpdateEventHandler };
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { GNArray, GNHashtable } from "./../../common/GNData";
|
|
2
|
+
import { ReturnCode } from "./../../constant/ReturnCode";
|
|
3
|
+
import { GNNetwork } from "./../../GNNetwork";
|
|
4
|
+
import { GNDebug } from "./../../logger/GNDebug";
|
|
5
|
+
import { NetworkingPeer } from "./../NetworkingPeer";
|
|
6
|
+
import { PeerBase } from "./../PeerBase";
|
|
7
|
+
import { GNSupport } from "./../../helper/GNSupport";
|
|
8
|
+
import { NetworkingPeerAxiosRequest } from "./NetworkingPeerAxiosRequest";
|
|
9
|
+
import { MessagePackConverterService } from "./../../helper/MessagePackConverterService";
|
|
10
|
+
import { MessageType } from "./../../config/GNServerSettings";
|
|
11
|
+
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
12
|
+
import { OperationRequest } from "./../../entity/OperationRequest";
|
|
13
|
+
import { CodeHelper } from "./../../helper/CodeHelper";
|
|
14
|
+
export class HttpAppResponse {
|
|
15
|
+
hasError() {
|
|
16
|
+
return this.error != null;
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
let answer = " StatusCode: " + this.statusCode;
|
|
20
|
+
if (this.error)
|
|
21
|
+
answer += ", <color=red>Error: " + this.error + "</color>";
|
|
22
|
+
answer += ", Text: " + this.text;
|
|
23
|
+
return answer;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export var PostType;
|
|
27
|
+
(function (PostType) {
|
|
28
|
+
PostType[PostType["Json"] = 0] = "Json";
|
|
29
|
+
PostType[PostType["MsgPack"] = 1] = "MsgPack";
|
|
30
|
+
})(PostType || (PostType = {}));
|
|
31
|
+
export class HttpPeer extends PeerBase {
|
|
32
|
+
initGNSocketObject() {
|
|
33
|
+
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
34
|
+
if (gnServerSettings == null)
|
|
35
|
+
throw new Error("Where is GN Server Settings");
|
|
36
|
+
this.isUse = gnServerSettings.isUseHttp();
|
|
37
|
+
this.networkingHttpPeerBase = new NetworkingPeerAxiosRequest();
|
|
38
|
+
let httpUrl = gnServerSettings.getHttpUrl();
|
|
39
|
+
let userAgent = "GN-ts-" + GNNetwork.getPlatform() + "@" + GNNetwork.getClientSdkVersion();
|
|
40
|
+
this.networkingHttpPeerBase.init(httpUrl, userAgent);
|
|
41
|
+
this.networkingHttpPeerBase.setUseReverseProxy(gnServerSettings.getUseReverseProxy());
|
|
42
|
+
}
|
|
43
|
+
send(operationPending) {
|
|
44
|
+
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
45
|
+
let operationRequest = operationPending.getOperationRequest();
|
|
46
|
+
if (operationRequest.getTimeout() == OperationRequest.defaultTimeOut)
|
|
47
|
+
operationRequest.setTimeout(gnServerSettings.getDefaultTimeoutInSeconds());
|
|
48
|
+
super.send(operationPending);
|
|
49
|
+
GNDebug.log("[GN Http SEND] " + operationRequest.toString());
|
|
50
|
+
let authToken = operationPending.getAuthToken();
|
|
51
|
+
let secretKey = operationPending.getSecretKey();
|
|
52
|
+
let gameId = operationPending.getGameId();
|
|
53
|
+
let customTags = operationPending.getCustomTags();
|
|
54
|
+
let postType = gnServerSettings.getMessageType() == MessageType.Json ? PostType.Json : PostType.MsgPack;
|
|
55
|
+
if (GNSupport.isBrowser() && postType == PostType.MsgPack) {
|
|
56
|
+
GNDebug.logWarning("GN JS client sdk does not support send msgpack request via HTTP, so we will send this request via HTTP json");
|
|
57
|
+
postType = PostType.Json;
|
|
58
|
+
}
|
|
59
|
+
let subUri = (postType == PostType.Json ? NetworkingPeer.API_JSON : NetworkingPeer.API_MSG_PACK) + "/" + CodeHelper.getRequestTypeName(operationPending.getRequestType()) + "/" + CodeHelper.getRequestRoleName(operationPending.getRole()) + "/" + operationRequest.getOperationCode();
|
|
60
|
+
let thiz = this;
|
|
61
|
+
this.networkingHttpPeerBase.postRequest(subUri, operationRequest.getParameters(), postType, (httpAppResponse) => {
|
|
62
|
+
thiz.onSendOperationRequestResponse(operationPending, httpAppResponse);
|
|
63
|
+
}, operationRequest.getTimeout(), authToken, secretKey, customTags, gameId);
|
|
64
|
+
}
|
|
65
|
+
onEnqueue(operationPending) {
|
|
66
|
+
GNDebug.log("[GN Http ENQUEUE] " + operationPending.getOperationRequest().toString());
|
|
67
|
+
}
|
|
68
|
+
onSendOperationRequestResponse(operationPending, httpAppResponse) {
|
|
69
|
+
let operationRequest = operationPending.getOperationRequest();
|
|
70
|
+
let obj = new GNHashtable();
|
|
71
|
+
if (!httpAppResponse.hasError()) {
|
|
72
|
+
if (httpAppResponse.statusCode == 200) {
|
|
73
|
+
let gnHashtable = null;
|
|
74
|
+
if (httpAppResponse.text) {
|
|
75
|
+
if (httpAppResponse.text[0] === HttpPeer.JSON_CHAR_KNOWN) {
|
|
76
|
+
let returnDatas = JSON.parse(httpAppResponse.text);
|
|
77
|
+
gnHashtable = GNHashtable.builder()
|
|
78
|
+
.addAll(returnDatas)
|
|
79
|
+
.build();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (gnHashtable == null) {
|
|
83
|
+
if (httpAppResponse.data != null) {
|
|
84
|
+
let iDict = MessagePackConverterService.deserialize(httpAppResponse.data);
|
|
85
|
+
gnHashtable = GNHashtable.builder()
|
|
86
|
+
.addAll(iDict)
|
|
87
|
+
.build();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (gnHashtable != null) {
|
|
91
|
+
obj.add(ParameterCode.ReturnCode, gnHashtable.getNumber(ParameterCode.ReturnCode));
|
|
92
|
+
obj.add(ParameterCode.Parameters, gnHashtable.getGNHashtable(ParameterCode.Parameters, new GNHashtable()));
|
|
93
|
+
obj.add(ParameterCode.InvalidRequestParameters, gnHashtable.getGNArray(ParameterCode.InvalidRequestParameters, new GNArray()));
|
|
94
|
+
obj.add(ParameterCode.DebugMessage, gnHashtable.getString(ParameterCode.DebugMessage));
|
|
95
|
+
obj.add(ParameterCode.ResponseId, operationRequest.getRequestId());
|
|
96
|
+
this.onResponseHandler(obj);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
obj.add(ParameterCode.ReturnCode, ReturnCode.UnknownError);
|
|
102
|
+
obj.add(ParameterCode.DebugMessage, httpAppResponse.error);
|
|
103
|
+
obj.add(ParameterCode.ResponseId, operationRequest.getRequestId());
|
|
104
|
+
this.onResponseHandler(obj);
|
|
105
|
+
}
|
|
106
|
+
getRequest(subUri, onHttpAppResponse, timeout = OperationRequest.defaultTimeOut, authToken = null, secretKey = null, gameId = null) {
|
|
107
|
+
this.networkingHttpPeerBase.getRequest(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId);
|
|
108
|
+
}
|
|
109
|
+
uploadFile(fileId, content, filename, mimetype, onHttpAppResponse, timeout = 6000) {
|
|
110
|
+
let authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
111
|
+
if (!authToken) {
|
|
112
|
+
let httpAppResponse = new HttpAppResponse();
|
|
113
|
+
httpAppResponse.statusCode = 401;
|
|
114
|
+
httpAppResponse.error = "Auth token null";
|
|
115
|
+
if (onHttpAppResponse != null)
|
|
116
|
+
onHttpAppResponse(httpAppResponse);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
let subUri = NetworkingPeer.UPLOAD_FILE + "/" + fileId;
|
|
120
|
+
this.networkingHttpPeerBase.postRequestUpload(subUri, content, filename, mimetype, onHttpAppResponse, timeout);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
HttpPeer.JSON_CHAR_KNOWN = "{";
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
import { GNHashtable } from "./../../common/GNData";
|
|
3
|
+
import { Commands } from "./../../constant/Commands";
|
|
4
|
+
import { GNSupport } from "./../../helper/GNSupport";
|
|
5
|
+
import { GNDebug } from "./../../logger/GNDebug";
|
|
6
|
+
import { HttpAppResponse, PostType } from "./HttpPeer";
|
|
7
|
+
import { NetworkingHttpPeerBase } from "./NetworkingHttpPeerBase";
|
|
8
|
+
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
9
|
+
import { GNNetwork } from "./../../GNNetwork";
|
|
10
|
+
import { MessagePackConverterService } from "./../../helper/MessagePackConverterService";
|
|
11
|
+
export class NetworkingPeerAxiosRequest extends NetworkingHttpPeerBase {
|
|
12
|
+
getRequest(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId) {
|
|
13
|
+
this.getRequestAxios(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId);
|
|
14
|
+
}
|
|
15
|
+
postRequest(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags, gameId) {
|
|
16
|
+
this.postRequestAxios(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags, gameId);
|
|
17
|
+
}
|
|
18
|
+
postRequestUpload(subUri, content, filename, mimetype, onHttpAppResponse, timeout) {
|
|
19
|
+
//GNDebug.logWarning("GN JS client sdk does not support upload file yet.");
|
|
20
|
+
// let httpAppResponse = new HttpAppResponse();
|
|
21
|
+
// httpAppResponse.error = "Upload file does not support in GN JS client sdk.";
|
|
22
|
+
// httpAppResponse.statusCode = -1;
|
|
23
|
+
// httpAppResponse.text = "[-3]";
|
|
24
|
+
// if (onHttpAppResponse != null) onHttpAppResponse(httpAppResponse);
|
|
25
|
+
this.postRequestUploadAxios(subUri, content, filename, mimetype, onHttpAppResponse, timeout);
|
|
26
|
+
}
|
|
27
|
+
async getRequestAxios(subUri, onHttpAppResponse, timeout, authToken, secretKey, gameId) {
|
|
28
|
+
let headers = {};
|
|
29
|
+
if (authToken)
|
|
30
|
+
headers[Commands.RequestAuthTokenCmd] = authToken;
|
|
31
|
+
if (secretKey)
|
|
32
|
+
headers[Commands.RequestSecretCmd] = secretKey;
|
|
33
|
+
if (gameId)
|
|
34
|
+
headers[Commands.RequestGameIdCmd] = gameId;
|
|
35
|
+
if (!GNSupport.isBrowser())
|
|
36
|
+
headers[Commands.USER_AGENT] = this.userAgent;
|
|
37
|
+
let httpAppResponse = new HttpAppResponse();
|
|
38
|
+
let targetUrl = this.httpUrl + "/" + subUri;
|
|
39
|
+
if (this.useReverseProxy) {
|
|
40
|
+
targetUrl = "/" + subUri;
|
|
41
|
+
headers[Commands.BaseUrl] = this.httpUrl;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
let result = await axios.get(targetUrl, {
|
|
45
|
+
headers: headers,
|
|
46
|
+
timeout: timeout * 1000,
|
|
47
|
+
responseType: "arraybuffer",
|
|
48
|
+
});
|
|
49
|
+
httpAppResponse.statusCode = result.status;
|
|
50
|
+
let buffers = this.toBuffers(result.data);
|
|
51
|
+
httpAppResponse.data = buffers[0];
|
|
52
|
+
httpAppResponse.text = buffers[1];
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
httpAppResponse.error = error.toString();
|
|
56
|
+
httpAppResponse.statusCode = -1;
|
|
57
|
+
httpAppResponse.text = "[-2]";
|
|
58
|
+
GNDebug.logError(error);
|
|
59
|
+
}
|
|
60
|
+
if (onHttpAppResponse != null)
|
|
61
|
+
onHttpAppResponse(httpAppResponse);
|
|
62
|
+
}
|
|
63
|
+
async postRequestAxios(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags, gameId) {
|
|
64
|
+
let headers = {};
|
|
65
|
+
if (authToken)
|
|
66
|
+
headers[Commands.RequestAuthTokenCmd] = authToken;
|
|
67
|
+
if (secretKey)
|
|
68
|
+
headers[Commands.RequestSecretCmd] = secretKey;
|
|
69
|
+
if (gameId)
|
|
70
|
+
headers[Commands.RequestGameIdCmd] = gameId;
|
|
71
|
+
if (!GNSupport.isBrowser())
|
|
72
|
+
headers[Commands.USER_AGENT] = this.userAgent;
|
|
73
|
+
if (param == null)
|
|
74
|
+
param = new GNHashtable();
|
|
75
|
+
if (customTags != null)
|
|
76
|
+
param.add(ParameterCode.CustomTags, customTags);
|
|
77
|
+
let body = null;
|
|
78
|
+
if (postType == PostType.Json) {
|
|
79
|
+
let content = param.toData();
|
|
80
|
+
body = content;
|
|
81
|
+
if (!GNSupport.isBrowser()) {
|
|
82
|
+
headers[Commands.CONTENT_LENGTH] = JSON.stringify(body).length;
|
|
83
|
+
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_JSON;
|
|
84
|
+
}
|
|
85
|
+
headers[Commands.ACCEPT] = Commands.APPLICATION_JSON;
|
|
86
|
+
}
|
|
87
|
+
else if (postType == PostType.MsgPack) {
|
|
88
|
+
let content = param.toData();
|
|
89
|
+
body = new Uint8Array(MessagePackConverterService.serialize(content));
|
|
90
|
+
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_MSGPACK;
|
|
91
|
+
headers[Commands.ACCEPT] = Commands.APPLICATION_MSGPACK;
|
|
92
|
+
if (!GNSupport.isBrowser())
|
|
93
|
+
headers[Commands.CONTENT_LENGTH] = body.length;
|
|
94
|
+
}
|
|
95
|
+
let httpAppResponse = new HttpAppResponse();
|
|
96
|
+
let targetUrl = this.httpUrl + "/" + subUri;
|
|
97
|
+
if (this.useReverseProxy) {
|
|
98
|
+
targetUrl = "/" + subUri;
|
|
99
|
+
headers[Commands.BaseUrl] = this.httpUrl;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
if (postType == PostType.Json) {
|
|
103
|
+
let result = await axios.post(targetUrl, body, {
|
|
104
|
+
headers: headers,
|
|
105
|
+
timeout: timeout * 1000,
|
|
106
|
+
responseType: "text",
|
|
107
|
+
});
|
|
108
|
+
httpAppResponse.statusCode = result.status;
|
|
109
|
+
// let buffers = this.toBuffers(result.data);
|
|
110
|
+
// httpAppResponse.data = buffers[0];
|
|
111
|
+
httpAppResponse.text = result.data;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
let result = await axios.post(targetUrl, body, {
|
|
115
|
+
headers: headers,
|
|
116
|
+
timeout: timeout * 1000,
|
|
117
|
+
responseType: "arraybuffer",
|
|
118
|
+
});
|
|
119
|
+
httpAppResponse.statusCode = result.status;
|
|
120
|
+
let buffers = this.toBuffers(result.data);
|
|
121
|
+
httpAppResponse.data = buffers[0];
|
|
122
|
+
httpAppResponse.text = buffers[1];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
httpAppResponse.error = error.toString();
|
|
127
|
+
httpAppResponse.statusCode = -1;
|
|
128
|
+
httpAppResponse.text = "[-2]";
|
|
129
|
+
GNDebug.logError(error);
|
|
130
|
+
}
|
|
131
|
+
if (onHttpAppResponse != null)
|
|
132
|
+
onHttpAppResponse(httpAppResponse);
|
|
133
|
+
}
|
|
134
|
+
async postRequestUploadAxios(subUri, content, filename, mimetype, onHttpAppResponse, timeout) {
|
|
135
|
+
let formData = new FormData();
|
|
136
|
+
formData.append(Commands.File, new Blob([content.buffer.slice(0)], { type: mimetype }), filename);
|
|
137
|
+
let headers = {};
|
|
138
|
+
headers[Commands.RequestAuthTokenCmd] = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
139
|
+
;
|
|
140
|
+
// if (!GNSupport.isBrowser()) {
|
|
141
|
+
// headers[Commands.CONTENT_TYPE] = "multipart/form-data";
|
|
142
|
+
// }
|
|
143
|
+
let httpAppResponse = new HttpAppResponse();
|
|
144
|
+
let targetUrl = this.httpUrl + "/" + subUri;
|
|
145
|
+
if (this.useReverseProxy) {
|
|
146
|
+
targetUrl = "/" + subUri;
|
|
147
|
+
headers[Commands.BaseUrl] = this.httpUrl;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
let result = await axios.post(targetUrl, formData, {
|
|
151
|
+
headers: headers,
|
|
152
|
+
timeout: timeout * 1000,
|
|
153
|
+
responseType: "arraybuffer",
|
|
154
|
+
});
|
|
155
|
+
httpAppResponse.statusCode = result.status;
|
|
156
|
+
let buffers = this.toBuffers(result.data);
|
|
157
|
+
httpAppResponse.data = buffers[0];
|
|
158
|
+
httpAppResponse.text = buffers[1];
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
httpAppResponse.error = error.toString();
|
|
162
|
+
httpAppResponse.statusCode = -1;
|
|
163
|
+
httpAppResponse.text = "[-2]";
|
|
164
|
+
GNDebug.logError(error);
|
|
165
|
+
}
|
|
166
|
+
if (onHttpAppResponse != null)
|
|
167
|
+
onHttpAppResponse(httpAppResponse);
|
|
168
|
+
}
|
|
169
|
+
uint8ArrayToString(uint8Array) {
|
|
170
|
+
return decodeURIComponent(escape(String.fromCharCode(...uint8Array)));
|
|
171
|
+
}
|
|
172
|
+
toBuffers(data) {
|
|
173
|
+
if (GNSupport.isBrowser()) {
|
|
174
|
+
data = new Uint8Array(data);
|
|
175
|
+
return [data, this.uint8ArrayToString(data)];
|
|
176
|
+
}
|
|
177
|
+
return [data, data.toString()];
|
|
178
|
+
}
|
|
179
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Commands } from "./../../constant/Commands";
|
|
2
|
+
import { GNDebug } from "./../../logger/GNDebug";
|
|
3
|
+
import { NetworkingSocketPeerBase, SocketPacket } from "./NetworkingSocketPeerBase";
|
|
4
|
+
import { GNNetwork } from "./../../GNNetwork";
|
|
5
|
+
import { OperationHelper } from "./../../helper/OperationHelper";
|
|
6
|
+
import { Manager } from "socket.io-client";
|
|
7
|
+
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
8
|
+
import { MessagePackConverterService } from "./../../helper/MessagePackConverterService";
|
|
9
|
+
import { MessageType } from "./../../config/GNServerSettings";
|
|
10
|
+
export class NetworkingPeerSocketIOClient extends NetworkingSocketPeerBase {
|
|
11
|
+
sendRequestAuthSocket() {
|
|
12
|
+
super.sendRequestAuthSocket();
|
|
13
|
+
if (this.clientId) {
|
|
14
|
+
this.socketManager.socket("/").emit(Commands.RequestAuthTokenCmd, GNNetwork.getAuthenticateStatus().getAuthToken());
|
|
15
|
+
}
|
|
16
|
+
;
|
|
17
|
+
}
|
|
18
|
+
reInitNewSocket() {
|
|
19
|
+
super.reInitNewSocket();
|
|
20
|
+
if (this.socketManager == null) {
|
|
21
|
+
const url = new URL(this.url);
|
|
22
|
+
this.socketManager = new Manager(url.origin, {
|
|
23
|
+
path: url.pathname + "socket.io",
|
|
24
|
+
reconnection: true,
|
|
25
|
+
reconnectionDelay: this.reconnectDelay,
|
|
26
|
+
timeout: this.pingTimeout,
|
|
27
|
+
autoConnect: false,
|
|
28
|
+
transports: ["websocket"]
|
|
29
|
+
});
|
|
30
|
+
let socket = this.socketManager.socket("/");
|
|
31
|
+
socket.on("connect", () => {
|
|
32
|
+
this.onConnect();
|
|
33
|
+
});
|
|
34
|
+
socket.on("disconnect", () => {
|
|
35
|
+
this.onDisconnect();
|
|
36
|
+
});
|
|
37
|
+
socket.on("error", (error) => {
|
|
38
|
+
this.onError(error);
|
|
39
|
+
});
|
|
40
|
+
socket.on(Commands.ResponseCmd_MsgPack, (args) => {
|
|
41
|
+
this.onResponseMsgPack(args);
|
|
42
|
+
});
|
|
43
|
+
socket.on(Commands.EventCmd_MsgPack, (args) => {
|
|
44
|
+
this.onEventMsgPack(args);
|
|
45
|
+
});
|
|
46
|
+
socket.on(Commands.ResponseCmd_Json, (args) => {
|
|
47
|
+
this.onResponseJson(args);
|
|
48
|
+
});
|
|
49
|
+
socket.on(Commands.EventCmd_Json, (args) => {
|
|
50
|
+
this.onEventJson(args);
|
|
51
|
+
});
|
|
52
|
+
this.socket = socket;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
onResponseMsgPack(...args) {
|
|
56
|
+
this.responsePacketLst.push(new SocketPacket(args[0], true));
|
|
57
|
+
}
|
|
58
|
+
onEventMsgPack(...args) {
|
|
59
|
+
this.eventPacketLst.push(new SocketPacket(args[0], true));
|
|
60
|
+
}
|
|
61
|
+
onResponseJson(...args) {
|
|
62
|
+
this.responsePacketLst.push(new SocketPacket(args[0], false));
|
|
63
|
+
}
|
|
64
|
+
onEventJson(...args) {
|
|
65
|
+
this.eventPacketLst.push(new SocketPacket(args[0], false));
|
|
66
|
+
}
|
|
67
|
+
onConnect() {
|
|
68
|
+
GNDebug.log("[GN Socket RECV] HandleOpen " + this.socket.id);
|
|
69
|
+
this.clientId = this.socket.id;
|
|
70
|
+
this.onConnectHandler();
|
|
71
|
+
}
|
|
72
|
+
onDisconnect() {
|
|
73
|
+
GNDebug.log("[GN Socket RECV] HandleClose ");
|
|
74
|
+
this.clientId = "";
|
|
75
|
+
this.onDisconnectHandler();
|
|
76
|
+
}
|
|
77
|
+
onError(error) {
|
|
78
|
+
GNDebug.logError(error);
|
|
79
|
+
}
|
|
80
|
+
init(url, reconnectDelay, pingInterval, pingTimeout) {
|
|
81
|
+
super.init(url, reconnectDelay, pingInterval, pingTimeout);
|
|
82
|
+
}
|
|
83
|
+
emit(requestType, role, operationRequest, authToken, secretKey, customTags, gameId) {
|
|
84
|
+
super.emit(requestType, role, operationRequest, authToken, secretKey, customTags, gameId);
|
|
85
|
+
if (this.socketManager == null) {
|
|
86
|
+
// callback here
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let socket = this.socketManager.socket("/");
|
|
90
|
+
if (socket == null) {
|
|
91
|
+
// callback here
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (customTags != null)
|
|
95
|
+
operationRequest.setParameter(ParameterCode.CustomTags, customTags);
|
|
96
|
+
let dataSend = OperationHelper.toSocketData(requestType, role, operationRequest);
|
|
97
|
+
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
98
|
+
if (gnServerSettings.getMessageType() == MessageType.Json)
|
|
99
|
+
socket.emit(Commands.RequestCmd_Json, dataSend);
|
|
100
|
+
else
|
|
101
|
+
socket.emit(Commands.RequestCmd_MsgPack, MessagePackConverterService.serialize(dataSend));
|
|
102
|
+
}
|
|
103
|
+
close(_onSocketDisconnect) {
|
|
104
|
+
super.close(_onSocketDisconnect);
|
|
105
|
+
this.isConnected = false;
|
|
106
|
+
if (this.socketManager != null) {
|
|
107
|
+
if (this.socketManager._readyState != "closed") {
|
|
108
|
+
this.socketManager._close();
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (this.socket != null)
|
|
113
|
+
this.socket.disconnect();
|
|
114
|
+
GNDebug.log("[GN Socket] Disconnecting via SocketIO client");
|
|
115
|
+
this.onDisconnectHandler();
|
|
116
|
+
}
|
|
117
|
+
connect(_onSocketConnect) {
|
|
118
|
+
super.connect(_onSocketConnect);
|
|
119
|
+
if (this.isConnected) {
|
|
120
|
+
GNDebug.log("[GN Socket] Reconnecting");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.isConnected = true;
|
|
124
|
+
GNDebug.log("[GN Socket] Connecting via SocketIO client");
|
|
125
|
+
if (this.socketManager != null)
|
|
126
|
+
this.socketManager.open();
|
|
127
|
+
if (this.socket != null)
|
|
128
|
+
this.socket.connect();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { MessagePackConverterService } from "./../../helper/MessagePackConverterService";
|
|
2
|
+
import { GNHashtable } from "./../../common/GNData";
|
|
3
|
+
import { GNNetwork } from "./../../GNNetwork";
|
|
4
|
+
import { GNDebug } from "./../../logger/GNDebug";
|
|
5
|
+
export class SocketPacket {
|
|
6
|
+
constructor(obj, isMsgPack) {
|
|
7
|
+
this.obj = obj;
|
|
8
|
+
this.isMsgPack = isMsgPack;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
class Action0List {
|
|
12
|
+
subscriber(action) {
|
|
13
|
+
this.handlers.push(action);
|
|
14
|
+
}
|
|
15
|
+
unsubscriber(action) {
|
|
16
|
+
let indexOf = this.handlers.indexOf(action);
|
|
17
|
+
if (indexOf != -1)
|
|
18
|
+
this.handlers.splice(indexOf, 1);
|
|
19
|
+
}
|
|
20
|
+
invoke() {
|
|
21
|
+
this.handlers.forEach((a) => {
|
|
22
|
+
if (a != null)
|
|
23
|
+
a();
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
constructor() {
|
|
27
|
+
this.handlers = [];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class NetworkingSocketPeerBase {
|
|
31
|
+
constructor() {
|
|
32
|
+
this.clientId = "";
|
|
33
|
+
this._onConnectHandler = new Action0List();
|
|
34
|
+
this._onDisconnectHandler = new Action0List();
|
|
35
|
+
}
|
|
36
|
+
init(url, reconnectDelay, pingInterval, pingTimeout) {
|
|
37
|
+
this.responsePacketLst = [];
|
|
38
|
+
this.eventPacketLst = [];
|
|
39
|
+
this.url = url;
|
|
40
|
+
this.reconnectDelay = reconnectDelay;
|
|
41
|
+
this.pingInterval = pingInterval;
|
|
42
|
+
this.pingTimeout = pingTimeout;
|
|
43
|
+
}
|
|
44
|
+
connect(_onSocketConnect) {
|
|
45
|
+
this._onSocketConnect = _onSocketConnect;
|
|
46
|
+
}
|
|
47
|
+
close(_onSocketDisconnect) {
|
|
48
|
+
this._onSocketDisconnect = _onSocketDisconnect;
|
|
49
|
+
}
|
|
50
|
+
sendRequestAuthSocket() {
|
|
51
|
+
}
|
|
52
|
+
send(requestType, role, operationRequest, authToken, secretKey, customTags, gameId) {
|
|
53
|
+
this.emit(requestType, role, operationRequest, authToken, secretKey, customTags, gameId);
|
|
54
|
+
}
|
|
55
|
+
emit(requestType, role, operationRequest, authToken, secretKey, customTags, gameId) {
|
|
56
|
+
}
|
|
57
|
+
reInitNewSocket() {
|
|
58
|
+
}
|
|
59
|
+
setOnConnectHandler(_onConnectHandler) {
|
|
60
|
+
this._onConnectHandler.subscriber(_onConnectHandler);
|
|
61
|
+
}
|
|
62
|
+
setOnDisconnectHandler(_onDisconnectHandler) {
|
|
63
|
+
this._onDisconnectHandler.subscriber(_onDisconnectHandler);
|
|
64
|
+
}
|
|
65
|
+
removeOnConnectHandler(_onConnectHandler) {
|
|
66
|
+
this._onConnectHandler.unsubscriber(_onConnectHandler);
|
|
67
|
+
}
|
|
68
|
+
removeOnDisconnectHandler(_onDisconnectHandler) {
|
|
69
|
+
this._onDisconnectHandler.unsubscriber(_onDisconnectHandler);
|
|
70
|
+
}
|
|
71
|
+
onConnectHandler() {
|
|
72
|
+
this._onConnectHandler.invoke();
|
|
73
|
+
let authToken = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
74
|
+
if (authToken != null) {
|
|
75
|
+
this.sendRequestAuthSocket();
|
|
76
|
+
}
|
|
77
|
+
if (this._onSocketConnect != null) {
|
|
78
|
+
this._onSocketConnect();
|
|
79
|
+
this._onSocketConnect = null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
onDisconnectHandler() {
|
|
83
|
+
this._onDisconnectHandler.invoke();
|
|
84
|
+
if (this._onSocketDisconnect != null) {
|
|
85
|
+
this._onSocketDisconnect();
|
|
86
|
+
this._onSocketDisconnect = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
setOnEventHandler(_onEventHandler) {
|
|
90
|
+
this._onEventHandler = _onEventHandler;
|
|
91
|
+
}
|
|
92
|
+
onEventHandler(obj) {
|
|
93
|
+
if (this._onEventHandler != null)
|
|
94
|
+
this._onEventHandler(obj);
|
|
95
|
+
}
|
|
96
|
+
setOnResponseHandler(_onResponseHandler) {
|
|
97
|
+
this._onResponseHandler = _onResponseHandler;
|
|
98
|
+
}
|
|
99
|
+
onResponseHandler(obj) {
|
|
100
|
+
if (this._onResponseHandler != null)
|
|
101
|
+
this._onResponseHandler(obj);
|
|
102
|
+
}
|
|
103
|
+
service() {
|
|
104
|
+
if (this.responsePacketLst.length > 0) {
|
|
105
|
+
for (let i = 0; i < this.responsePacketLst.length; i++) {
|
|
106
|
+
let responsePacket = this.responsePacketLst[i];
|
|
107
|
+
if (responsePacket.isMsgPack) {
|
|
108
|
+
try {
|
|
109
|
+
let iDict = MessagePackConverterService.deserialize(responsePacket.obj);
|
|
110
|
+
let gnHashtable = GNHashtable.builder()
|
|
111
|
+
.addAll(iDict)
|
|
112
|
+
.build();
|
|
113
|
+
this.onResponseHandler(gnHashtable);
|
|
114
|
+
}
|
|
115
|
+
catch (ex) {
|
|
116
|
+
GNDebug.logException(ex);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
try {
|
|
121
|
+
let iDict = responsePacket.obj;
|
|
122
|
+
let gnHashtable = GNHashtable.builder()
|
|
123
|
+
.addAll(iDict)
|
|
124
|
+
.build();
|
|
125
|
+
this.onResponseHandler(gnHashtable);
|
|
126
|
+
}
|
|
127
|
+
catch (ex) {
|
|
128
|
+
GNDebug.logException(ex);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.responsePacketLst.length = 0;
|
|
133
|
+
}
|
|
134
|
+
if (this.eventPacketLst.length > 0) {
|
|
135
|
+
for (let i = 0; i < this.eventPacketLst.length; i++) {
|
|
136
|
+
let eventPacket = this.eventPacketLst[i];
|
|
137
|
+
if (eventPacket.isMsgPack) {
|
|
138
|
+
try {
|
|
139
|
+
let iDict = MessagePackConverterService.deserialize(eventPacket.obj);
|
|
140
|
+
let gnHashtable = GNHashtable.builder()
|
|
141
|
+
.addAll(iDict)
|
|
142
|
+
.build();
|
|
143
|
+
this.onEventHandler(gnHashtable);
|
|
144
|
+
}
|
|
145
|
+
catch (ex) {
|
|
146
|
+
GNDebug.logException(ex);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
try {
|
|
151
|
+
let iDict = eventPacket.obj;
|
|
152
|
+
let gnHashtable = GNHashtable.builder()
|
|
153
|
+
.addAll(iDict)
|
|
154
|
+
.build();
|
|
155
|
+
this.onEventHandler(gnHashtable);
|
|
156
|
+
}
|
|
157
|
+
catch (ex) {
|
|
158
|
+
GNDebug.logException(ex);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
this.eventPacketLst.length = 0;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|