mcbe-ipc 2.0.1 → 3.0.0
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/README.md +1 -71
- package/dist/ipc.d.ts +85 -36
- package/dist/ipc.js +775 -328
- package/dist/ipc.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,74 +17,4 @@ An IPC[^1] system for MCBE Script API projects
|
|
|
17
17
|
|
|
18
18
|
**TypeScript**
|
|
19
19
|
1. Download `ipc.ts` from the latest [release](https://github.com/OmniacDev/MCBE-IPC/releases/latest)
|
|
20
|
-
2. Copy file into your project
|
|
21
|
-
|
|
22
|
-
## Usage
|
|
23
|
-
|
|
24
|
-
### Sending & Receiving
|
|
25
|
-
|
|
26
|
-
`IPC.send()` and `IPC.on()` can be used to send messages or data between packs.
|
|
27
|
-
|
|
28
|
-
_Pack 1_
|
|
29
|
-
```js
|
|
30
|
-
import IPC from 'ipc.js'
|
|
31
|
-
|
|
32
|
-
IPC.on('message_channel', (args) => {
|
|
33
|
-
console.log(`Message: ${args}`)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
IPC.on('data_channel', (args) => {
|
|
37
|
-
console.log(`Data: ${args.example_bool}, ${args.example_number}`)
|
|
38
|
-
})
|
|
39
|
-
```
|
|
40
|
-
_Pack 2_
|
|
41
|
-
```js
|
|
42
|
-
import IPC from 'ipc.js'
|
|
43
|
-
|
|
44
|
-
IPC.send('message_channel', 'Example Message')
|
|
45
|
-
|
|
46
|
-
IPC.send('data_channel', { example_number: 100, example_bool: true })
|
|
47
|
-
```
|
|
48
|
-
_Console Output_
|
|
49
|
-
```
|
|
50
|
-
Message: Example Message
|
|
51
|
-
Data: true, 100
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Requesting & Serving
|
|
55
|
-
|
|
56
|
-
`IPC.invoke()` and `IPC.handle()` can be used to request and serve data between packs.
|
|
57
|
-
|
|
58
|
-
_Pack 1_
|
|
59
|
-
```js
|
|
60
|
-
import IPC from 'ipc.js'
|
|
61
|
-
|
|
62
|
-
IPC.handle('request_channel', (args) => {
|
|
63
|
-
switch (args) {
|
|
64
|
-
case 'status':
|
|
65
|
-
return 'inactive'
|
|
66
|
-
case 'size':
|
|
67
|
-
return 100
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
```
|
|
71
|
-
_Pack 2_
|
|
72
|
-
```js
|
|
73
|
-
import IPC from 'ipc.js'
|
|
74
|
-
|
|
75
|
-
IPC.invoke('request_channel', 'status').then(result => {
|
|
76
|
-
console.log(`Status: ${result}`)
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
IPC.invoke('request_channel', 'size').then(result => {
|
|
80
|
-
console.log(`Size: ${result}`)
|
|
81
|
-
})
|
|
82
|
-
```
|
|
83
|
-
_Console Output_
|
|
84
|
-
```
|
|
85
|
-
Status: inactive
|
|
86
|
-
Size: 100
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
20
|
+
2. Copy file into your project
|
package/dist/ipc.d.ts
CHANGED
|
@@ -22,11 +22,75 @@
|
|
|
22
22
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
23
|
* SOFTWARE.
|
|
24
24
|
*/
|
|
25
|
-
declare namespace
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
export declare namespace SERDE {
|
|
26
|
+
class ByteArray {
|
|
27
|
+
private _buffer;
|
|
28
|
+
private _data_view;
|
|
29
|
+
private _length;
|
|
30
|
+
private _offset;
|
|
31
|
+
private get _end();
|
|
32
|
+
constructor(size?: number);
|
|
33
|
+
write(...values: number[]): void;
|
|
34
|
+
read(amount?: number): number[];
|
|
35
|
+
write_uint8(value: number): void;
|
|
36
|
+
read_uint8(): number | undefined;
|
|
37
|
+
write_uint16(value: number): void;
|
|
38
|
+
read_uint16(): number | undefined;
|
|
39
|
+
write_uint32(value: number): void;
|
|
40
|
+
read_uint32(): number | undefined;
|
|
41
|
+
write_int8(value: number): void;
|
|
42
|
+
read_int8(): number | undefined;
|
|
43
|
+
write_int16(value: number): void;
|
|
44
|
+
read_int16(): number | undefined;
|
|
45
|
+
write_int32(value: number): void;
|
|
46
|
+
read_int32(): number | undefined;
|
|
47
|
+
write_f32(value: number): void;
|
|
48
|
+
read_f32(): number | undefined;
|
|
49
|
+
write_f64(value: number): void;
|
|
50
|
+
read_f64(): number | undefined;
|
|
51
|
+
private _ensure_capacity;
|
|
52
|
+
static from_uint8array(array: Uint8Array): ByteArray;
|
|
53
|
+
to_uint8array(): Uint8Array;
|
|
54
|
+
}
|
|
55
|
+
function serialize(byte_array: ByteArray, max_size?: number): Generator<void, string[], void>;
|
|
56
|
+
function deserialize(strings: string[]): Generator<void, ByteArray, void>;
|
|
57
|
+
}
|
|
58
|
+
export declare class Proto {
|
|
59
|
+
static Int8: NET.Serializable<number>;
|
|
60
|
+
static Int16: NET.Serializable<number>;
|
|
61
|
+
static Int32: NET.Serializable<number>;
|
|
62
|
+
static UInt8: NET.Serializable<number>;
|
|
63
|
+
static UInt16: NET.Serializable<number>;
|
|
64
|
+
static UInt32: NET.Serializable<number>;
|
|
65
|
+
static Float32: NET.Serializable<number>;
|
|
66
|
+
static Float64: NET.Serializable<number>;
|
|
67
|
+
static VarInt: NET.Serializable<number>;
|
|
68
|
+
static String: NET.Serializable<string>;
|
|
69
|
+
static Boolean: NET.Serializable<boolean>;
|
|
70
|
+
static UInt8Array: NET.Serializable<Uint8Array>;
|
|
71
|
+
static Date: NET.Serializable<Date>;
|
|
72
|
+
static Object<T extends object>(obj: {
|
|
73
|
+
[K in keyof T]: NET.Serializable<T[K]>;
|
|
74
|
+
}): NET.Serializable<T>;
|
|
75
|
+
static Array<T>(items: NET.Serializable<T>): NET.Serializable<T[]>;
|
|
76
|
+
static Tuple<T extends any[]>(...items: {
|
|
77
|
+
[K in keyof T]: NET.Serializable<T[K]>;
|
|
78
|
+
}): NET.Serializable<T>;
|
|
79
|
+
static Optional<T>(item: NET.Serializable<T>): NET.Serializable<T | undefined>;
|
|
80
|
+
static Map<K, V>(key: NET.Serializable<K>, value: NET.Serializable<V>): NET.Serializable<Map<K, V>>;
|
|
81
|
+
static Set<V>(value: NET.Serializable<V>): NET.Serializable<Set<V>>;
|
|
82
|
+
}
|
|
83
|
+
export declare namespace NET {
|
|
84
|
+
interface Serializable<T = any> {
|
|
85
|
+
serialize(value: T, stream: ByteArray): Generator<void, void, void>;
|
|
86
|
+
deserialize(stream: ByteArray): Generator<void, T, void>;
|
|
87
|
+
}
|
|
88
|
+
import ByteArray = SERDE.ByteArray;
|
|
89
|
+
function emit<T>(endpoint: string, serializer: Serializable<T>, value: T): Generator<void, void, void>;
|
|
90
|
+
function listen<T>(endpoint: string, serializer: Serializable<T>, callback: (value: T) => Generator<void, void, void>): () => void;
|
|
91
|
+
}
|
|
92
|
+
export declare namespace IPC {
|
|
93
|
+
class Connection {
|
|
30
94
|
private readonly _from;
|
|
31
95
|
private readonly _to;
|
|
32
96
|
private readonly _enc;
|
|
@@ -37,13 +101,13 @@ declare namespace IPC {
|
|
|
37
101
|
get to(): string;
|
|
38
102
|
constructor(from: string, to: string, encryption: string | false);
|
|
39
103
|
terminate(notify?: boolean): void;
|
|
40
|
-
send<T
|
|
41
|
-
invoke<T
|
|
42
|
-
on<T
|
|
43
|
-
once<T
|
|
44
|
-
handle<T
|
|
104
|
+
send<T>(channel: string, serializer: NET.Serializable<T>, value: T): void;
|
|
105
|
+
invoke<T, R>(channel: string, serializer: NET.Serializable<T>, value: T, deserializer: NET.Serializable<R>): Promise<R>;
|
|
106
|
+
on<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
107
|
+
once<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
108
|
+
handle<T, R>(channel: string, deserializer: NET.Serializable<T>, serializer: NET.Serializable<R>, listener: (value: T) => R): () => void;
|
|
45
109
|
}
|
|
46
|
-
|
|
110
|
+
class ConnectionManager {
|
|
47
111
|
private readonly _id;
|
|
48
112
|
private readonly _enc_map;
|
|
49
113
|
private readonly _con_map;
|
|
@@ -53,36 +117,21 @@ declare namespace IPC {
|
|
|
53
117
|
get id(): string;
|
|
54
118
|
constructor(id: string, force_encryption?: boolean);
|
|
55
119
|
connect(to: string, encrypted?: boolean, timeout?: number): Promise<Connection>;
|
|
56
|
-
send<T
|
|
57
|
-
invoke<T
|
|
58
|
-
on<T
|
|
59
|
-
once<T
|
|
60
|
-
handle<T
|
|
120
|
+
send<T>(channel: string, serializer: NET.Serializable<T>, value: T): void;
|
|
121
|
+
invoke<T, R>(channel: string, serializer: NET.Serializable<T>, value: T, deserializer: NET.Serializable<R>): Promise<R>[];
|
|
122
|
+
on<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
123
|
+
once<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
124
|
+
handle<T, R>(channel: string, deserializer: NET.Serializable<T>, serializer: NET.Serializable<R>, listener: (value: T) => R): () => void;
|
|
61
125
|
}
|
|
62
126
|
/** Sends a message with `args` to `channel` */
|
|
63
|
-
|
|
64
|
-
/** Sends a message with `args` to `channel` */
|
|
65
|
-
export function send<T extends any[]>(channel: string, ...args: T): void;
|
|
127
|
+
function send<T>(channel: string, serializer: NET.Serializable<T>, value: T): void;
|
|
66
128
|
/** Sends an `invoke` message through IPC, and expects a result asynchronously. */
|
|
67
|
-
|
|
68
|
-
/** Sends an `invoke` message through IPC, and expects a result asynchronously. */
|
|
69
|
-
export function invoke<T extends any[], R extends any>(channel: string, ...args: T): Promise<R>;
|
|
70
|
-
/** Listens to `channel`. When a new message arrives, `listener` will be called with `listener(args)`. */
|
|
71
|
-
export function on<C extends keyof SendTypes>(channel: C, listener: (...args: SendTypes[C]) => void): () => void;
|
|
129
|
+
function invoke<T, R>(channel: string, serializer: NET.Serializable<T>, value: T, deserializer: NET.Serializable<R>): Promise<R>;
|
|
72
130
|
/** Listens to `channel`. When a new message arrives, `listener` will be called with `listener(args)`. */
|
|
73
|
-
|
|
74
|
-
/** Listens to `channel` once. When a new message arrives, `listener` will be called with `listener(args)`, and then removed. */
|
|
75
|
-
export function once<C extends keyof SendTypes>(channel: C, listener: (...args: SendTypes[C]) => void): () => void;
|
|
131
|
+
function on<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
76
132
|
/** Listens to `channel` once. When a new message arrives, `listener` will be called with `listener(args)`, and then removed. */
|
|
77
|
-
|
|
133
|
+
function once<T>(channel: string, deserializer: NET.Serializable<T>, listener: (value: T) => void): () => void;
|
|
78
134
|
/** Adds a handler for an `invoke` IPC. This handler will be called whenever `invoke(channel, ...args)` is called */
|
|
79
|
-
|
|
80
|
-
/** Adds a handler for an `invoke` IPC. This handler will be called whenever `invoke(channel, ...args)` is called */
|
|
81
|
-
export function handle<T extends any[], R extends any>(channel: string, listener: (...args: T) => R): () => void;
|
|
82
|
-
export {};
|
|
135
|
+
function handle<T, R>(channel: string, deserializer: NET.Serializable<T>, serializer: NET.Serializable<R>, listener: (value: T) => R): () => void;
|
|
83
136
|
}
|
|
84
137
|
export default IPC;
|
|
85
|
-
export declare namespace NET {
|
|
86
|
-
function emit<T = any>(namespace: string, channel: string, args: T): Generator<void, void, void>;
|
|
87
|
-
function listen<T = any>(namespace: string, channel: string, callback: (args: T) => Generator<void, void, void>): () => void;
|
|
88
|
-
}
|