fullstacked 0.11.3-1148 → 0.11.3-1150
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/archive/archive.ts +140 -140
- package/lib/archive/index.ts +4 -4
- package/lib/base64.ts +144 -144
- package/lib/bridge/index.ts +53 -53
- package/lib/bridge/platform/android.ts +18 -18
- package/lib/bridge/platform/apple.ts +46 -46
- package/lib/bridge/platform/electron.ts +14 -14
- package/lib/bridge/platform/linux-gtk.ts +48 -48
- package/lib/bridge/platform/linux-qt.ts +68 -68
- package/lib/bridge/platform/node.ts +32 -32
- package/lib/bridge/platform/wasm.ts +17 -17
- package/lib/bridge/platform/windows.ts +49 -49
- package/lib/bridge/serialization.ts +153 -153
- package/lib/components/snackbar.ts +60 -60
- package/lib/connect/index.ts +125 -125
- package/lib/core_message/core_message.ts +75 -75
- package/lib/core_message/index.ts +3 -3
- package/lib/fetch/index.ts +318 -318
- package/lib/fs/fs.ts +157 -157
- package/lib/fs/index.ts +3 -3
- package/lib/fullstacked.d.ts +208 -208
- package/lib/platform/index.ts +14 -14
- package/package.json +1 -1
package/lib/connect/index.ts
CHANGED
|
@@ -1,125 +1,125 @@
|
|
|
1
|
-
import { bridge } from "../bridge";
|
|
2
|
-
import {
|
|
3
|
-
deserializeArgs,
|
|
4
|
-
numberTo4Bytes,
|
|
5
|
-
serializeArgs
|
|
6
|
-
} from "../bridge/serialization";
|
|
7
|
-
import core_message from "../core_message";
|
|
8
|
-
import { toByteArray } from "../base64";
|
|
9
|
-
|
|
10
|
-
export type Data = string | number | boolean | Uint8Array;
|
|
11
|
-
|
|
12
|
-
type DataChannelCallback = (data: Data[]) => void;
|
|
13
|
-
|
|
14
|
-
type DataChannel = {
|
|
15
|
-
send(...args: Data[]): void;
|
|
16
|
-
on(callback: DataChannelCallback): void;
|
|
17
|
-
off(callback: DataChannelCallback): void;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
type DataChannelRawCallback = (data: Uint8Array) => void;
|
|
21
|
-
|
|
22
|
-
type DataChannelRaw = {
|
|
23
|
-
send(buffer: Uint8Array): void;
|
|
24
|
-
on(callback: DataChannelRawCallback): void;
|
|
25
|
-
off(callback: DataChannelRawCallback): void;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
type Channel = {
|
|
29
|
-
raw: false;
|
|
30
|
-
listeners: Set<DataChannelCallback>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
type ChannelRaw = {
|
|
34
|
-
raw: true;
|
|
35
|
-
listeners: Set<DataChannelRawCallback>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const channels = new Map<string, Channel | ChannelRaw>();
|
|
39
|
-
|
|
40
|
-
// 20
|
|
41
|
-
export function connect(
|
|
42
|
-
name: string,
|
|
43
|
-
port: number,
|
|
44
|
-
host?: string,
|
|
45
|
-
raw?: false
|
|
46
|
-
): Promise<DataChannel>;
|
|
47
|
-
export function connect(
|
|
48
|
-
name: string,
|
|
49
|
-
port: number,
|
|
50
|
-
host: string,
|
|
51
|
-
raw: true
|
|
52
|
-
): Promise<DataChannelRaw>;
|
|
53
|
-
export function connect(
|
|
54
|
-
name: string,
|
|
55
|
-
port: number,
|
|
56
|
-
host = "localhost",
|
|
57
|
-
raw = false
|
|
58
|
-
) {
|
|
59
|
-
const payload = new Uint8Array([
|
|
60
|
-
20,
|
|
61
|
-
...serializeArgs([name, port, host, raw])
|
|
62
|
-
]);
|
|
63
|
-
|
|
64
|
-
const transformer = ([channelId]) => {
|
|
65
|
-
if (raw) {
|
|
66
|
-
const listeners = new Set<DataChannelRawCallback>();
|
|
67
|
-
|
|
68
|
-
const channel: ChannelRaw = {
|
|
69
|
-
raw: true,
|
|
70
|
-
listeners
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
channels.set(channelId, channel);
|
|
74
|
-
|
|
75
|
-
core_message.addListener("channel-" + channelId, (dataStr) => {
|
|
76
|
-
const data = toByteArray(dataStr);
|
|
77
|
-
listeners.forEach((cb) => cb(data));
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
return {
|
|
81
|
-
send: (data) => send(channelId, data),
|
|
82
|
-
on: (cb) => listeners.add(cb),
|
|
83
|
-
off: (cb) => listeners.add(cb)
|
|
84
|
-
} as DataChannelRaw;
|
|
85
|
-
} else {
|
|
86
|
-
const listeners = new Set<DataChannelCallback>();
|
|
87
|
-
|
|
88
|
-
const channel: Channel = {
|
|
89
|
-
raw: false,
|
|
90
|
-
listeners
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
core_message.addListener("channel-" + channelId, (dataStr) => {
|
|
94
|
-
const data = toByteArray(dataStr);
|
|
95
|
-
listeners.forEach((cb) => cb(deserializeArgs(data)));
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
channels.set(channelId, channel);
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
send: (...data) => {
|
|
102
|
-
const body = serializeArgs(data);
|
|
103
|
-
send(
|
|
104
|
-
channelId,
|
|
105
|
-
new Uint8Array([
|
|
106
|
-
...numberTo4Bytes(body.byteLength),
|
|
107
|
-
...body
|
|
108
|
-
])
|
|
109
|
-
);
|
|
110
|
-
},
|
|
111
|
-
on: (cb) => listeners.add(cb),
|
|
112
|
-
off: (cb) => listeners.add(cb)
|
|
113
|
-
} as DataChannel;
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
return bridge(payload, transformer);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 21
|
|
121
|
-
function send(channelId: string, data: Uint8Array) {
|
|
122
|
-
const payload = new Uint8Array([21, ...serializeArgs([channelId, data])]);
|
|
123
|
-
|
|
124
|
-
return bridge(payload);
|
|
125
|
-
}
|
|
1
|
+
import { bridge } from "../bridge";
|
|
2
|
+
import {
|
|
3
|
+
deserializeArgs,
|
|
4
|
+
numberTo4Bytes,
|
|
5
|
+
serializeArgs
|
|
6
|
+
} from "../bridge/serialization";
|
|
7
|
+
import core_message from "../core_message";
|
|
8
|
+
import { toByteArray } from "../base64";
|
|
9
|
+
|
|
10
|
+
export type Data = string | number | boolean | Uint8Array;
|
|
11
|
+
|
|
12
|
+
type DataChannelCallback = (data: Data[]) => void;
|
|
13
|
+
|
|
14
|
+
type DataChannel = {
|
|
15
|
+
send(...args: Data[]): void;
|
|
16
|
+
on(callback: DataChannelCallback): void;
|
|
17
|
+
off(callback: DataChannelCallback): void;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type DataChannelRawCallback = (data: Uint8Array) => void;
|
|
21
|
+
|
|
22
|
+
type DataChannelRaw = {
|
|
23
|
+
send(buffer: Uint8Array): void;
|
|
24
|
+
on(callback: DataChannelRawCallback): void;
|
|
25
|
+
off(callback: DataChannelRawCallback): void;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type Channel = {
|
|
29
|
+
raw: false;
|
|
30
|
+
listeners: Set<DataChannelCallback>;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
type ChannelRaw = {
|
|
34
|
+
raw: true;
|
|
35
|
+
listeners: Set<DataChannelRawCallback>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const channels = new Map<string, Channel | ChannelRaw>();
|
|
39
|
+
|
|
40
|
+
// 20
|
|
41
|
+
export function connect(
|
|
42
|
+
name: string,
|
|
43
|
+
port: number,
|
|
44
|
+
host?: string,
|
|
45
|
+
raw?: false
|
|
46
|
+
): Promise<DataChannel>;
|
|
47
|
+
export function connect(
|
|
48
|
+
name: string,
|
|
49
|
+
port: number,
|
|
50
|
+
host: string,
|
|
51
|
+
raw: true
|
|
52
|
+
): Promise<DataChannelRaw>;
|
|
53
|
+
export function connect(
|
|
54
|
+
name: string,
|
|
55
|
+
port: number,
|
|
56
|
+
host = "localhost",
|
|
57
|
+
raw = false
|
|
58
|
+
) {
|
|
59
|
+
const payload = new Uint8Array([
|
|
60
|
+
20,
|
|
61
|
+
...serializeArgs([name, port, host, raw])
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
const transformer = ([channelId]) => {
|
|
65
|
+
if (raw) {
|
|
66
|
+
const listeners = new Set<DataChannelRawCallback>();
|
|
67
|
+
|
|
68
|
+
const channel: ChannelRaw = {
|
|
69
|
+
raw: true,
|
|
70
|
+
listeners
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
channels.set(channelId, channel);
|
|
74
|
+
|
|
75
|
+
core_message.addListener("channel-" + channelId, (dataStr) => {
|
|
76
|
+
const data = toByteArray(dataStr);
|
|
77
|
+
listeners.forEach((cb) => cb(data));
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
send: (data) => send(channelId, data),
|
|
82
|
+
on: (cb) => listeners.add(cb),
|
|
83
|
+
off: (cb) => listeners.add(cb)
|
|
84
|
+
} as DataChannelRaw;
|
|
85
|
+
} else {
|
|
86
|
+
const listeners = new Set<DataChannelCallback>();
|
|
87
|
+
|
|
88
|
+
const channel: Channel = {
|
|
89
|
+
raw: false,
|
|
90
|
+
listeners
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
core_message.addListener("channel-" + channelId, (dataStr) => {
|
|
94
|
+
const data = toByteArray(dataStr);
|
|
95
|
+
listeners.forEach((cb) => cb(deserializeArgs(data)));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
channels.set(channelId, channel);
|
|
99
|
+
|
|
100
|
+
return {
|
|
101
|
+
send: (...data) => {
|
|
102
|
+
const body = serializeArgs(data);
|
|
103
|
+
send(
|
|
104
|
+
channelId,
|
|
105
|
+
new Uint8Array([
|
|
106
|
+
...numberTo4Bytes(body.byteLength),
|
|
107
|
+
...body
|
|
108
|
+
])
|
|
109
|
+
);
|
|
110
|
+
},
|
|
111
|
+
on: (cb) => listeners.add(cb),
|
|
112
|
+
off: (cb) => listeners.add(cb)
|
|
113
|
+
} as DataChannel;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
return bridge(payload, transformer);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 21
|
|
121
|
+
function send(channelId: string, data: Uint8Array) {
|
|
122
|
+
const payload = new Uint8Array([21, ...serializeArgs([channelId, data])]);
|
|
123
|
+
|
|
124
|
+
return bridge(payload);
|
|
125
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { bridge } from "../bridge";
|
|
2
|
-
import { serializeArgs } from "../bridge/serialization";
|
|
3
|
-
import { SnackBar } from "../components/snackbar";
|
|
4
|
-
|
|
5
|
-
const coreMessageListeners = new Map<string, Set<(message: string) => void>>();
|
|
6
|
-
export const addListener = (
|
|
7
|
-
messageType: string,
|
|
8
|
-
cb: (message: string) => void
|
|
9
|
-
) => {
|
|
10
|
-
let listeners = coreMessageListeners.get(messageType);
|
|
11
|
-
if (!listeners) {
|
|
12
|
-
listeners = new Set<typeof cb>();
|
|
13
|
-
coreMessageListeners.set(messageType, listeners);
|
|
14
|
-
}
|
|
15
|
-
listeners.add(cb);
|
|
16
|
-
|
|
17
|
-
const pending = pendingMessages.get(messageType);
|
|
18
|
-
if (pending?.length) {
|
|
19
|
-
for (const m of pending) {
|
|
20
|
-
cb(m);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
export const removeListener = (
|
|
25
|
-
messageType: string,
|
|
26
|
-
cb: (message: string) => void
|
|
27
|
-
) => {
|
|
28
|
-
let listeners = coreMessageListeners.get(messageType);
|
|
29
|
-
listeners?.delete(cb);
|
|
30
|
-
if (listeners?.size === 0) {
|
|
31
|
-
coreMessageListeners.delete(messageType);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const pendingMessages = new Map<string, string[]>();
|
|
36
|
-
setInterval(() => pendingMessages.clear(), 10 * 1000); // 10s
|
|
37
|
-
|
|
38
|
-
globalThis.oncoremessage = (messageType: string, message: string) => {
|
|
39
|
-
const listeners = coreMessageListeners.get(messageType);
|
|
40
|
-
if (!listeners?.size) {
|
|
41
|
-
let pending = pendingMessages.get(messageType);
|
|
42
|
-
if (!pending) {
|
|
43
|
-
pending = [];
|
|
44
|
-
pendingMessages.set(messageType, pending);
|
|
45
|
-
}
|
|
46
|
-
pending.push(message);
|
|
47
|
-
} else {
|
|
48
|
-
listeners?.forEach((cb) => cb(message));
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
addListener("hello", console.log);
|
|
53
|
-
addListener("log", console.log);
|
|
54
|
-
addListener("alert", (message) => {
|
|
55
|
-
SnackBar({
|
|
56
|
-
message,
|
|
57
|
-
autoDismissTimeout: 4000
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// 40
|
|
62
|
-
function setTitle(title: string) {
|
|
63
|
-
const payload = new Uint8Array([
|
|
64
|
-
40,
|
|
65
|
-
...serializeArgs([title])
|
|
66
|
-
]);
|
|
67
|
-
bridge(payload);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
let lastTitleSeen = null;
|
|
71
|
-
setInterval(() => {
|
|
72
|
-
if(lastTitleSeen !== document.title) {
|
|
73
|
-
setTitle(document.title);
|
|
74
|
-
}
|
|
75
|
-
lastTitleSeen = document.title;
|
|
1
|
+
import { bridge } from "../bridge";
|
|
2
|
+
import { serializeArgs } from "../bridge/serialization";
|
|
3
|
+
import { SnackBar } from "../components/snackbar";
|
|
4
|
+
|
|
5
|
+
const coreMessageListeners = new Map<string, Set<(message: string) => void>>();
|
|
6
|
+
export const addListener = (
|
|
7
|
+
messageType: string,
|
|
8
|
+
cb: (message: string) => void
|
|
9
|
+
) => {
|
|
10
|
+
let listeners = coreMessageListeners.get(messageType);
|
|
11
|
+
if (!listeners) {
|
|
12
|
+
listeners = new Set<typeof cb>();
|
|
13
|
+
coreMessageListeners.set(messageType, listeners);
|
|
14
|
+
}
|
|
15
|
+
listeners.add(cb);
|
|
16
|
+
|
|
17
|
+
const pending = pendingMessages.get(messageType);
|
|
18
|
+
if (pending?.length) {
|
|
19
|
+
for (const m of pending) {
|
|
20
|
+
cb(m);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
export const removeListener = (
|
|
25
|
+
messageType: string,
|
|
26
|
+
cb: (message: string) => void
|
|
27
|
+
) => {
|
|
28
|
+
let listeners = coreMessageListeners.get(messageType);
|
|
29
|
+
listeners?.delete(cb);
|
|
30
|
+
if (listeners?.size === 0) {
|
|
31
|
+
coreMessageListeners.delete(messageType);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const pendingMessages = new Map<string, string[]>();
|
|
36
|
+
setInterval(() => pendingMessages.clear(), 10 * 1000); // 10s
|
|
37
|
+
|
|
38
|
+
globalThis.oncoremessage = (messageType: string, message: string) => {
|
|
39
|
+
const listeners = coreMessageListeners.get(messageType);
|
|
40
|
+
if (!listeners?.size) {
|
|
41
|
+
let pending = pendingMessages.get(messageType);
|
|
42
|
+
if (!pending) {
|
|
43
|
+
pending = [];
|
|
44
|
+
pendingMessages.set(messageType, pending);
|
|
45
|
+
}
|
|
46
|
+
pending.push(message);
|
|
47
|
+
} else {
|
|
48
|
+
listeners?.forEach((cb) => cb(message));
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
addListener("hello", console.log);
|
|
53
|
+
addListener("log", console.log);
|
|
54
|
+
addListener("alert", (message) => {
|
|
55
|
+
SnackBar({
|
|
56
|
+
message,
|
|
57
|
+
autoDismissTimeout: 4000
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// 40
|
|
62
|
+
function setTitle(title: string) {
|
|
63
|
+
const payload = new Uint8Array([
|
|
64
|
+
40,
|
|
65
|
+
...serializeArgs([title])
|
|
66
|
+
]);
|
|
67
|
+
bridge(payload);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let lastTitleSeen = null;
|
|
71
|
+
setInterval(() => {
|
|
72
|
+
if(lastTitleSeen !== document.title) {
|
|
73
|
+
setTitle(document.title);
|
|
74
|
+
}
|
|
75
|
+
lastTitleSeen = document.title;
|
|
76
76
|
}, 500)
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import * as core_message from "./core_message";
|
|
2
|
-
export default core_message;
|
|
3
|
-
export * from "./core_message";
|
|
1
|
+
import * as core_message from "./core_message";
|
|
2
|
+
export default core_message;
|
|
3
|
+
export * from "./core_message";
|