@xmobitea/gn-typescript-client 0.0.1
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/GNServerSettingsConfig.debug.json +21 -0
- package/dist/editor/GNServerSettingsEditor.d.ts +2 -0
- package/dist/index.d.ts +160 -0
- package/dist/runtime/GNNetwork.d.ts +85 -0
- package/dist/runtime/common/Action0.d.ts +3 -0
- package/dist/runtime/common/Action1.d.ts +3 -0
- package/dist/runtime/common/Action2.d.ts +3 -0
- package/dist/runtime/common/Action3.d.ts +3 -0
- package/dist/runtime/common/Action4.d.ts +3 -0
- package/dist/runtime/common/GNData.d.ts +69 -0
- package/dist/runtime/config/GNServerSettings.d.ts +56 -0
- package/dist/runtime/constant/Commands.d.ts +16 -0
- package/dist/runtime/constant/EventCode.d.ts +3 -0
- package/dist/runtime/constant/OperationCode.d.ts +13 -0
- package/dist/runtime/constant/ReturnCode.d.ts +12 -0
- package/dist/runtime/constant/enumType/FriendStatus.d.ts +6 -0
- package/dist/runtime/constant/enumType/GoogleLoginType.d.ts +4 -0
- package/dist/runtime/constant/enumType/InvalidMemberType.d.ts +17 -0
- package/dist/runtime/constant/enumType/LoginType.d.ts +10 -0
- package/dist/runtime/constant/enumType/PlatformType.d.ts +8 -0
- package/dist/runtime/constant/enumType/UserRoleType.d.ts +8 -0
- package/dist/runtime/constant/errorCode/DebugErrorCode.d.ts +3 -0
- package/dist/runtime/constant/errorCode/EnterDisplayNameErrorCode.d.ts +3 -0
- package/dist/runtime/constant/errorCode/FetchAllDataErrorCode.d.ts +4 -0
- package/dist/runtime/constant/errorCode/FetchSparkPlayerErrorCode.d.ts +4 -0
- package/dist/runtime/constant/errorCode/FileUploadInfoErrorCode.d.ts +5 -0
- package/dist/runtime/constant/errorCode/GetAppConfigErrorCode.d.ts +3 -0
- package/dist/runtime/constant/errorCode/LoginErrorCode.d.ts +11 -0
- package/dist/runtime/constant/errorCode/RegisterSocketErrorCode.d.ts +3 -0
- package/dist/runtime/constant/parameterCode/DebugParameterCode.d.ts +7 -0
- package/dist/runtime/constant/parameterCode/EnterDisplayNameParameterCode.d.ts +4 -0
- package/dist/runtime/constant/parameterCode/FetchAllDataParameterCode.d.ts +7 -0
- package/dist/runtime/constant/parameterCode/FetchSparkPlayerParameterCode.d.ts +15 -0
- package/dist/runtime/constant/parameterCode/FileUploadInfoParameterCode.d.ts +11 -0
- package/dist/runtime/constant/parameterCode/GetAppConfigParameterCode.d.ts +4 -0
- package/dist/runtime/constant/parameterCode/LoginParameterCode.d.ts +18 -0
- package/dist/runtime/constant/parameterCode/ParameterCode.d.ts +6 -0
- package/dist/runtime/constant/parameterCode/RegisterSocketParameterCode.d.ts +3 -0
- package/dist/runtime/entity/InvalidMember.d.ts +5 -0
- package/dist/runtime/entity/OperationEvent.d.ts +14 -0
- package/dist/runtime/entity/OperationHelper.d.ts +16 -0
- package/dist/runtime/entity/OperationRequest.d.ts +23 -0
- package/dist/runtime/entity/OperationResponse.d.ts +27 -0
- package/dist/runtime/entity/request/CreateNewFileUploadInfoOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/CustomOperationRequest.d.ts +10 -0
- package/dist/runtime/entity/request/DebugOperationRequest.d.ts +7 -0
- package/dist/runtime/entity/request/EnterDisplayNameOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/FetchAllDataOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/FetchSparkPlayerOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/GetAppConfigOperationRequest.d.ts +7 -0
- package/dist/runtime/entity/request/GetFileUploadInfoOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/LoginOperationRequest.d.ts +33 -0
- package/dist/runtime/entity/request/LogoutOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/RegisterAccountOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/RegisterSocketOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/request/TemplateOperationRequest.d.ts +6 -0
- package/dist/runtime/entity/response/CreateNewFileUploadInfoOperationResponse.d.ts +10 -0
- package/dist/runtime/entity/response/CustomOperationResponse.d.ts +14 -0
- package/dist/runtime/entity/response/DebugOperationResponse.d.ts +11 -0
- package/dist/runtime/entity/response/EnterDisplayNameOperationResponse.d.ts +7 -0
- package/dist/runtime/entity/response/FetchAllDataOperationResponse.d.ts +10 -0
- package/dist/runtime/entity/response/FetchSparkPlayerOperationResponse.d.ts +20 -0
- package/dist/runtime/entity/response/GetAppConfigOperationResponse.d.ts +6 -0
- package/dist/runtime/entity/response/GetFileUploadInfoOperationResponse.d.ts +15 -0
- package/dist/runtime/entity/response/LoginOperationResponse.d.ts +9 -0
- package/dist/runtime/entity/response/LogoutOperationResponse.d.ts +5 -0
- package/dist/runtime/entity/response/PublicAddressGetRandomMessageOperationResponse.d.ts +6 -0
- package/dist/runtime/entity/response/RegisterAccountOperationResponse.d.ts +5 -0
- package/dist/runtime/entity/response/RegisterSocketOperationResponse.d.ts +5 -0
- package/dist/runtime/entity/response/TemplateOperationResponse.d.ts +6 -0
- package/dist/runtime/helper/CodeHelper.d.ts +16 -0
- package/dist/runtime/helper/GNSupport.d.ts +5 -0
- package/dist/runtime/logger/GNDebug.d.ts +15 -0
- package/dist/runtime/networking/HttpPeer.d.ts +29 -0
- package/dist/runtime/networking/IPeer.d.ts +9 -0
- package/dist/runtime/networking/NetworkingPeer.d.ts +74 -0
- package/dist/runtime/networking/NetworkingPeerBase.d.ts +47 -0
- package/dist/runtime/networking/NetworkingPeerSocket.d.ts +22 -0
- package/dist/runtime/networking/OperationPending.d.ts +17 -0
- package/dist/runtime/networking/PeerBase.d.ts +28 -0
- package/dist/runtime/networking/SocketPeer.d.ts +24 -0
- package/dist/runtime/networking/handler/IServerEventHandler.d.ts +14 -0
- package/dist/runtime/networking/handler/OnDebugEventHander.d.ts +6 -0
- package/index.js +391 -0
- package/package.json +37 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Action0 } from "./../common/Action0";
|
|
2
|
+
import { OperationRequest } from "./../entity/OperationRequest";
|
|
3
|
+
import { NetworkingPeerBase } from "./NetworkingPeerBase";
|
|
4
|
+
export declare class NetworkingPeerSocket extends NetworkingPeerBase {
|
|
5
|
+
private socketManager;
|
|
6
|
+
private socket;
|
|
7
|
+
private isConnected;
|
|
8
|
+
isWsConnected: boolean;
|
|
9
|
+
sendRequestAuthSocket(): void;
|
|
10
|
+
reInitNewSocket(): void;
|
|
11
|
+
private onResponseMsgPack;
|
|
12
|
+
private onEventMsgPack;
|
|
13
|
+
private onResponseJson;
|
|
14
|
+
private onEventJson;
|
|
15
|
+
private onConnect;
|
|
16
|
+
private onDisconnect;
|
|
17
|
+
private onError;
|
|
18
|
+
init(url: string, reconnectDelay: number, pingInterval: number, pingTimeout: number): void;
|
|
19
|
+
protected emit(operationRequest: OperationRequest): void;
|
|
20
|
+
close(_onSocketDisconnect: Action0): void;
|
|
21
|
+
connect(_onSocketConnect: Action0): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Action1 } from "./../common/Action1";
|
|
2
|
+
import { OperationRequest } from "./../entity/OperationRequest";
|
|
3
|
+
import { OperationResponse } from "./../entity/OperationResponse";
|
|
4
|
+
export declare class OperationPending {
|
|
5
|
+
private operationRequest;
|
|
6
|
+
private onOperationResponse;
|
|
7
|
+
private timeout;
|
|
8
|
+
private firstSend;
|
|
9
|
+
private secondsSend;
|
|
10
|
+
constructor(operationRequest: OperationRequest, onOperationResponse: Action1<OperationResponse>);
|
|
11
|
+
onSend(): void;
|
|
12
|
+
onRecv(): void;
|
|
13
|
+
getExecuteTimerInMs(): number;
|
|
14
|
+
isTimeout(): boolean;
|
|
15
|
+
getOperationRequest(): OperationRequest;
|
|
16
|
+
getCallback(): Action1<OperationResponse>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Action1 } from "./../common/Action1";
|
|
2
|
+
import { GNArray } from "./../common/GNData";
|
|
3
|
+
import { OperationRequest } from "./../entity/OperationRequest";
|
|
4
|
+
import { OperationResponse } from "./../entity/OperationResponse";
|
|
5
|
+
import { IPeer } from "./IPeer";
|
|
6
|
+
import { OperationPending } from "./OperationPending";
|
|
7
|
+
export declare abstract class PeerBase implements IPeer {
|
|
8
|
+
private operationPendingQueue;
|
|
9
|
+
private operationWaitingResponseDic;
|
|
10
|
+
private static requestId;
|
|
11
|
+
private perMsgTimer;
|
|
12
|
+
private nextSendMsgTimer;
|
|
13
|
+
private checkTimeoutOperationPending;
|
|
14
|
+
protected getSendRate(): number;
|
|
15
|
+
protected setSendRate(sendRate: number): void;
|
|
16
|
+
ping: number;
|
|
17
|
+
private pingLst;
|
|
18
|
+
protected isUse: boolean;
|
|
19
|
+
initPeer(): void;
|
|
20
|
+
private initSendRate;
|
|
21
|
+
protected abstract initGNSocketObject(): void;
|
|
22
|
+
enqueue(operationRequest: OperationRequest, onOperationResponse: Action1<OperationResponse>): void;
|
|
23
|
+
isUsing(): boolean;
|
|
24
|
+
service(): void;
|
|
25
|
+
protected onResponseHandler(obj: GNArray, isEncrypted: boolean): void;
|
|
26
|
+
send(operationPending: OperationPending): void;
|
|
27
|
+
addPing(value: number): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Action0 } from "./../common/Action0";
|
|
2
|
+
import { GNArray } from "./../common/GNData";
|
|
3
|
+
import { IServerEventHandler } from "./handler/IServerEventHandler";
|
|
4
|
+
import { OperationPending } from "./OperationPending";
|
|
5
|
+
import { PeerBase } from "./PeerBase";
|
|
6
|
+
export declare class SocketPeer extends PeerBase {
|
|
7
|
+
private serverEventHandlerDic;
|
|
8
|
+
private networkingPeerBase;
|
|
9
|
+
getClientId(): string;
|
|
10
|
+
isConnected(): boolean;
|
|
11
|
+
sendRequestAuthSocket(): void;
|
|
12
|
+
subscriberServerEventHandler(): void;
|
|
13
|
+
subscriberAServerEventHandler(serverEventHandler: IServerEventHandler): void;
|
|
14
|
+
initGNSocketObject(): void;
|
|
15
|
+
setOnConnectHandler(_onConnectHandler: Action0): void;
|
|
16
|
+
setOnDisconnectHandler(_onDisconnectHandler: Action0): void;
|
|
17
|
+
removeOnConnectHandler(_onConnectHandler: Action0): void;
|
|
18
|
+
removeOnDisconnectHandler(_onDisconnectHandler: Action0): void;
|
|
19
|
+
connect(_onSocketConnect: Action0): void;
|
|
20
|
+
disconnect(_onSocketDisconnect: Action0): void;
|
|
21
|
+
send(operationPending: OperationPending): void;
|
|
22
|
+
onEventHandler(obj: GNArray, isEncrypted: boolean): void;
|
|
23
|
+
service(): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OperationEvent } from "./../../entity/OperationEvent";
|
|
2
|
+
export interface IServerEventHandler {
|
|
3
|
+
getEventCode(): number;
|
|
4
|
+
handle(operationEvent: OperationEvent): void;
|
|
5
|
+
}
|
|
6
|
+
export declare namespace IServerEventHandler {
|
|
7
|
+
type Constructor<T> = {
|
|
8
|
+
new (...args: any[]): T;
|
|
9
|
+
readonly prototype: T;
|
|
10
|
+
};
|
|
11
|
+
export function getImplementations(): Constructor<IServerEventHandler>[];
|
|
12
|
+
export function registerEvent<T extends Constructor<IServerEventHandler>>(ctor: T): T;
|
|
13
|
+
export {};
|
|
14
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { OperationEvent } from "./../../entity/OperationEvent";
|
|
2
|
+
import { IServerEventHandler } from "./IServerEventHandler";
|
|
3
|
+
export declare class OnDebugEventHander implements IServerEventHandler {
|
|
4
|
+
getEventCode(): number;
|
|
5
|
+
handle(operationEvent: OperationEvent): void;
|
|
6
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
GNNetwork,
|
|
5
|
+
GNServerSettings,
|
|
6
|
+
OperationCode,
|
|
7
|
+
LogType,
|
|
8
|
+
LoginOperationResponse,
|
|
9
|
+
ReturnCode,
|
|
10
|
+
GNDebug
|
|
11
|
+
} = require("./dist/index");
|
|
12
|
+
|
|
13
|
+
const encode = require("@msgpack/msgpack").encode;
|
|
14
|
+
const decode = require("@msgpack/msgpack").decode;
|
|
15
|
+
var axios = require("axios");
|
|
16
|
+
const FormData = require('form-data');
|
|
17
|
+
|
|
18
|
+
const optionsPath = __dirname + "/./GNServerSettingsConfig.debug.json";
|
|
19
|
+
let optionStr = fs.readFileSync(optionsPath).toString();
|
|
20
|
+
let fullOptions = JSON.parse(optionStr);
|
|
21
|
+
let options = fullOptions.options;
|
|
22
|
+
|
|
23
|
+
let gnServerSettings = new GNServerSettings();
|
|
24
|
+
gnServerSettings.config(options);
|
|
25
|
+
|
|
26
|
+
// gnServerSettings.serverAddress = "127.0.0.1";
|
|
27
|
+
// gnServerSettings.serverPort = 2202;
|
|
28
|
+
// gnServerSettings.useSsl = false;
|
|
29
|
+
// gnServerSettings.useSocket = true;
|
|
30
|
+
// gnServerSettings.useHttp = true;
|
|
31
|
+
// gnServerSettings.sendRate = 20;
|
|
32
|
+
// gnServerSettings.reconnectDelay = 5000;
|
|
33
|
+
// gnServerSettings.pingInterval = 20000;
|
|
34
|
+
// gnServerSettings.pingTimeout = 20000;
|
|
35
|
+
// gnServerSettings.codeCanSendNotAuthorized = [OperationCode.Debug, OperationCode.GetAppConfig, OperationCode.Login, OperationCode.RegisterAccount];
|
|
36
|
+
// gnServerSettings.logType = LogType.All;
|
|
37
|
+
|
|
38
|
+
GNNetwork.init(gnServerSettings);
|
|
39
|
+
// GNNetwork.connectSocket({
|
|
40
|
+
// invoke: () => {
|
|
41
|
+
// console.log("connect success");
|
|
42
|
+
// }
|
|
43
|
+
// });
|
|
44
|
+
|
|
45
|
+
GNNetwork.deviceLogin({
|
|
46
|
+
invoke: function (loginOperationResponse) {
|
|
47
|
+
console.log(loginOperationResponse.parameters);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// var a = new Uint8Array([
|
|
52
|
+
// 91,
|
|
53
|
+
// 49,
|
|
54
|
+
// 44,
|
|
55
|
+
// 123,
|
|
56
|
+
// 34,
|
|
57
|
+
// 69,
|
|
58
|
+
// 34,
|
|
59
|
+
// 58,
|
|
60
|
+
// 49,
|
|
61
|
+
// 44,
|
|
62
|
+
// 34,
|
|
63
|
+
// 65,
|
|
64
|
+
// 34,
|
|
65
|
+
// 58,
|
|
66
|
+
// 34,
|
|
67
|
+
// 57,
|
|
68
|
+
// 56,
|
|
69
|
+
// 54,
|
|
70
|
+
// 99,
|
|
71
|
+
// 53,
|
|
72
|
+
// 51,
|
|
73
|
+
// 55,
|
|
74
|
+
// 100,
|
|
75
|
+
// 55,
|
|
76
|
+
// 48,
|
|
77
|
+
// 54,
|
|
78
|
+
// 53,
|
|
79
|
+
// 55,
|
|
80
|
+
// 55,
|
|
81
|
+
// 97,
|
|
82
|
+
// 102,
|
|
83
|
+
// 99,
|
|
84
|
+
// 98,
|
|
85
|
+
// 52,
|
|
86
|
+
// 54,
|
|
87
|
+
// 49,
|
|
88
|
+
// 53,
|
|
89
|
+
// 51,
|
|
90
|
+
// 100,
|
|
91
|
+
// 102,
|
|
92
|
+
// 49,
|
|
93
|
+
// 51,
|
|
94
|
+
// 50,
|
|
95
|
+
// 54,
|
|
96
|
+
// 97,
|
|
97
|
+
// 48,
|
|
98
|
+
// 52,
|
|
99
|
+
// 34,
|
|
100
|
+
// 44,
|
|
101
|
+
// 34,
|
|
102
|
+
// 85,
|
|
103
|
+
// 34,
|
|
104
|
+
// 58,
|
|
105
|
+
// 34,
|
|
106
|
+
// 54,
|
|
107
|
+
// 51,
|
|
108
|
+
// 98,
|
|
109
|
+
// 100,
|
|
110
|
+
// 52,
|
|
111
|
+
// 99,
|
|
112
|
+
// 53,
|
|
113
|
+
// 54,
|
|
114
|
+
// 98,
|
|
115
|
+
// 57,
|
|
116
|
+
// 54,
|
|
117
|
+
// 50,
|
|
118
|
+
// 55,
|
|
119
|
+
// 53,
|
|
120
|
+
// 54,
|
|
121
|
+
// 98,
|
|
122
|
+
// 56,
|
|
123
|
+
// 48,
|
|
124
|
+
// 54,
|
|
125
|
+
// 48,
|
|
126
|
+
// 97,
|
|
127
|
+
// 49,
|
|
128
|
+
// 98,
|
|
129
|
+
// 97,
|
|
130
|
+
// 34,
|
|
131
|
+
// 125,
|
|
132
|
+
// 93
|
|
133
|
+
// ]);
|
|
134
|
+
// console.log(utf8ArrayToString(a));;
|
|
135
|
+
|
|
136
|
+
// function bytesToSring(bytes) {
|
|
137
|
+
// var chars = [];
|
|
138
|
+
// for (var i = 0, n = bytes.length; i < n;) {
|
|
139
|
+
// chars.push(((bytes[i++] & 0xff) << 8) | (bytes[i++] & 0xff));
|
|
140
|
+
// }
|
|
141
|
+
// return String.fromCharCode.apply(null, chars);
|
|
142
|
+
// }
|
|
143
|
+
|
|
144
|
+
// console.log(decodeURIComponent(escape(String.fromCharCode(... a))));
|
|
145
|
+
// function utf8ArrayToString(aBytes) {
|
|
146
|
+
// var sView = "";
|
|
147
|
+
|
|
148
|
+
// for (var nPart, nLen = aBytes.length, nIdx = 0; nIdx < nLen; nIdx++) {
|
|
149
|
+
// nPart = aBytes[nIdx];
|
|
150
|
+
|
|
151
|
+
// sView += String.fromCharCode(nPart > 251 && nPart < 254 && nIdx + 5 < nLen ?
|
|
152
|
+
// /* six bytes */
|
|
153
|
+
// /* (nPart - 252 << 30) may be not so safe in ECMAScript! So...: */
|
|
154
|
+
// (nPart - 252) * 1073741824 + (aBytes[++ nIdx] - 128 << 24) + (aBytes[++ nIdx] - 128 << 18) + (aBytes[++ nIdx] - 128 << 12) + (aBytes[++ nIdx] - 128 << 6) + aBytes[++ nIdx] - 128 : nPart > 247 && nPart < 252 && nIdx + 4 < nLen ? /* five bytes */
|
|
155
|
+
// (nPart - 248 << 24) + (aBytes[++ nIdx] - 128 << 18) + (aBytes[++ nIdx] - 128 << 12) + (aBytes[++ nIdx] - 128 << 6) + aBytes[++ nIdx] - 128 : nPart > 239 && nPart < 248 && nIdx + 3 < nLen ? /* four bytes */
|
|
156
|
+
// (nPart - 240 << 18) + (aBytes[++ nIdx] - 128 << 12) + (aBytes[++ nIdx] - 128 << 6) + aBytes[++ nIdx] - 128 : nPart > 223 && nPart < 240 && nIdx + 2 < nLen ? /* three bytes */
|
|
157
|
+
// (nPart - 224 << 12) + (aBytes[++ nIdx] - 128 << 6) + aBytes[++ nIdx] - 128 : nPart > 191 && nPart < 224 && nIdx + 1 < nLen ? /* two bytes */
|
|
158
|
+
// (nPart - 192 << 6) + aBytes[++ nIdx] - 128 :
|
|
159
|
+
// /* nPart < 127 ? */
|
|
160
|
+
// /* one byte */
|
|
161
|
+
// nPart);
|
|
162
|
+
// }
|
|
163
|
+
|
|
164
|
+
// return sView;
|
|
165
|
+
// }
|
|
166
|
+
|
|
167
|
+
// function Utf8ArrayToStr(array) {
|
|
168
|
+
// var out,
|
|
169
|
+
// i,
|
|
170
|
+
// len,
|
|
171
|
+
// c;
|
|
172
|
+
// var char2,
|
|
173
|
+
// char3;
|
|
174
|
+
|
|
175
|
+
// out = "";
|
|
176
|
+
// len = array.length;
|
|
177
|
+
// i = 0;
|
|
178
|
+
// while (i < len) {
|
|
179
|
+
// c = array[i++];
|
|
180
|
+
// switch (c >> 4) {
|
|
181
|
+
// case 0:
|
|
182
|
+
// case 1:
|
|
183
|
+
// case 2:
|
|
184
|
+
// case 3:
|
|
185
|
+
// case 4:
|
|
186
|
+
// case 5:
|
|
187
|
+
// case 6:
|
|
188
|
+
// case 7:
|
|
189
|
+
// // 0xxxxxxx
|
|
190
|
+
// out += String.fromCharCode(c);
|
|
191
|
+
// break;
|
|
192
|
+
// case 12:
|
|
193
|
+
// case 13:
|
|
194
|
+
// // 110x xxxx 10xx xxxx
|
|
195
|
+
// char2 = array[i++];
|
|
196
|
+
// out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
|
197
|
+
// break;
|
|
198
|
+
// case 14:
|
|
199
|
+
// // 1110 xxxx 10xx xxxx 10xx xxxx
|
|
200
|
+
// char2 = array[i++];
|
|
201
|
+
// char3 = array[i++];
|
|
202
|
+
// out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
|
|
203
|
+
// break;
|
|
204
|
+
// }
|
|
205
|
+
// }
|
|
206
|
+
|
|
207
|
+
// return out;
|
|
208
|
+
// }
|
|
209
|
+
|
|
210
|
+
// var data = encode({"1":2,"4":"17_503b123a-e2ba-4305-a517-90bda87692fe"});
|
|
211
|
+
// var request3 = async function () {
|
|
212
|
+
// axios.post("http://127.0.0.1:2202/api/1/2", data, {
|
|
213
|
+
// "headers": {
|
|
214
|
+
// "Content-Type": "application/msgpack",
|
|
215
|
+
// "Content-Length": data.length
|
|
216
|
+
// },
|
|
217
|
+
// responseType: "arraybuffer",
|
|
218
|
+
// }).then(x => {
|
|
219
|
+
// console.log(x.data.toString());
|
|
220
|
+
// });
|
|
221
|
+
|
|
222
|
+
// let formData = new FormData();
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
// var data = encode({"1": 2, "4": "17_503b123a-e2ba-4305-a517-90bda87692fe"});
|
|
226
|
+
|
|
227
|
+
// let formData = new FormData();
|
|
228
|
+
// formData.append("1", 2);
|
|
229
|
+
// formData.append("4", "17_503b123a-e2ba-4305-a517-90bda87692fe");
|
|
230
|
+
// console.log(formData.getHeaders());
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
// var request4 = async function () {
|
|
234
|
+
// axios.post("http://127.0.0.1:2202/api/1/2", encode({"1":2,"4":"17_503b123a-e2ba-4305-a517-90bda87692fe"}), {
|
|
235
|
+
// headers: new axios.AxiosHeaders().set("content-type", "application/msgpack").set("content-length", encode({"1":2,"4":"17_503b123a-e2ba-4305-a517-90bda87692fe"}).length),
|
|
236
|
+
// responseType: "arraybuffer",
|
|
237
|
+
|
|
238
|
+
// }).then(x => {
|
|
239
|
+
// console.log(x.data.toString());
|
|
240
|
+
// });
|
|
241
|
+
// }
|
|
242
|
+
// request4();
|
|
243
|
+
|
|
244
|
+
// }
|
|
245
|
+
|
|
246
|
+
// request3();
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
// let gnServerSettings = new GN.GNServerSettings();
|
|
250
|
+
|
|
251
|
+
// gnServerSettings.serverAddress = "127.0.0.1";
|
|
252
|
+
// gnServerSettings.serverPort = 2202;
|
|
253
|
+
// gnServerSettings.useSsl = false;
|
|
254
|
+
// gnServerSettings.useSocket = true;
|
|
255
|
+
// gnServerSettings.useHttp = true;
|
|
256
|
+
// gnServerSettings.sendRate = 20;
|
|
257
|
+
// gnServerSettings.reconnectDelay = 5000;
|
|
258
|
+
// gnServerSettings.pingInterval = 20000;
|
|
259
|
+
// gnServerSettings.pingTimeout = 20000;
|
|
260
|
+
// gnServerSettings.codeCanSendNotAuthorized = [GN.OperationCode.Debug, GN.OperationCode.GetAppConfig, GN.OperationCode.Login, GN.OperationCode.RegisterAccount];
|
|
261
|
+
// gnServerSettings.logType = GN.LogType.All;
|
|
262
|
+
|
|
263
|
+
// GN.GNNetwork.init(gnServerSettings);
|
|
264
|
+
|
|
265
|
+
// // var http = require("http");
|
|
266
|
+
|
|
267
|
+
// // var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
|
|
268
|
+
|
|
269
|
+
// // let request = new XMLHttpRequest();
|
|
270
|
+
// // request.open("POST", "http://127.0.0.1:2202/api/0/2", true);
|
|
271
|
+
|
|
272
|
+
// // request.setRequestHeader(USER_AGENT, HttpPeer.userAgent);
|
|
273
|
+
|
|
274
|
+
// // request.timeout = 15 * 1000;
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
// var request2 = async function () {
|
|
278
|
+
// let result = await axios.post("http://127.0.0.1:2202/api/1/2", data, {
|
|
279
|
+
// "headers": {
|
|
280
|
+
// "Content-Type": "application/msgpack"
|
|
281
|
+
// },
|
|
282
|
+
// responseType: "arraybuffer",
|
|
283
|
+
// });
|
|
284
|
+
|
|
285
|
+
// console.log(result.data.toString());
|
|
286
|
+
|
|
287
|
+
// }
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
// // request.
|
|
291
|
+
|
|
292
|
+
// // request.setRequestHeader("content-type", "application/json");
|
|
293
|
+
|
|
294
|
+
// // let content = [0];
|
|
295
|
+
// // let body = JSON.stringify(content);
|
|
296
|
+
// // //let body = encode(content);
|
|
297
|
+
|
|
298
|
+
// // request.responseType = "application/json";
|
|
299
|
+
|
|
300
|
+
// // request.send(body);
|
|
301
|
+
|
|
302
|
+
// const { io, Socket, Manager } = require("./src/plugins/socket.io.esm.min.js");
|
|
303
|
+
|
|
304
|
+
// const manager = new Manager("http://127.0.0.1:2202/socket.io/", {
|
|
305
|
+
// autoConnect: true,
|
|
306
|
+
// transports: ["websocket"],
|
|
307
|
+
// reconnection: true,
|
|
308
|
+
// reconnectionDelay: 300,
|
|
309
|
+
|
|
310
|
+
// });
|
|
311
|
+
|
|
312
|
+
// console.log("open");
|
|
313
|
+
|
|
314
|
+
// manager.open(err => {
|
|
315
|
+
// console.log(err);
|
|
316
|
+
// });
|
|
317
|
+
|
|
318
|
+
// const socket = manager.socket("/");
|
|
319
|
+
// socket.connect();
|
|
320
|
+
|
|
321
|
+
// socket.io.on("error", (error) => {
|
|
322
|
+
// console.log("error " + error);
|
|
323
|
+
// });
|
|
324
|
+
|
|
325
|
+
// socket.io.on("ping", () => {
|
|
326
|
+
// console.log("ping");
|
|
327
|
+
// });
|
|
328
|
+
|
|
329
|
+
// socket.io.on("reconnect", (attempt) => {
|
|
330
|
+
// console.log("reconnect " + attempt);
|
|
331
|
+
// });
|
|
332
|
+
|
|
333
|
+
// socket.io.on("reconnect_attempt", (attempt) => {
|
|
334
|
+
// console.log("reconnect_attempt " + attempt);
|
|
335
|
+
// });
|
|
336
|
+
|
|
337
|
+
// socket.io.on("reconnect_error", (error) => {
|
|
338
|
+
// console.log("reconnect_error " + error);
|
|
339
|
+
// });
|
|
340
|
+
|
|
341
|
+
// socket.io.on("reconnect_failed", () => {
|
|
342
|
+
// console.log("reconnect_failed");
|
|
343
|
+
// });
|
|
344
|
+
|
|
345
|
+
// socket.on("open", l => {
|
|
346
|
+
// console.log("on open");
|
|
347
|
+
// });
|
|
348
|
+
|
|
349
|
+
// socket.on("r", (...l) => {
|
|
350
|
+
// console.log(l[0].length);
|
|
351
|
+
// console.log(decode(l[0]));
|
|
352
|
+
// })
|
|
353
|
+
|
|
354
|
+
// socket.on("connect", (listener) => {
|
|
355
|
+
// console.log("on connect");
|
|
356
|
+
// //socket.emit("r", encode([2]));
|
|
357
|
+
|
|
358
|
+
// //socket.disconnect();
|
|
359
|
+
// });
|
|
360
|
+
|
|
361
|
+
// socket.on("disconnect", () => {
|
|
362
|
+
// console.log("on disconnect");
|
|
363
|
+
|
|
364
|
+
// //setTimeout(() => socket.connect(), 3000);
|
|
365
|
+
// });
|
|
366
|
+
|
|
367
|
+
// // // manager.open((err) => {
|
|
368
|
+
// // // if (err) { // an error has occurred
|
|
369
|
+
// // // } else { // the connection was successfully established
|
|
370
|
+
// // // }
|
|
371
|
+
|
|
372
|
+
// // // console.log("open " + err);
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
// // // });
|
|
376
|
+
|
|
377
|
+
process.on("uncaughtException", (uncaughtException) => {
|
|
378
|
+
GNDebug.log("Uncaught Exception at: %s - message: %s", uncaughtException.stack, uncaughtException.message);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
process.on("uncaughtError", (uncaughtException) => {
|
|
382
|
+
GNDebug.log("Uncaught Error at: %s - message: %s", uncaughtException.stack, uncaughtException.message);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
process.on("unhandledRejection", (reason) => {
|
|
386
|
+
GNDebug.log("Unhandled Rejection at: %s - message: %s", reason.stack, reason.message);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
// console.log(manager);
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xmobitea/gn-typescript-client",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"debug": "node index.js",
|
|
9
|
+
"test": "mocha -r ts-node/register ./test/**/*.test.ts",
|
|
10
|
+
"build": "rm -rf ./dist && webpack --mode production --display-modules",
|
|
11
|
+
"push": "npm run build && npm run test && npm publish && git push"
|
|
12
|
+
},
|
|
13
|
+
"author": "changx.develop@gmail.com (https://xmobitea.com)",
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"@types/mocha": "^8.2.2",
|
|
17
|
+
"@types/node-localstorage": "^1.3.0",
|
|
18
|
+
"mocha": "^9.2.2",
|
|
19
|
+
"terser-webpack-plugin": "^4.2.3",
|
|
20
|
+
"ts-loader": "^8.0.17",
|
|
21
|
+
"ts-node": "^10.8.1",
|
|
22
|
+
"tslib": "^2.1.0",
|
|
23
|
+
"webpack": "^5.71.0",
|
|
24
|
+
"webpack-cli": "^3.3.12",
|
|
25
|
+
"webpack-node-externals": "^3.0.0"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@msgpack/msgpack": "^2.7.2",
|
|
29
|
+
"axios": "^1.2.2",
|
|
30
|
+
"crypto": "^1.0.1",
|
|
31
|
+
"node-localstorage": "^2.2.1",
|
|
32
|
+
"socket.io-client": "^4.5.4"
|
|
33
|
+
},
|
|
34
|
+
"directories": {
|
|
35
|
+
"test": "test"
|
|
36
|
+
}
|
|
37
|
+
}
|