justrun-ws 0.1.3 → 0.2.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/lib/WsClient.js +211 -0
- package/lib/bundle.min.js +1 -1
- package/lib/common/AdjustableTimer.js +42 -0
- package/lib/common/DataWrapper.js +14 -16
- package/lib/common/List.js +21 -21
- package/lib/common/utils.js +20 -20
- package/lib/common/varUintOps.js +51 -51
- package/lib/handler/SimpleHandler.js +49 -47
- package/lib/handler/common.js +2 -3
- package/lib/index.d.ts +60 -142
- package/lib/index.js +2 -5
- package/lib/net/BrowserWsNet.js +51 -47
- package/lib/net/LazyConn.js +42 -31
- package/lib/net/NetErrorString.js +14 -0
- package/lib/net/PackageWrapper.js +16 -16
- package/lib/net/TimeoutMonitor.js +39 -39
- package/lib/net/TypedPkgHub.js +173 -175
- package/lib/net/hubPkgSerializer.js +2 -2
- package/package.json +1 -1
|
@@ -1,88 +1,90 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { NetErrorString } from '../net/NetErrorString';
|
|
2
|
+
import { b } from './common';
|
|
3
|
+
const c = new Error(NetErrorString.g);
|
|
4
|
+
export class n {
|
|
3
5
|
constructor(wrapperCtor, d, e = true) {
|
|
4
|
-
this.
|
|
5
|
-
this.
|
|
6
|
-
this.
|
|
6
|
+
this.l = wrapperCtor;
|
|
7
|
+
this.v = d;
|
|
8
|
+
this.w = e;
|
|
7
9
|
}
|
|
8
10
|
get pkgType() {
|
|
9
|
-
return this.
|
|
11
|
+
return this.l.pkgType;
|
|
10
12
|
}
|
|
11
|
-
get
|
|
12
|
-
return this.
|
|
13
|
+
get m() {
|
|
14
|
+
return this.l.name;
|
|
13
15
|
}
|
|
14
|
-
async
|
|
15
|
-
const { buff, bodyOffset } =
|
|
16
|
-
const
|
|
17
|
-
const message = new this.
|
|
18
|
-
if (conn.context !== undefined || !this.
|
|
16
|
+
async $(conn, a) {
|
|
17
|
+
const { buff, bodyOffset } = a;
|
|
18
|
+
const h = buff.subarray(bodyOffset);
|
|
19
|
+
const message = new this.l(h, true);
|
|
20
|
+
if (conn.context !== undefined || !this.w) {
|
|
19
21
|
try {
|
|
20
|
-
await this.
|
|
22
|
+
await this.v(conn, message);
|
|
21
23
|
}
|
|
22
24
|
catch (err) {
|
|
23
25
|
if (!err.isError) {
|
|
24
|
-
|
|
26
|
+
b(conn, err);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
else {
|
|
29
|
-
|
|
31
|
+
b(conn, c);
|
|
30
32
|
}
|
|
31
33
|
if (conn.context === undefined) {
|
|
32
34
|
await conn.close();
|
|
33
35
|
}
|
|
34
36
|
}
|
|
35
|
-
async
|
|
36
|
-
if (conn.context !== undefined || !this.
|
|
37
|
+
async r(conn, message) {
|
|
38
|
+
if (conn.context !== undefined || !this.w) {
|
|
37
39
|
try {
|
|
38
|
-
return await this.
|
|
40
|
+
return await this.v(conn, message);
|
|
39
41
|
}
|
|
40
42
|
catch (err) {
|
|
41
43
|
if (!err.isError) {
|
|
42
|
-
|
|
44
|
+
b(conn, err);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
48
|
else {
|
|
47
|
-
|
|
49
|
+
b(conn, c);
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
52
|
+
l;
|
|
53
|
+
v;
|
|
54
|
+
w;
|
|
53
55
|
}
|
|
54
|
-
export class
|
|
56
|
+
export class o {
|
|
55
57
|
constructor(wrapperCtor, d, e = true) {
|
|
56
|
-
this.
|
|
57
|
-
this.
|
|
58
|
-
this.
|
|
58
|
+
this.l = wrapperCtor;
|
|
59
|
+
this.v = d;
|
|
60
|
+
this.w = e;
|
|
59
61
|
}
|
|
60
62
|
get pkgType() {
|
|
61
|
-
return this.
|
|
63
|
+
return this.l.pkgType;
|
|
62
64
|
}
|
|
63
|
-
get
|
|
64
|
-
return this.
|
|
65
|
+
get m() {
|
|
66
|
+
return this.l.name;
|
|
65
67
|
}
|
|
66
|
-
async
|
|
67
|
-
const { buff, requestId, bodyOffset } =
|
|
68
|
-
const
|
|
69
|
-
const request = new this.
|
|
68
|
+
async $(conn, a) {
|
|
69
|
+
const { buff, requestId, bodyOffset } = a;
|
|
70
|
+
const h = buff.subarray(bodyOffset);
|
|
71
|
+
const request = new this.l(h, true);
|
|
70
72
|
let error;
|
|
71
|
-
if (conn.context !== undefined || !this.
|
|
73
|
+
if (conn.context !== undefined || !this.w) {
|
|
72
74
|
try {
|
|
73
|
-
await this.
|
|
75
|
+
await this.v(conn, request);
|
|
74
76
|
}
|
|
75
77
|
catch (err) {
|
|
76
78
|
if (err.isError) {
|
|
77
79
|
error = err;
|
|
78
80
|
}
|
|
79
81
|
else {
|
|
80
|
-
error =
|
|
82
|
+
error = b(conn, err);
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
else {
|
|
85
|
-
error =
|
|
87
|
+
error = b(conn, c);
|
|
86
88
|
}
|
|
87
89
|
try {
|
|
88
90
|
if (!error) {
|
|
@@ -99,24 +101,24 @@ export class h {
|
|
|
99
101
|
await conn.close(err);
|
|
100
102
|
}
|
|
101
103
|
}
|
|
102
|
-
async
|
|
103
|
-
if (conn.context !== undefined || !this.
|
|
104
|
+
async r(conn, request) {
|
|
105
|
+
if (conn.context !== undefined || !this.w) {
|
|
104
106
|
try {
|
|
105
|
-
return await this.
|
|
107
|
+
return await this.v(conn, request);
|
|
106
108
|
}
|
|
107
109
|
catch (err) {
|
|
108
110
|
if (err.isError) {
|
|
109
111
|
throw err;
|
|
110
112
|
}
|
|
111
113
|
else {
|
|
112
|
-
throw
|
|
114
|
+
throw b(conn, err);
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
}
|
|
116
|
-
throw
|
|
118
|
+
throw b(conn, c);
|
|
117
119
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
120
|
+
l;
|
|
121
|
+
v;
|
|
122
|
+
w;
|
|
121
123
|
}
|
|
122
124
|
//# sourceMappingURL=SimpleHandler.js.map
|
package/lib/handler/common.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { JsonError } from '../net/JsonPackageWrapper';
|
|
2
2
|
export class CommonError extends JsonError {
|
|
3
3
|
}
|
|
4
|
-
export
|
|
5
|
-
export let a = (b, err) => {
|
|
4
|
+
export let b = (a, err) => {
|
|
6
5
|
return new CommonError(err.message);
|
|
7
6
|
};
|
|
8
7
|
export const handleUncaughtErrorWith = (handler) => {
|
|
9
|
-
|
|
8
|
+
b = handler;
|
|
10
9
|
};
|
|
11
10
|
//# sourceMappingURL=common.js.map
|
package/lib/index.d.ts
CHANGED
|
@@ -43,34 +43,6 @@ export declare abstract class RequestWrapper<RequestT, ResponseT> extends PkgWra
|
|
|
43
43
|
export type ErrorWrapperCtor<ErrorT, WrapperT extends ErrorWrapper<ErrorT> = ErrorWrapper<ErrorT>> = new (error: ErrorT | Uint8Array, needParse?: true) => WrapperT;
|
|
44
44
|
export type MessageWrapperCtor<MessageT, WrapperT extends MessageWrapper<MessageT> = MessageWrapper<MessageT>> = new (message: MessageT | Uint8Array, needParse?: true) => WrapperT;
|
|
45
45
|
export type RequestWrapperCtor<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT> = RequestWrapper<RequestT, ResponseT>> = new (request: RequestT | Uint8Array, needParse?: true, _response?: ResponseT) => WrapperT;
|
|
46
|
-
export interface AddressInfo {
|
|
47
|
-
address: string;
|
|
48
|
-
family: string;
|
|
49
|
-
port: number;
|
|
50
|
-
}
|
|
51
|
-
export interface IRawPkgConn {
|
|
52
|
-
readonly localAddress?: string;
|
|
53
|
-
readonly localPort?: number;
|
|
54
|
-
readonly remoteAddress?: string;
|
|
55
|
-
readonly remoteFamily?: string;
|
|
56
|
-
readonly remotePort?: number;
|
|
57
|
-
sendPkgBuff(buff: Uint8Array): Promise<void>;
|
|
58
|
-
sendPkgBuffV(buffVector: Uint8Array[]): Promise<void>;
|
|
59
|
-
close(err?: Error): Promise<void>;
|
|
60
|
-
hadClosed(): boolean;
|
|
61
|
-
}
|
|
62
|
-
export interface IPkgConnWrapper<ConnWrapperT> {
|
|
63
|
-
readonly conn: ConnWrapperT;
|
|
64
|
-
onPkgBuff: (buff: Uint8Array) => void;
|
|
65
|
-
onClose: (err?: Error) => void;
|
|
66
|
-
}
|
|
67
|
-
export interface INet<ConnWrapperT> {
|
|
68
|
-
address(): AddressInfo | null;
|
|
69
|
-
setConnWrapperMaker(makeWrapper: (conn: IRawPkgConn, isActive?: boolean) => IPkgConnWrapper<ConnWrapperT>): void;
|
|
70
|
-
startListen(connStr?: string): Promise<boolean>;
|
|
71
|
-
stopListen(): Promise<boolean>;
|
|
72
|
-
connect(connStr: string): Promise<ConnWrapperT>;
|
|
73
|
-
}
|
|
74
46
|
export interface IConn<ConnContextT = void> {
|
|
75
47
|
context?: ConnContextT | undefined;
|
|
76
48
|
readonly id: number;
|
|
@@ -85,97 +57,12 @@ export interface IConn<ConnContextT = void> {
|
|
|
85
57
|
sendResponse<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>, requestId: number): Promise<void>;
|
|
86
58
|
close(err?: Error): Promise<void>;
|
|
87
59
|
}
|
|
88
|
-
export interface IPkgHub<ConnContextT = void, HubContextT = void> {
|
|
89
|
-
context?: HubContextT | undefined;
|
|
90
|
-
address(): AddressInfo | null;
|
|
91
|
-
getConn(connId: number): IConn<ConnContextT> | undefined;
|
|
92
|
-
connect(connStr: string): Promise<IConn<ConnContextT>>;
|
|
93
|
-
connectLocal(): Promise<IConn<ConnContextT>>;
|
|
94
|
-
startServer(connStr?: string): Promise<boolean>;
|
|
95
|
-
stopServer(): Promise<boolean>;
|
|
96
|
-
}
|
|
97
60
|
export type ParseResult<PkgTypeT extends number | string> = {
|
|
98
61
|
buff: Uint8Array;
|
|
99
62
|
pkgType: PkgTypeT;
|
|
100
63
|
requestId: number;
|
|
101
64
|
bodyOffset: number;
|
|
102
65
|
};
|
|
103
|
-
export interface IPkgHandler<PkgTypeT extends number | string, ConnContextT = void> {
|
|
104
|
-
get pkgType(): PkgTypeT;
|
|
105
|
-
get pkgName(): string;
|
|
106
|
-
run(conn: IConn<ConnContextT>, parseResult: ParseResult<PkgTypeT>): void | Promise<void>;
|
|
107
|
-
}
|
|
108
|
-
export interface IMessageHandler<PkgTypeT extends number | string, MessageT, WrapperT extends MessageWrapper<MessageT>, ConnContextT = void> extends IPkgHandler<PkgTypeT, ConnContextT> {
|
|
109
|
-
runLocal(conn: IConn<ConnContextT>, message: WrapperT): void | Promise<void>;
|
|
110
|
-
}
|
|
111
|
-
export interface IRequestHandler<PkgTypeT extends number | string, RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>, ConnContextT = void> extends IPkgHandler<PkgTypeT, ConnContextT> {
|
|
112
|
-
runLocal(conn: IConn<ConnContextT>, request: WrapperT): void | Promise<void>;
|
|
113
|
-
}
|
|
114
|
-
export declare abstract class JsonError<ErrorT> extends ErrorWrapper<ErrorT> {
|
|
115
|
-
protected encode(data: ErrorT): Uint8Array;
|
|
116
|
-
protected decode(buffer: Uint8Array): ErrorT;
|
|
117
|
-
}
|
|
118
|
-
export declare abstract class JsonMessage<MessageT> extends MessageWrapper<MessageT> {
|
|
119
|
-
protected encode(data: MessageT): Uint8Array;
|
|
120
|
-
protected decode(buffer: Uint8Array): MessageT;
|
|
121
|
-
}
|
|
122
|
-
export declare abstract class JsonRequest<RequestT, ResponseT> extends RequestWrapper<RequestT, ResponseT> {
|
|
123
|
-
protected encode(data: RequestT): Uint8Array;
|
|
124
|
-
protected decode(buffer: Uint8Array): RequestT;
|
|
125
|
-
protected encodeResponse(response: ResponseT): Uint8Array;
|
|
126
|
-
protected decodeResponse(buffer: Uint8Array): ResponseT;
|
|
127
|
-
}
|
|
128
|
-
export declare class CommonError extends JsonError<string> {
|
|
129
|
-
}
|
|
130
|
-
export interface DoneResp<ResultT extends string | number | boolean = boolean> {
|
|
131
|
-
result: ResultT;
|
|
132
|
-
}
|
|
133
|
-
export interface ClientPkg {
|
|
134
|
-
cid: string;
|
|
135
|
-
}
|
|
136
|
-
export declare const handleUncaughtErrorWith: (handler: (conn: IConn<unknown>, err: Error) => ErrorWrapper<unknown>) => void;
|
|
137
|
-
export type HandleFunc<WrapperT, ConnContextT> = (conn: IConn<ConnContextT>, wrapper: WrapperT) => void | Promise<void>;
|
|
138
|
-
export declare class SimpleMessageHandler<PkgTypeT extends number | string, MessageT, WrapperT extends MessageWrapper<MessageT>, ConnContextT> implements IMessageHandler<PkgTypeT, MessageT, WrapperT, ConnContextT> {
|
|
139
|
-
constructor(wrapperCtor: MessageWrapperCtor<MessageT, WrapperT>, handleFunc: HandleFunc<WrapperT, ConnContextT>, checkContext?: boolean);
|
|
140
|
-
get pkgType(): PkgTypeT;
|
|
141
|
-
get pkgName(): string;
|
|
142
|
-
run(conn: IConn<ConnContextT>, parseResult: ParseResult<PkgTypeT>): Promise<void>;
|
|
143
|
-
runLocal(conn: IConn<ConnContextT>, message: WrapperT): Promise<void>;
|
|
144
|
-
private _wrapperCtor;
|
|
145
|
-
private _handleFunc;
|
|
146
|
-
private _checkContext;
|
|
147
|
-
}
|
|
148
|
-
export declare class BrowserWsNet<ConnWrapperT> implements INet<ConnWrapperT> {
|
|
149
|
-
address(): AddressInfo | null;
|
|
150
|
-
setConnWrapperMaker(makeWrapper: (conn: IRawPkgConn, isActive?: boolean) => IPkgConnWrapper<ConnWrapperT>): void;
|
|
151
|
-
startListen(_connStr?: string): Promise<boolean>;
|
|
152
|
-
stopListen(): Promise<boolean>;
|
|
153
|
-
connect(connStr: string): Promise<ConnWrapperT>;
|
|
154
|
-
private setupConn;
|
|
155
|
-
private makeWrapper;
|
|
156
|
-
}
|
|
157
|
-
export declare const makeNumTypePkgBuff: (pkgType: number, requestId: number, encoded: Uint8Array[]) => void;
|
|
158
|
-
export declare const parseNumTypePkgBuff: (buff: Uint8Array) => ParseResult<number>;
|
|
159
|
-
export declare class LazyConn<ConnContextT> implements IConn<ConnContextT> {
|
|
160
|
-
constructor(connectFunc: () => Promise<IConn<ConnContextT> | undefined>);
|
|
161
|
-
get id(): number;
|
|
162
|
-
get context(): ConnContextT | undefined;
|
|
163
|
-
set context(val: ConnContextT | undefined);
|
|
164
|
-
localAddress?: string | undefined;
|
|
165
|
-
localPort?: number | undefined;
|
|
166
|
-
remoteAddress?: string | undefined;
|
|
167
|
-
remoteFamily?: string | undefined;
|
|
168
|
-
remotePort?: number | undefined;
|
|
169
|
-
sendErrorResponse<ErrorT>(error: ErrorWrapper<ErrorT>, requestId: number): Promise<void>;
|
|
170
|
-
sendResponse<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>, requestId: number): Promise<void>;
|
|
171
|
-
sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
|
|
172
|
-
sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<void>;
|
|
173
|
-
close(err?: Error): Promise<void>;
|
|
174
|
-
private connect;
|
|
175
|
-
private _connectFunc;
|
|
176
|
-
private _conn?;
|
|
177
|
-
private _waitingConn?;
|
|
178
|
-
}
|
|
179
66
|
declare class ListNode {
|
|
180
67
|
constructor();
|
|
181
68
|
getPrev<SelfT extends ListNode>(this: SelfT): SelfT;
|
|
@@ -210,38 +97,69 @@ export type TypedPkgHubOpts<PkgTypeT extends number | string> = {
|
|
|
210
97
|
makePkgBuff: (pkgType: PkgTypeT, requestId: number, encoded: Uint8Array[]) => void;
|
|
211
98
|
parsePkgBuff: (buff: Uint8Array) => ParseResult<PkgTypeT>;
|
|
212
99
|
};
|
|
213
|
-
export declare class
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
100
|
+
export declare abstract class JsonError<ErrorT> extends ErrorWrapper<ErrorT> {
|
|
101
|
+
protected encode(data: ErrorT): Uint8Array;
|
|
102
|
+
protected decode(buffer: Uint8Array): ErrorT;
|
|
103
|
+
}
|
|
104
|
+
export declare abstract class JsonMessage<MessageT> extends MessageWrapper<MessageT> {
|
|
105
|
+
protected encode(data: MessageT): Uint8Array;
|
|
106
|
+
protected decode(buffer: Uint8Array): MessageT;
|
|
107
|
+
}
|
|
108
|
+
export declare abstract class JsonRequest<RequestT, ResponseT> extends RequestWrapper<RequestT, ResponseT> {
|
|
109
|
+
protected encode(data: RequestT): Uint8Array;
|
|
110
|
+
protected decode(buffer: Uint8Array): RequestT;
|
|
111
|
+
protected encodeResponse(response: ResponseT): Uint8Array;
|
|
112
|
+
protected decodeResponse(buffer: Uint8Array): ResponseT;
|
|
113
|
+
}
|
|
114
|
+
export declare class CommonError extends JsonError<string> {
|
|
115
|
+
}
|
|
116
|
+
export interface DoneResp<ResultT extends string | number | boolean = boolean> {
|
|
117
|
+
result: ResultT;
|
|
118
|
+
}
|
|
119
|
+
export interface IAuthResp {
|
|
120
|
+
cid: string;
|
|
121
|
+
token: string;
|
|
122
|
+
shard?: number;
|
|
123
|
+
}
|
|
124
|
+
export declare const handleUncaughtErrorWith: (handler: (conn: IConn<unknown>, err: Error) => ErrorWrapper<unknown>) => void;
|
|
125
|
+
export declare enum NetErrorString {
|
|
126
|
+
AuthTimeout = "AuthTimeout",
|
|
127
|
+
BadRequest = "BadRequest",
|
|
128
|
+
ConnectFailed = "ConnectFailed",
|
|
129
|
+
ConnectionClosed = "ConnectionClosed",
|
|
130
|
+
InvalidConnString = "InvalidConnString",
|
|
131
|
+
InvalidConnection = "InvalidConnection",
|
|
132
|
+
InvalidPackage = "InvalidPackage",
|
|
133
|
+
NotAuthenticated = "NotAuthenticated",
|
|
134
|
+
Timeout = "Timeout",
|
|
135
|
+
UnknownError = "UnknownError"
|
|
136
|
+
}
|
|
137
|
+
export declare const createNumPkgTypeClient: (getConnStr: (shard?: number) => string, timeoutMonitor?: TimeoutMonitor) => WsClient<number>;
|
|
138
|
+
export declare class WsClient<PkgTypeT extends number | string> {
|
|
139
|
+
constructor(getConnStr: (shard?: number) => string, opts: TypedPkgHubOpts<PkgTypeT>);
|
|
227
140
|
registerError<ErrorT>(pkgType: PkgTypeT, wrapperCtor: ErrorWrapperCtor<ErrorT>): void;
|
|
228
141
|
registerMessage<MessageT>(pkgType: PkgTypeT, wrapperCtor: MessageWrapperCtor<MessageT>): void;
|
|
229
142
|
registerRequest<RequestT, ResponseT>(pkgType: PkgTypeT, wrapperCtor: RequestWrapperCtor<RequestT, ResponseT>): void;
|
|
230
|
-
handleMessageWith<MessageT, WrapperT extends MessageWrapper<MessageT>>(
|
|
231
|
-
handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
private
|
|
240
|
-
private
|
|
241
|
-
private
|
|
242
|
-
private
|
|
243
|
-
private
|
|
244
|
-
private
|
|
143
|
+
handleMessageWith<MessageT, WrapperT extends MessageWrapper<MessageT>>(wrapperCtor: MessageWrapperCtor<MessageT, WrapperT>, handler: (message: MessageT) => void | Promise<void>): void;
|
|
144
|
+
handleRequestWith<RequestT, ResponseT, WrapperT extends RequestWrapper<RequestT, ResponseT>>(wrapperCtor: RequestWrapperCtor<RequestT, ResponseT, WrapperT>, handler: (request: RequestT) => ResponseT | Promise<ResponseT>): void;
|
|
145
|
+
sendMessage<MessageT>(message: MessageWrapper<MessageT>): Promise<void>;
|
|
146
|
+
sendRequest<RequestT, ResponseT>(request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
|
|
147
|
+
sendCustomAuthRequest<RequestT, ResponseT extends IAuthResp>(_request: RequestWrapper<RequestT, ResponseT>): Promise<ResponseT>;
|
|
148
|
+
resetAuthState(): void;
|
|
149
|
+
enableAuthenticate(proxyAuthPkgType: PkgTypeT, authStatusCallback: (cid: string) => void, allowAnonymous?: true): void;
|
|
150
|
+
reconnect(delay?: number): void;
|
|
151
|
+
onConnectionStatus(listener: (isOpen: boolean, active: boolean, err?: Error) => void): void;
|
|
152
|
+
private connect;
|
|
153
|
+
private onConnOpen;
|
|
154
|
+
private onConnClose;
|
|
155
|
+
private _pkgHub;
|
|
156
|
+
private _conn;
|
|
157
|
+
private _cid;
|
|
158
|
+
private _connState;
|
|
159
|
+
private _getConnStr;
|
|
160
|
+
private _originConnect;
|
|
161
|
+
private _connectDelay?;
|
|
162
|
+
private _listenerArr?;
|
|
245
163
|
}
|
|
246
164
|
|
|
247
165
|
export {};
|
package/lib/index.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
export { CommonError, handleUncaughtErrorWith } from './handler/common';
|
|
2
|
-
export { SimpleMessageHandler } from './handler/SimpleHandler';
|
|
3
|
-
export { BrowserWsNet } from './net/BrowserWsNet';
|
|
4
|
-
export { makeNumTypePkgBuff, parseNumTypePkgBuff } from './net/hubPkgSerializer';
|
|
5
2
|
export { JsonError, JsonMessage, JsonRequest } from './net/JsonPackageWrapper';
|
|
6
|
-
export {
|
|
3
|
+
export { NetErrorString } from './net/NetErrorString';
|
|
7
4
|
export { ErrorWrapper, EventWrapper, MessageWrapper, RequestWrapper } from './net/PackageWrapper';
|
|
8
5
|
export { TimeoutMonitor } from './net/TimeoutMonitor';
|
|
9
|
-
export {
|
|
6
|
+
export { createNumPkgTypeClient, WsClient } from './WsClient';
|
|
10
7
|
//# sourceMappingURL=index.js.map
|
package/lib/net/BrowserWsNet.js
CHANGED
|
@@ -1,53 +1,57 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { y } from '../common/utils';
|
|
2
|
+
import { NetErrorString } from './NetErrorString';
|
|
3
|
+
export class r {
|
|
4
|
+
o() {
|
|
4
5
|
return null;
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
this.
|
|
7
|
+
P(D) {
|
|
8
|
+
this.D = D;
|
|
8
9
|
}
|
|
9
|
-
async
|
|
10
|
+
async Q(t) {
|
|
10
11
|
return false;
|
|
11
12
|
}
|
|
12
|
-
async
|
|
13
|
+
async R() {
|
|
13
14
|
return false;
|
|
14
15
|
}
|
|
15
|
-
async
|
|
16
|
-
const
|
|
17
|
-
return new Promise((
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
async c(e) {
|
|
17
|
+
const f = new WebSocket(e);
|
|
18
|
+
return new Promise((d, i) => {
|
|
19
|
+
f.onerror = (k) => {
|
|
20
|
+
i(new Error(NetErrorString.m));
|
|
20
21
|
};
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
f.onopen = () => {
|
|
23
|
+
d(this.a4(f, true));
|
|
23
24
|
};
|
|
24
25
|
});
|
|
25
26
|
}
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const { conn,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
a4 = (f, q) => {
|
|
28
|
+
const b = new s(f);
|
|
29
|
+
const { conn, E, n } = this.D(b, q);
|
|
30
|
+
f.onmessage = (j) => {
|
|
31
|
+
j.data.arrayBuffer().then((buff) => {
|
|
32
|
+
E(new Uint8Array(buff));
|
|
32
33
|
});
|
|
33
34
|
};
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
f.onerror = (k) => {
|
|
36
|
+
n(new Error(NetErrorString.m));
|
|
36
37
|
};
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
38
|
+
f.onclose = (j) => {
|
|
39
|
+
if (j.code === 1000) {
|
|
40
|
+
n();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
n(new Error(j.reason));
|
|
40
44
|
}
|
|
41
45
|
};
|
|
42
46
|
return conn;
|
|
43
47
|
};
|
|
44
|
-
|
|
48
|
+
D(a, u) {
|
|
45
49
|
throw new Error('Need to call "setConnWrapperMaker" before using');
|
|
46
50
|
}
|
|
47
51
|
}
|
|
48
|
-
class
|
|
49
|
-
constructor(
|
|
50
|
-
this.
|
|
52
|
+
class s {
|
|
53
|
+
constructor(f) {
|
|
54
|
+
this.g = f;
|
|
51
55
|
}
|
|
52
56
|
get localAddress() {
|
|
53
57
|
return;
|
|
@@ -64,36 +68,36 @@ class i {
|
|
|
64
68
|
get remotePort() {
|
|
65
69
|
return;
|
|
66
70
|
}
|
|
67
|
-
async
|
|
68
|
-
if (this.
|
|
69
|
-
return this.
|
|
71
|
+
async N(buff) {
|
|
72
|
+
if (this.g) {
|
|
73
|
+
return this.g.send(buff);
|
|
70
74
|
}
|
|
71
|
-
throw new Error(
|
|
75
|
+
throw new Error(NetErrorString.l);
|
|
72
76
|
}
|
|
73
|
-
async
|
|
74
|
-
if (this.
|
|
75
|
-
const buff =
|
|
76
|
-
return this.
|
|
77
|
+
async p(h) {
|
|
78
|
+
if (this.g) {
|
|
79
|
+
const buff = y(h);
|
|
80
|
+
return this.g.send(buff);
|
|
77
81
|
}
|
|
78
|
-
throw new Error(
|
|
82
|
+
throw new Error(NetErrorString.l);
|
|
79
83
|
}
|
|
80
84
|
async close(err) {
|
|
81
|
-
const {
|
|
82
|
-
if (
|
|
83
|
-
this.
|
|
85
|
+
const { g } = this;
|
|
86
|
+
if (g) {
|
|
87
|
+
this.g = undefined;
|
|
84
88
|
if (!err) {
|
|
85
|
-
if (
|
|
86
|
-
|
|
89
|
+
if (g.readyState === WebSocket.OPEN) {
|
|
90
|
+
g.close(1000);
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
93
|
else {
|
|
90
|
-
|
|
94
|
+
g.close(3000, err.message);
|
|
91
95
|
}
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
|
-
|
|
95
|
-
return !this.
|
|
98
|
+
O() {
|
|
99
|
+
return !this.g;
|
|
96
100
|
}
|
|
97
|
-
|
|
101
|
+
g;
|
|
98
102
|
}
|
|
99
103
|
//# sourceMappingURL=BrowserWsNet.js.map
|