@xmobitea/gn-typescript-client 2.6.8-tsc → 2.6.8
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 +46892 -0
- package/dist/gearn.js.client.min.js +2 -0
- package/dist/gearn.js.client.min.js.LICENSE.txt +14 -0
- package/dist/index.js +34170 -337
- package/package.json +1 -1
- package/dist/runtime/GNNetwork.js +0 -250
- package/dist/runtime/GNNetworkAuthenticateApi.js +0 -122
- package/dist/runtime/GNNetworkCharacterPlayerApi.js +0 -968
- package/dist/runtime/GNNetworkCloudScriptApi.js +0 -104
- package/dist/runtime/GNNetworkContentApi.js +0 -140
- package/dist/runtime/GNNetworkDashboardApi.js +0 -170
- package/dist/runtime/GNNetworkGamePlayerApi.js +0 -950
- package/dist/runtime/GNNetworkGroupApi.js +0 -734
- package/dist/runtime/GNNetworkInventoryApi.js +0 -626
- package/dist/runtime/GNNetworkMasterPlayerApi.js +0 -1550
- package/dist/runtime/GNNetworkMultiplayerApi.js +0 -194
- package/dist/runtime/GNNetworkStoreInventoryApi.js +0 -266
- package/dist/runtime/common/Action0.js +0 -1
- package/dist/runtime/common/Action1.js +0 -1
- package/dist/runtime/common/Action2.js +0 -1
- package/dist/runtime/common/Action3.js +0 -1
- package/dist/runtime/common/Action4.js +0 -1
- package/dist/runtime/common/GNData.js +0 -211
- package/dist/runtime/config/GNServerSettings.js +0 -149
- package/dist/runtime/constant/Commands.js +0 -19
- package/dist/runtime/constant/EventCode.js +0 -8
- package/dist/runtime/constant/OperationCode.js +0 -221
- package/dist/runtime/constant/ReturnCode.js +0 -14
- package/dist/runtime/constant/enumType/ExecuteResponseStatus.js +0 -8
- package/dist/runtime/constant/enumType/FriendStatus.js +0 -7
- package/dist/runtime/constant/enumType/GoogleLoginType.js +0 -5
- package/dist/runtime/constant/enumType/GroupStatus.js +0 -7
- package/dist/runtime/constant/enumType/InvalidMemberType.js +0 -18
- package/dist/runtime/constant/enumType/ItemType.js +0 -5
- package/dist/runtime/constant/enumType/MatchmakingMemberStatus.js +0 -6
- package/dist/runtime/constant/enumType/MatchmakingTicketStatus.js +0 -8
- package/dist/runtime/constant/enumType/OwnerType.js +0 -9
- package/dist/runtime/constant/enumType/PermissionDataItem.js +0 -5
- package/dist/runtime/constant/enumType/PushPlatformType.js +0 -5
- package/dist/runtime/constant/enumType/RequestRole.js +0 -6
- package/dist/runtime/constant/enumType/RequestType.js +0 -15
- package/dist/runtime/constant/enumType/StoreItemType.js +0 -5
- package/dist/runtime/constant/enumType/StoreReceiveType.js +0 -8
- package/dist/runtime/constant/errorCode/ErrorCode.js +0 -52
- package/dist/runtime/constant/parameterCode/ParameterCode.js +0 -617
- package/dist/runtime/entity/DataMember.js +0 -208
- package/dist/runtime/entity/GNMetadata.js +0 -11
- package/dist/runtime/entity/InvalidMember.js +0 -1
- package/dist/runtime/entity/OperationEvent.js +0 -24
- package/dist/runtime/entity/OperationHelper.js +0 -24
- package/dist/runtime/entity/OperationRequest.js +0 -42
- package/dist/runtime/entity/OperationResponse.js +0 -73
- package/dist/runtime/entity/models/AuthenticateModels.js +0 -426
- package/dist/runtime/entity/models/AuthenticateRequestModels.js +0 -188
- package/dist/runtime/entity/models/AuthenticateResponseModels.js +0 -131
- package/dist/runtime/entity/models/CharacterPlayerModels.js +0 -1437
- package/dist/runtime/entity/models/CharacterPlayerRequestModels.js +0 -1386
- package/dist/runtime/entity/models/CharacterPlayerResponseModels.js +0 -376
- package/dist/runtime/entity/models/CloudScriptModels.js +0 -197
- package/dist/runtime/entity/models/CloudScriptRequestModels.js +0 -138
- package/dist/runtime/entity/models/CloudScriptResponseModels.js +0 -40
- package/dist/runtime/entity/models/ContentModels.js +0 -203
- package/dist/runtime/entity/models/ContentRequestModels.js +0 -190
- package/dist/runtime/entity/models/ContentResponseModels.js +0 -54
- package/dist/runtime/entity/models/DashboardModels.js +0 -3002
- package/dist/runtime/entity/models/DashboardRequestModels.js +0 -268
- package/dist/runtime/entity/models/DashboardResponseModels.js +0 -187
- package/dist/runtime/entity/models/GamePlayerModels.js +0 -1591
- package/dist/runtime/entity/models/GamePlayerRequestModels.js +0 -1360
- package/dist/runtime/entity/models/GamePlayerResponseModels.js +0 -369
- package/dist/runtime/entity/models/GenericModels.js +0 -177
- package/dist/runtime/entity/models/GroupModels.js +0 -1139
- package/dist/runtime/entity/models/GroupRequestModels.js +0 -1048
- package/dist/runtime/entity/models/GroupResponseModels.js +0 -285
- package/dist/runtime/entity/models/InventoryModels.js +0 -915
- package/dist/runtime/entity/models/InventoryRequestModels.js +0 -892
- package/dist/runtime/entity/models/InventoryResponseModels.js +0 -243
- package/dist/runtime/entity/models/MasterPlayerModels.js +0 -2573
- package/dist/runtime/entity/models/MasterPlayerRequestModels.js +0 -2228
- package/dist/runtime/entity/models/MasterPlayerResponseModels.js +0 -607
- package/dist/runtime/entity/models/MultiplayerModels.js +0 -404
- package/dist/runtime/entity/models/MultiplayerRequestModels.js +0 -268
- package/dist/runtime/entity/models/MultiplayerResponseModels.js +0 -75
- package/dist/runtime/entity/models/StoreInventoryModels.js +0 -797
- package/dist/runtime/entity/models/StoreInventoryRequestModels.js +0 -372
- package/dist/runtime/entity/models/StoreInventoryResponseModels.js +0 -103
- package/dist/runtime/entity/request/CustomOperationRequest.js +0 -24
- package/dist/runtime/entity/response/CustomOperationResponse.js +0 -29
- package/dist/runtime/entity/response/GetAuthInfoResponse.js +0 -2
- package/dist/runtime/entity/response/UploadFileResponse.js +0 -2
- package/dist/runtime/helper/CodeHelper.js +0 -63
- package/dist/runtime/helper/ConverterService.js +0 -275
- package/dist/runtime/helper/EnumUtility.js +0 -33
- package/dist/runtime/helper/GNSupport.js +0 -8
- package/dist/runtime/helper/GNUtils.js +0 -72
- package/dist/runtime/helper/MessagePackConverterService.js +0 -9
- package/dist/runtime/logger/GNDebug.js +0 -29
- package/dist/runtime/networking/AuthenticateStatus.js +0 -14
- package/dist/runtime/networking/IPeer.js +0 -1
- package/dist/runtime/networking/NetworkingPeer.js +0 -178
- package/dist/runtime/networking/OperationPending.js +0 -53
- package/dist/runtime/networking/PeerBase.js +0 -161
- package/dist/runtime/networking/handler/IServerEventHandler.js +0 -13
- package/dist/runtime/networking/handler/OnCharacterPlayerFriendUpdateEventHandler.js +0 -39
- package/dist/runtime/networking/handler/OnCharacterPlayerGroupUpdateEventHandler.js +0 -39
- package/dist/runtime/networking/handler/OnGamePlayerFriendUpdateEventHandler.js +0 -39
- package/dist/runtime/networking/handler/OnGamePlayerGroupUpdateEventHandler.js +0 -39
- package/dist/runtime/networking/handler/OnGroupMemberUpdateEventHandler.js +0 -35
- package/dist/runtime/networking/handler/OnGroupMessageUpdateEventHandler.js +0 -43
- package/dist/runtime/networking/http/HttpPeer.js +0 -122
- package/dist/runtime/networking/http/NetworkingHttpPeerBase.js +0 -6
- package/dist/runtime/networking/http/NetworkingPeerAxiosRequest.js +0 -164
- package/dist/runtime/networking/socket/NetworkingPeerSocketIOClient.js +0 -130
- package/dist/runtime/networking/socket/NetworkingSocketPeerBase.js +0 -165
- package/dist/runtime/networking/socket/SocketPeer.js +0 -115
- package/dist/runtime/typescript/ServiceUpdate.js +0 -12
|
@@ -1,164 +0,0 @@
|
|
|
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
|
-
try {
|
|
39
|
-
let result = await axios.get(this.httpUrl + "/" + subUri, {
|
|
40
|
-
headers: headers,
|
|
41
|
-
timeout: timeout * 1000,
|
|
42
|
-
responseType: "arraybuffer",
|
|
43
|
-
});
|
|
44
|
-
httpAppResponse.statusCode = result.status;
|
|
45
|
-
let buffers = this.toBuffers(result.data);
|
|
46
|
-
httpAppResponse.data = buffers[0];
|
|
47
|
-
httpAppResponse.text = buffers[1];
|
|
48
|
-
}
|
|
49
|
-
catch (error) {
|
|
50
|
-
httpAppResponse.error = error.toString();
|
|
51
|
-
httpAppResponse.statusCode = -1;
|
|
52
|
-
httpAppResponse.text = "[-2]";
|
|
53
|
-
GNDebug.logError(error);
|
|
54
|
-
}
|
|
55
|
-
if (onHttpAppResponse != null)
|
|
56
|
-
onHttpAppResponse(httpAppResponse);
|
|
57
|
-
}
|
|
58
|
-
async postRequestAxios(subUri, param, postType, onHttpAppResponse, timeout, authToken, secretKey, customTags, gameId) {
|
|
59
|
-
let headers = {};
|
|
60
|
-
if (authToken)
|
|
61
|
-
headers[Commands.RequestAuthTokenCmd] = authToken;
|
|
62
|
-
if (secretKey)
|
|
63
|
-
headers[Commands.RequestSecretCmd] = secretKey;
|
|
64
|
-
if (gameId)
|
|
65
|
-
headers[Commands.RequestGameIdCmd] = gameId;
|
|
66
|
-
if (!GNSupport.isBrowser())
|
|
67
|
-
headers[Commands.USER_AGENT] = this.userAgent;
|
|
68
|
-
if (param == null)
|
|
69
|
-
param = new GNHashtable();
|
|
70
|
-
if (customTags != null)
|
|
71
|
-
param.add(ParameterCode.CustomTags, customTags);
|
|
72
|
-
let body = null;
|
|
73
|
-
if (postType == PostType.Json) {
|
|
74
|
-
let content = param.toData();
|
|
75
|
-
body = content;
|
|
76
|
-
if (!GNSupport.isBrowser()) {
|
|
77
|
-
headers[Commands.CONTENT_LENGTH] = JSON.stringify(body).length;
|
|
78
|
-
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_JSON;
|
|
79
|
-
}
|
|
80
|
-
headers[Commands.ACCEPT] = Commands.APPLICATION_JSON;
|
|
81
|
-
}
|
|
82
|
-
else if (postType == PostType.MsgPack) {
|
|
83
|
-
let content = param.toData();
|
|
84
|
-
body = Buffer.from(MessagePackConverterService.serialize(content));
|
|
85
|
-
headers[Commands.CONTENT_TYPE] = Commands.APPLICATION_MSGPACK;
|
|
86
|
-
headers[Commands.ACCEPT] = Commands.APPLICATION_MSGPACK;
|
|
87
|
-
if (!GNSupport.isBrowser())
|
|
88
|
-
headers[Commands.CONTENT_LENGTH] = body.length;
|
|
89
|
-
}
|
|
90
|
-
let httpAppResponse = new HttpAppResponse();
|
|
91
|
-
try {
|
|
92
|
-
if (postType == PostType.Json) {
|
|
93
|
-
let result = await axios.post(this.httpUrl + "/" + subUri, body, {
|
|
94
|
-
headers: headers,
|
|
95
|
-
timeout: timeout * 1000,
|
|
96
|
-
responseType: "text",
|
|
97
|
-
});
|
|
98
|
-
httpAppResponse.statusCode = result.status;
|
|
99
|
-
// let buffers = this.toBuffers(result.data);
|
|
100
|
-
// httpAppResponse.data = buffers[0];
|
|
101
|
-
httpAppResponse.text = result.data;
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
let result = await axios.post(this.httpUrl + "/" + subUri, body, {
|
|
105
|
-
headers: headers,
|
|
106
|
-
timeout: timeout * 1000,
|
|
107
|
-
responseType: "arraybuffer",
|
|
108
|
-
});
|
|
109
|
-
httpAppResponse.statusCode = result.status;
|
|
110
|
-
let buffers = this.toBuffers(result.data);
|
|
111
|
-
httpAppResponse.data = buffers[0];
|
|
112
|
-
httpAppResponse.text = buffers[1];
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
catch (error) {
|
|
116
|
-
httpAppResponse.error = error.toString();
|
|
117
|
-
httpAppResponse.statusCode = -1;
|
|
118
|
-
httpAppResponse.text = "[-2]";
|
|
119
|
-
GNDebug.logError(error);
|
|
120
|
-
}
|
|
121
|
-
if (onHttpAppResponse != null)
|
|
122
|
-
onHttpAppResponse(httpAppResponse);
|
|
123
|
-
}
|
|
124
|
-
async postRequestUploadAxios(subUri, content, filename, mimetype, onHttpAppResponse, timeout) {
|
|
125
|
-
let formData = new FormData();
|
|
126
|
-
formData.append(Commands.File, new Blob([content], { type: mimetype }), filename);
|
|
127
|
-
let headers = {};
|
|
128
|
-
headers[Commands.RequestAuthTokenCmd] = GNNetwork.getAuthenticateStatus().getAuthToken();
|
|
129
|
-
;
|
|
130
|
-
// if (!GNSupport.isBrowser()) {
|
|
131
|
-
// headers[Commands.CONTENT_TYPE] = "multipart/form-data";
|
|
132
|
-
// }
|
|
133
|
-
let httpAppResponse = new HttpAppResponse();
|
|
134
|
-
try {
|
|
135
|
-
let result = await axios.post(this.httpUrl + "/" + subUri, formData, {
|
|
136
|
-
headers: headers,
|
|
137
|
-
timeout: timeout * 1000,
|
|
138
|
-
responseType: "arraybuffer",
|
|
139
|
-
});
|
|
140
|
-
httpAppResponse.statusCode = result.status;
|
|
141
|
-
let buffers = this.toBuffers(result.data);
|
|
142
|
-
httpAppResponse.data = buffers[0];
|
|
143
|
-
httpAppResponse.text = buffers[1];
|
|
144
|
-
}
|
|
145
|
-
catch (error) {
|
|
146
|
-
httpAppResponse.error = error.toString();
|
|
147
|
-
httpAppResponse.statusCode = -1;
|
|
148
|
-
httpAppResponse.text = "[-2]";
|
|
149
|
-
GNDebug.logError(error);
|
|
150
|
-
}
|
|
151
|
-
if (onHttpAppResponse != null)
|
|
152
|
-
onHttpAppResponse(httpAppResponse);
|
|
153
|
-
}
|
|
154
|
-
uint8ArrayToString(uint8Array) {
|
|
155
|
-
return decodeURIComponent(escape(String.fromCharCode(...uint8Array)));
|
|
156
|
-
}
|
|
157
|
-
toBuffers(data) {
|
|
158
|
-
if (GNSupport.isBrowser()) {
|
|
159
|
-
data = new Uint8Array(data);
|
|
160
|
-
return [data, this.uint8ArrayToString(data)];
|
|
161
|
-
}
|
|
162
|
-
return [data, data.toString()];
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
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 "./../../entity/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
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { OperationEvent } from "./../../entity/OperationEvent";
|
|
2
|
-
import { GNNetwork } from "./../../GNNetwork";
|
|
3
|
-
import { GNDebug } from "./../../logger/GNDebug";
|
|
4
|
-
import { IServerEventHandler } from "./../handler/IServerEventHandler";
|
|
5
|
-
import { NetworkingPeerSocketIOClient } from "./NetworkingPeerSocketIOClient";
|
|
6
|
-
import { PeerBase } from "./../PeerBase";
|
|
7
|
-
import { ParameterCode } from "./../../constant/parameterCode/ParameterCode";
|
|
8
|
-
import { OperationRequest } from "./../../entity/OperationRequest";
|
|
9
|
-
export class SocketPeer extends PeerBase {
|
|
10
|
-
getClientId() {
|
|
11
|
-
return this.networkingSocketPeerBase.clientId;
|
|
12
|
-
}
|
|
13
|
-
isConnected() {
|
|
14
|
-
return this.networkingSocketPeerBase.isWsConnected;
|
|
15
|
-
}
|
|
16
|
-
sendRequestAuthSocket() {
|
|
17
|
-
this.networkingSocketPeerBase.sendRequestAuthSocket();
|
|
18
|
-
}
|
|
19
|
-
subscriberServerEventHandler() {
|
|
20
|
-
this.serverEventHandlersDict = {};
|
|
21
|
-
let serverEventHandlers = IServerEventHandler.getImplementations();
|
|
22
|
-
for (let i = 0; i < serverEventHandlers.length; i++) {
|
|
23
|
-
let serverEventHandler = new serverEventHandlers[i]();
|
|
24
|
-
if (serverEventHandler != null) {
|
|
25
|
-
let serverEventHandlers2 = this.serverEventHandlersDict[serverEventHandler.getEventCode()];
|
|
26
|
-
if (serverEventHandlers2 == null) {
|
|
27
|
-
serverEventHandlers2 = [];
|
|
28
|
-
this.serverEventHandlersDict[serverEventHandler.getEventCode()] = serverEventHandlers2;
|
|
29
|
-
}
|
|
30
|
-
serverEventHandlers2.push(serverEventHandler);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
subscriberAServerEventHandler(serverEventHandler) {
|
|
35
|
-
let serverEventHandlers2 = this.serverEventHandlersDict[serverEventHandler.getEventCode()];
|
|
36
|
-
if (serverEventHandlers2 == null) {
|
|
37
|
-
serverEventHandlers2 = [];
|
|
38
|
-
this.serverEventHandlersDict[serverEventHandler.getEventCode()] = serverEventHandlers2;
|
|
39
|
-
}
|
|
40
|
-
serverEventHandlers2.push(serverEventHandler);
|
|
41
|
-
}
|
|
42
|
-
initGNSocketObject() {
|
|
43
|
-
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
44
|
-
if (gnServerSettings == null)
|
|
45
|
-
throw new Error("Where is GN Server Settings");
|
|
46
|
-
this.isUse = gnServerSettings.isUseSocket();
|
|
47
|
-
this.networkingSocketPeerBase = new NetworkingPeerSocketIOClient();
|
|
48
|
-
this.networkingSocketPeerBase.init(gnServerSettings.getSocketUrl(), gnServerSettings.getReconnectDelay(), gnServerSettings.getPingInterval(), gnServerSettings.getPingTimeout());
|
|
49
|
-
this.networkingSocketPeerBase.reInitNewSocket();
|
|
50
|
-
let thiz = this;
|
|
51
|
-
this.networkingSocketPeerBase.setOnEventHandler((t1) => {
|
|
52
|
-
thiz.onEventHandler(t1);
|
|
53
|
-
});
|
|
54
|
-
this.networkingSocketPeerBase.setOnResponseHandler((t1) => {
|
|
55
|
-
thiz.onResponseHandler(t1);
|
|
56
|
-
});
|
|
57
|
-
this.subscriberServerEventHandler();
|
|
58
|
-
}
|
|
59
|
-
setOnConnectHandler(_onConnectHandler) {
|
|
60
|
-
this.networkingSocketPeerBase.setOnConnectHandler(_onConnectHandler);
|
|
61
|
-
}
|
|
62
|
-
setOnDisconnectHandler(_onDisconnectHandler) {
|
|
63
|
-
this.networkingSocketPeerBase.setOnDisconnectHandler(_onDisconnectHandler);
|
|
64
|
-
}
|
|
65
|
-
removeOnConnectHandler(_onConnectHandler) {
|
|
66
|
-
this.networkingSocketPeerBase.removeOnConnectHandler(_onConnectHandler);
|
|
67
|
-
}
|
|
68
|
-
removeOnDisconnectHandler(_onDisconnectHandler) {
|
|
69
|
-
this.networkingSocketPeerBase.removeOnDisconnectHandler(_onDisconnectHandler);
|
|
70
|
-
}
|
|
71
|
-
connect(_onSocketConnect) {
|
|
72
|
-
this.networkingSocketPeerBase.connect(_onSocketConnect);
|
|
73
|
-
}
|
|
74
|
-
disconnect(_onSocketDisconnect) {
|
|
75
|
-
this.networkingSocketPeerBase.close(_onSocketDisconnect);
|
|
76
|
-
}
|
|
77
|
-
setOnEventHandler(_onEventHandler) {
|
|
78
|
-
this._onEventHandler = _onEventHandler;
|
|
79
|
-
}
|
|
80
|
-
send(operationPending) {
|
|
81
|
-
let gnServerSettings = GNNetwork.getGNServerSettings();
|
|
82
|
-
let operationRequest = operationPending.getOperationRequest();
|
|
83
|
-
if (operationRequest.getTimeout() == OperationRequest.defaultTimeOut)
|
|
84
|
-
operationRequest.setTimeout(gnServerSettings.getDefaultTimeoutInSeconds());
|
|
85
|
-
super.send(operationPending);
|
|
86
|
-
GNDebug.log("[GN Socket SEND] " + operationPending.getOperationRequest().toString());
|
|
87
|
-
let authToken = operationPending.getAuthToken();
|
|
88
|
-
let secretKey = operationPending.getSecretKey();
|
|
89
|
-
let gameId = operationPending.getGameId();
|
|
90
|
-
let customTags = operationPending.getCustomTags();
|
|
91
|
-
this.networkingSocketPeerBase.send(operationPending.getRequestType(), operationPending.getRole(), operationPending.getOperationRequest(), authToken, secretKey, customTags, gameId);
|
|
92
|
-
}
|
|
93
|
-
onEnqueue(operationPending) {
|
|
94
|
-
GNDebug.log("[GN Socket ENQUEUE] " + operationPending.getOperationRequest().toString());
|
|
95
|
-
}
|
|
96
|
-
onEventHandler(obj) {
|
|
97
|
-
let eventCode = obj.getString(ParameterCode.EventCode);
|
|
98
|
-
let operationEvent = new OperationEvent(eventCode, obj.getGNHashtable(ParameterCode.Parameters));
|
|
99
|
-
GNDebug.log("[GN Socket EVENT] " + operationEvent.toString());
|
|
100
|
-
if (this._onEventHandler != null)
|
|
101
|
-
this._onEventHandler(operationEvent);
|
|
102
|
-
let serverEventHandlers = this.serverEventHandlersDict[eventCode];
|
|
103
|
-
if (serverEventHandlers == null)
|
|
104
|
-
return;
|
|
105
|
-
serverEventHandlers.forEach(serverEventHandler => {
|
|
106
|
-
if (serverEventHandler != null) {
|
|
107
|
-
serverEventHandler.handle(operationEvent);
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
service() {
|
|
112
|
-
super.service();
|
|
113
|
-
this.networkingSocketPeerBase.service();
|
|
114
|
-
}
|
|
115
|
-
}
|