bunite-core 0.1.0 → 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/package.json +4 -1
- package/src/bun/core/BrowserView.ts +1 -14
- package/src/bun/index.ts +5 -2
- package/src/shared/rpc.ts +17 -2
- package/src/shared/webRpcHandler.ts +3 -3
- package/src/view/index.ts +2 -9
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bunite-core",
|
|
3
3
|
"description": "Uniting UI and Bun",
|
|
4
|
-
"version": "0.1
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"setup:cef": "bun ../tools/bunite-dev/scripts/setup-cef.ts",
|
|
@@ -21,5 +21,8 @@
|
|
|
21
21
|
],
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"msgpackr": "^1.11.9"
|
|
24
|
+
},
|
|
25
|
+
"optionalDependencies": {
|
|
26
|
+
"bunite-native-win-x64": "0.0.3"
|
|
24
27
|
}
|
|
25
28
|
}
|
|
@@ -2,8 +2,7 @@ import { ptr } from "bun:ffi";
|
|
|
2
2
|
import { buildViewPreloadScript } from "../preload/inline";
|
|
3
3
|
import { log } from "../../shared/log";
|
|
4
4
|
import { buniteEventEmitter } from "../events/eventEmitter";
|
|
5
|
-
import {
|
|
6
|
-
import { createWebRPCHandler } from "../../shared/webRpcHandler";
|
|
5
|
+
import { type RPCPacket, type RPCTransport, type RPCWithTransport } from "../../shared/rpc";
|
|
7
6
|
import { ensureNativeRuntime, getNativeLibrary, toCString, waitForViewReady, cancelWaitForViewReady } from "../proc/native";
|
|
8
7
|
import { attachBrowserViewRegistry, getRPCPort, sendMessageToView } from "./Socket";
|
|
9
8
|
import { randomBytes } from "node:crypto";
|
|
@@ -175,18 +174,6 @@ export class BrowserView<T extends RPCWithTransport = RPCWithTransport> {
|
|
|
175
174
|
return Object.values(BrowserViewMap);
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
static defineRPC<Schema extends BuniteRPCSchema>(
|
|
179
|
-
config: BuniteRPCConfig<Schema, "bun">
|
|
180
|
-
) {
|
|
181
|
-
const rpc = defineBuniteRPC("bun", config);
|
|
182
|
-
const webRpc = createWebRPCHandler<Schema>(config);
|
|
183
|
-
return Object.assign(rpc, {
|
|
184
|
-
webHandler: webRpc,
|
|
185
|
-
webClients: webRpc.webClients,
|
|
186
|
-
broadcast: webRpc.broadcast,
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
|
|
190
177
|
handleIncomingRPC(packet: RPCPacket) {
|
|
191
178
|
this.pipe.receive(packet);
|
|
192
179
|
}
|
package/src/bun/index.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { BuniteEvent } from "./events/event";
|
|
|
7
7
|
import { completePermissionRequest } from "./proc/native";
|
|
8
8
|
import {
|
|
9
9
|
createRPC,
|
|
10
|
-
|
|
10
|
+
defineBunRPC,
|
|
11
11
|
type BuniteRPCConfig,
|
|
12
12
|
type BuniteRPCSchema,
|
|
13
13
|
type RPCSchema,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "../shared/rpc";
|
|
16
16
|
import { createTransportDemuxer, type TransportDemuxer } from "../shared/rpcDemux";
|
|
17
17
|
import { createWebSocketTransport, type WebSocketLike, type WebSocketTransportPipe } from "../shared/webSocketTransport";
|
|
18
|
+
import { createWebRPCHandler, type WebRPCClient } from "../shared/webRpcHandler";
|
|
18
19
|
import type { MessageBoxOptions, MessageBoxResponse } from "./core/Utils";
|
|
19
20
|
import { log, type LogLevel } from "../shared/log";
|
|
20
21
|
|
|
@@ -27,8 +28,9 @@ export {
|
|
|
27
28
|
completePermissionRequest,
|
|
28
29
|
createRPC,
|
|
29
30
|
createTransportDemuxer,
|
|
31
|
+
createWebRPCHandler,
|
|
30
32
|
createWebSocketTransport,
|
|
31
|
-
|
|
33
|
+
defineBunRPC,
|
|
32
34
|
log
|
|
33
35
|
};
|
|
34
36
|
|
|
@@ -43,6 +45,7 @@ export type {
|
|
|
43
45
|
RPCSchema,
|
|
44
46
|
RPCWithTransport,
|
|
45
47
|
TransportDemuxer,
|
|
48
|
+
WebRPCClient,
|
|
46
49
|
WebSocketLike,
|
|
47
50
|
WebSocketTransportPipe,
|
|
48
51
|
WindowOptionsType
|
package/src/shared/rpc.ts
CHANGED
|
@@ -370,11 +370,10 @@ export function createRPC<
|
|
|
370
370
|
};
|
|
371
371
|
}
|
|
372
372
|
|
|
373
|
-
|
|
373
|
+
function defineSideRPC<
|
|
374
374
|
Schema extends BuniteRPCSchema,
|
|
375
375
|
Side extends "bun" | "webview"
|
|
376
376
|
>(
|
|
377
|
-
side: Side,
|
|
378
377
|
config: BuniteRPCConfig<Schema, Side> & {
|
|
379
378
|
extraRequestHandlers?: Record<string, (...args: any[]) => unknown>;
|
|
380
379
|
}
|
|
@@ -416,3 +415,19 @@ export function defineBuniteRPC<
|
|
|
416
415
|
|
|
417
416
|
return rpc;
|
|
418
417
|
}
|
|
418
|
+
|
|
419
|
+
export function defineBunRPC<Schema extends BuniteRPCSchema>(
|
|
420
|
+
config: BuniteRPCConfig<Schema, "bun"> & {
|
|
421
|
+
extraRequestHandlers?: Record<string, (...args: any[]) => unknown>;
|
|
422
|
+
}
|
|
423
|
+
) {
|
|
424
|
+
return defineSideRPC<Schema, "bun">(config);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
export function defineWebviewRPC<Schema extends BuniteRPCSchema>(
|
|
428
|
+
config: BuniteRPCConfig<Schema, "webview"> & {
|
|
429
|
+
extraRequestHandlers?: Record<string, (...args: any[]) => unknown>;
|
|
430
|
+
}
|
|
431
|
+
) {
|
|
432
|
+
return defineSideRPC<Schema, "webview">(config);
|
|
433
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
2
|
+
defineBunRPC,
|
|
3
3
|
type BuniteRPCConfig,
|
|
4
4
|
type BuniteRPCSchema
|
|
5
5
|
} from "./rpc";
|
|
@@ -8,7 +8,7 @@ import { log } from "./log";
|
|
|
8
8
|
|
|
9
9
|
export type WebRPCClient<Schema extends BuniteRPCSchema = BuniteRPCSchema> = {
|
|
10
10
|
ws: WebSocketLike;
|
|
11
|
-
rpc: ReturnType<typeof
|
|
11
|
+
rpc: ReturnType<typeof defineBunRPC<Schema>>;
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
export function createWebRPCHandler<Schema extends BuniteRPCSchema>(
|
|
@@ -24,7 +24,7 @@ export function createWebRPCHandler<Schema extends BuniteRPCSchema>(
|
|
|
24
24
|
const handler = {
|
|
25
25
|
open(ws: WebSocketLike) {
|
|
26
26
|
const pipe = createWebSocketTransport(ws);
|
|
27
|
-
const rpc =
|
|
27
|
+
const rpc = defineBunRPC(config);
|
|
28
28
|
rpc.setTransport(pipe.transport);
|
|
29
29
|
|
|
30
30
|
const client: WebRPCClient<Schema> = { ws, rpc: rpc as WebRPCClient<Schema>["rpc"] };
|
package/src/view/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "../shared/webviewPolyfill";
|
|
2
2
|
import {
|
|
3
|
-
|
|
3
|
+
defineWebviewRPC,
|
|
4
4
|
type BuniteRPCConfig,
|
|
5
5
|
type RPCPacket,
|
|
6
6
|
type BuniteRPCSchema,
|
|
@@ -161,13 +161,6 @@ export class BuniteView<T extends RPCWithTransport = RPCWithTransport> {
|
|
|
161
161
|
this.bunSocket.send(toArrayBuffer(encrypted));
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
static defineRPC<Schema extends BuniteRPCSchema>(
|
|
165
|
-
config: BuniteRPCConfig<Schema, "webview">
|
|
166
|
-
) {
|
|
167
|
-
const rpc = defineBuniteRPC("webview", config);
|
|
168
|
-
new BuniteView({ rpc });
|
|
169
|
-
return rpc;
|
|
170
|
-
}
|
|
171
164
|
}
|
|
172
165
|
|
|
173
166
|
async function messageToUint8Array(data: unknown) {
|
|
@@ -178,7 +171,7 @@ async function messageToUint8Array(data: unknown) {
|
|
|
178
171
|
}
|
|
179
172
|
|
|
180
173
|
export { log, type LogLevel } from "../shared/log";
|
|
181
|
-
export { createTransportDemuxer, createWebSocketTransport,
|
|
174
|
+
export { createTransportDemuxer, createWebSocketTransport, defineWebviewRPC };
|
|
182
175
|
|
|
183
176
|
export type {
|
|
184
177
|
BuniteRPCConfig,
|