egos-transfer 0.0.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/.lintstagedrc.json +3 -0
- package/.prettierrc +7 -0
- package/.watchmanconfig +6 -0
- package/README.md +343 -0
- package/dist/constant.d.ts +13 -0
- package/dist/constant.js +16 -0
- package/dist/entity.d.ts +159 -0
- package/dist/entity.js +164 -0
- package/dist/file-transfer.d.ts +81 -0
- package/dist/file-transfer.js +476 -0
- package/dist/handler.d.ts +42 -0
- package/dist/handler.js +369 -0
- package/dist/helper.d.ts +2 -0
- package/dist/helper.js +12 -0
- package/dist/http-transfer.d.ts +46 -0
- package/dist/http-transfer.js +243 -0
- package/dist/http-transformer.d.ts +3 -0
- package/dist/http-transformer.js +20 -0
- package/dist/index.d.ts +95 -0
- package/dist/index.js +665 -0
- package/dist/interfaces.d.ts +362 -0
- package/dist/interfaces.js +2 -0
- package/dist/locker.d.ts +115 -0
- package/dist/locker.js +245 -0
- package/dist/router.d.ts +62 -0
- package/dist/router.js +191 -0
- package/dist/server.d.ts +29 -0
- package/dist/server.js +77 -0
- package/dist/utils.d.ts +92 -0
- package/dist/utils.js +333 -0
- package/package.json +42 -0
- package/src/constant.ts +14 -0
- package/src/entity.ts +201 -0
- package/src/file-transfer.ts +517 -0
- package/src/handler.ts +413 -0
- package/src/helper.ts +8 -0
- package/src/http-transfer.ts +261 -0
- package/src/http-transformer.ts +20 -0
- package/src/index.ts +732 -0
- package/src/interfaces.ts +420 -0
- package/src/locker.ts +322 -0
- package/src/router.ts +243 -0
- package/src/server.ts +83 -0
- package/src/utils.ts +386 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertToHttp = void 0;
|
|
4
|
+
const convertToHttp = (peerId, payload) => {
|
|
5
|
+
const headers = payload.headers || {};
|
|
6
|
+
headers['x-peer-id'] = peerId;
|
|
7
|
+
headers['x-request-id'] = payload.requestId;
|
|
8
|
+
headers['x-message-id'] = payload.id;
|
|
9
|
+
const url = payload.route;
|
|
10
|
+
const params = payload.method.toLocaleLowerCase() === 'get' ? payload.body : null;
|
|
11
|
+
return {
|
|
12
|
+
url: url,
|
|
13
|
+
method: payload.method,
|
|
14
|
+
headers,
|
|
15
|
+
data: payload.body,
|
|
16
|
+
params,
|
|
17
|
+
timeout: payload.timeout,
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
exports.convertToHttp = convertToHttp;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { DataConnection, Peer, PeerOptions } from 'peerjs';
|
|
2
|
+
import { IDeviceStatus, IMessage, PeerMessage, PeerRequestPayload, RequestCallbackFn, RouteItem } from './interfaces';
|
|
3
|
+
import { InternalApi, PeerAction } from './entity';
|
|
4
|
+
import { PeerRouter } from './router';
|
|
5
|
+
export interface ContentPayload {
|
|
6
|
+
file: string;
|
|
7
|
+
parent: string;
|
|
8
|
+
}
|
|
9
|
+
type ResponseCb<T = any> = (args: T) => void;
|
|
10
|
+
export declare abstract class PeerTransfer {
|
|
11
|
+
protected peer: Peer | undefined;
|
|
12
|
+
protected peerPool: Map<string, Peer>;
|
|
13
|
+
protected peerIdMap: Map<string, string>;
|
|
14
|
+
protected connectPool: Map<string, DataConnection>;
|
|
15
|
+
static connecting: Map<string, {
|
|
16
|
+
promise: Promise<any>;
|
|
17
|
+
resolve: (value: any | PromiseLike<any>) => void;
|
|
18
|
+
reject: (reason?: any) => void;
|
|
19
|
+
}>;
|
|
20
|
+
protected retry: number;
|
|
21
|
+
protected peerConfig: PeerOptions | undefined;
|
|
22
|
+
deviceId: string;
|
|
23
|
+
protected requests: Map<string, ResponseCb>;
|
|
24
|
+
protected timeout: number;
|
|
25
|
+
protected router: PeerRouter;
|
|
26
|
+
protected booted: Promise<string> | undefined;
|
|
27
|
+
protected reconnectingPromise: Promise<Peer | undefined> | undefined;
|
|
28
|
+
protected timeoutId: ReturnType<typeof setTimeout>;
|
|
29
|
+
protected checkerId: ReturnType<typeof setInterval>;
|
|
30
|
+
isPaused: boolean;
|
|
31
|
+
peerId: string;
|
|
32
|
+
constructor(deviceId: string, config: PeerOptions, isRadomPeerId?: boolean);
|
|
33
|
+
abstract getStore(): any;
|
|
34
|
+
abstract online(deviceId: string): void;
|
|
35
|
+
abstract offline(deviceId: string): void;
|
|
36
|
+
abstract genRequestId(): Promise<string>;
|
|
37
|
+
abstract getApi(deviceId: string): Promise<InternalApi | undefined>;
|
|
38
|
+
abstract discoverDeviceById(deviceId: string): Promise<void>;
|
|
39
|
+
abstract onDestroy(): void;
|
|
40
|
+
abstract requireAuth(): void;
|
|
41
|
+
abstract onConnectLimit(): void;
|
|
42
|
+
initialize(peer: Peer): Promise<string>;
|
|
43
|
+
handleSocketMessage(message: IMessage): void;
|
|
44
|
+
onHeartbeat(message: IMessage): void;
|
|
45
|
+
onError(message: IMessage): void;
|
|
46
|
+
onOpen(message: IMessage): void;
|
|
47
|
+
onDeviceOnline(message: IMessage): Promise<void>;
|
|
48
|
+
onDeviceOffline(message: IMessage): void;
|
|
49
|
+
removeConnection(peerId: string): void;
|
|
50
|
+
addConnection(conn: DataConnection): void;
|
|
51
|
+
checkConnection(): void;
|
|
52
|
+
getApiHost(): string;
|
|
53
|
+
getDeviceStatus(peerId: string): Promise<IDeviceStatus | undefined>;
|
|
54
|
+
connectToPeer(deviceId: string): Promise<DataConnection | undefined>;
|
|
55
|
+
ping(peerId: string): Promise<boolean>;
|
|
56
|
+
onConnect(conn: DataConnection, positive?: boolean): Promise<DataConnection | undefined>;
|
|
57
|
+
request(peerId: string, payload: PeerRequestPayload): Promise<PeerMessage>;
|
|
58
|
+
reply(conn: DataConnection, oldMessage: PeerMessage, message: {
|
|
59
|
+
body?: Record<string, any>;
|
|
60
|
+
headers?: Record<string, string | number>;
|
|
61
|
+
error?: string | Record<string, any>;
|
|
62
|
+
}): Promise<void>;
|
|
63
|
+
send(conn: DataConnection, message: PeerRequestPayload): Promise<void>;
|
|
64
|
+
inheritMessage(receiveMsg: PeerMessage): {
|
|
65
|
+
src: string;
|
|
66
|
+
id: string;
|
|
67
|
+
requestId: string;
|
|
68
|
+
route: string;
|
|
69
|
+
createdAt: string | number;
|
|
70
|
+
action: PeerAction;
|
|
71
|
+
};
|
|
72
|
+
reconnect(): Promise<Peer | undefined>;
|
|
73
|
+
private doReconnect;
|
|
74
|
+
createPeer(force?: boolean): Promise<Peer | undefined>;
|
|
75
|
+
clearInstance(): void;
|
|
76
|
+
destroy(): void;
|
|
77
|
+
onRequest(conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
78
|
+
onResponse(conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
79
|
+
responseOk(conn: DataConnection, message: PeerMessage): Promise<void>;
|
|
80
|
+
responseFail(conn: DataConnection, message: PeerMessage, err: string | Record<string, any>): Promise<void>;
|
|
81
|
+
addRequest(id: string, cb: ResponseCb): void;
|
|
82
|
+
use(handler: RequestCallbackFn, prefix?: string): void;
|
|
83
|
+
addRoute(route: Omit<RouteItem, 'scope'>): void;
|
|
84
|
+
stop(): void;
|
|
85
|
+
resume(): Promise<Peer>;
|
|
86
|
+
}
|
|
87
|
+
export * from './interfaces';
|
|
88
|
+
export * from './handler';
|
|
89
|
+
export * from './file-transfer';
|
|
90
|
+
export * from './server';
|
|
91
|
+
export * from './utils';
|
|
92
|
+
export * from './locker';
|
|
93
|
+
export * from './entity';
|
|
94
|
+
export * from './http-transformer';
|
|
95
|
+
export * from './http-transfer';
|