@zimi/remote 0.2.1-alpha.9 → 0.2.3
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/LICENSE.md +21 -21
- package/README.md +289 -214
- package/dist/adaptor.d.mts +33 -0
- package/dist/adaptor.d.ts +6 -5
- package/dist/adaptor.js +1 -1
- package/dist/adaptor.js.map +1 -1
- package/dist/adaptor.mjs +1 -0
- package/dist/adaptor.mjs.map +1 -0
- package/dist/adaptors/dao3/client.d.mts +39 -0
- package/dist/adaptors/dao3/client.d.ts +14 -3
- package/dist/adaptors/dao3/client.js +1 -35
- package/dist/adaptors/dao3/client.js.map +1 -1
- package/dist/adaptors/dao3/client.mjs +2 -0
- package/dist/adaptors/dao3/client.mjs.map +1 -0
- package/dist/adaptors/dao3/server.d.mts +82 -0
- package/dist/adaptors/dao3/server.d.ts +21 -4
- package/dist/adaptors/dao3/server.js +1 -89
- package/dist/adaptors/dao3/server.js.map +1 -1
- package/dist/adaptors/dao3/server.mjs +2 -0
- package/dist/adaptors/dao3/server.mjs.map +1 -0
- package/dist/adaptors/electron/constants.d.mts +5 -0
- package/dist/adaptors/electron/constants.d.ts +5 -0
- package/dist/adaptors/electron/constants.js +2 -0
- package/dist/adaptors/electron/constants.js.map +1 -0
- package/dist/adaptors/electron/constants.mjs +2 -0
- package/dist/adaptors/electron/constants.mjs.map +1 -0
- package/dist/adaptors/electron/main.d.mts +10 -0
- package/dist/adaptors/electron/main.d.ts +10 -0
- package/dist/adaptors/electron/main.js +2 -0
- package/dist/adaptors/electron/main.js.map +1 -0
- package/dist/adaptors/electron/main.mjs +2 -0
- package/dist/adaptors/electron/main.mjs.map +1 -0
- package/dist/adaptors/electron/messenger.d.mts +8 -0
- package/dist/adaptors/electron/messenger.d.ts +8 -0
- package/dist/adaptors/electron/messenger.js +2 -0
- package/dist/adaptors/electron/messenger.js.map +1 -0
- package/dist/adaptors/electron/messenger.mjs +2 -0
- package/dist/adaptors/electron/messenger.mjs.map +1 -0
- package/dist/adaptors/electron/preload.d.mts +6 -0
- package/dist/adaptors/electron/preload.d.ts +6 -0
- package/dist/adaptors/electron/preload.js +2 -0
- package/dist/adaptors/electron/preload.js.map +1 -0
- package/dist/adaptors/electron/preload.mjs +2 -0
- package/dist/adaptors/electron/preload.mjs.map +1 -0
- package/dist/adaptors/electron/renderer.d.mts +9 -0
- package/dist/adaptors/electron/renderer.d.ts +9 -0
- package/dist/adaptors/electron/renderer.js +2 -0
- package/dist/adaptors/electron/renderer.js.map +1 -0
- package/dist/adaptors/electron/renderer.mjs +2 -0
- package/dist/adaptors/electron/renderer.mjs.map +1 -0
- package/dist/adaptors/http.d.mts +15 -0
- package/dist/adaptors/http.d.ts +6 -4
- package/dist/adaptors/http.js +1 -26
- package/dist/adaptors/http.js.map +1 -1
- package/dist/adaptors/http.mjs +2 -0
- package/dist/adaptors/http.mjs.map +1 -0
- package/dist/adaptors/iframe.d.mts +7 -0
- package/dist/adaptors/iframe.d.ts +5 -2
- package/dist/adaptors/iframe.js +1 -38
- package/dist/adaptors/iframe.js.map +1 -1
- package/dist/adaptors/iframe.mjs +2 -0
- package/dist/adaptors/iframe.mjs.map +1 -0
- package/dist/index.d.mts +16 -0
- package/dist/index.d.ts +16 -10
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/index.mjs.map +1 -0
- package/dist/remote.d.mts +81 -0
- package/dist/remote.d.ts +6 -4
- package/dist/remote.js +1 -196
- package/dist/remote.js.map +1 -1
- package/dist/remote.mjs +2 -0
- package/dist/remote.mjs.map +1 -0
- package/dist/remoteValue/exposeToRemote.d.mts +43 -0
- package/dist/remoteValue/exposeToRemote.d.ts +33 -6
- package/dist/remoteValue/exposeToRemote.js +1 -49
- package/dist/remoteValue/exposeToRemote.js.map +1 -1
- package/dist/remoteValue/exposeToRemote.mjs +2 -0
- package/dist/remoteValue/exposeToRemote.mjs.map +1 -0
- package/dist/remoteValue/remoteValue.d.mts +29 -0
- package/dist/remoteValue/remoteValue.d.ts +6 -4
- package/dist/remoteValue/remoteValue.js +1 -67
- package/dist/remoteValue/remoteValue.js.map +1 -1
- package/dist/remoteValue/remoteValue.mjs +2 -0
- package/dist/remoteValue/remoteValue.mjs.map +1 -0
- package/dist/remoteValue/type.d.mts +67 -0
- package/dist/remoteValue/type.d.ts +23 -18
- package/dist/remoteValue/type.js +1 -1
- package/dist/remoteValue/type.js.map +1 -1
- package/dist/remoteValue/type.mjs +1 -0
- package/dist/remoteValue/type.mjs.map +1 -0
- package/dist/response.d.mts +105 -0
- package/dist/response.d.ts +6 -5
- package/dist/response.js +1 -154
- package/dist/response.js.map +1 -1
- package/dist/response.mjs +2 -0
- package/dist/response.mjs.map +1 -0
- package/package.json +13 -6
- package/src/adaptor.ts +34 -34
- package/src/adaptors/dao3/client.ts +53 -44
- package/src/adaptors/dao3/server.ts +136 -121
- package/src/adaptors/electron/constants.ts +3 -0
- package/src/adaptors/electron/main.ts +59 -0
- package/src/adaptors/electron/messenger.ts +13 -0
- package/src/adaptors/electron/preload.ts +21 -0
- package/src/adaptors/electron/renderer.ts +52 -0
- package/src/adaptors/http.ts +31 -31
- package/src/adaptors/iframe.ts +47 -47
- package/src/index.ts +6 -1
- package/src/remote.ts +263 -260
- package/src/remoteValue/exposeToRemote.ts +102 -68
- package/src/remoteValue/remoteValue.ts +94 -94
- package/src/remoteValue/type.ts +124 -119
- package/src/response.ts +170 -170
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import {
|
|
2
|
+
import { AdaptorPackageData } from '../../adaptor.js';
|
|
3
|
+
|
|
3
4
|
interface RemoteChannel {
|
|
4
5
|
onClientEvent(fn: (e: unknown) => void): void;
|
|
5
6
|
}
|
|
@@ -17,12 +18,22 @@ interface RemoteChannel {
|
|
|
17
18
|
* remoteChannel.sendServerEvent(e)
|
|
18
19
|
* },
|
|
19
20
|
* } satisfies Adaptor
|
|
21
|
+
*
|
|
22
|
+
* export const remote = new Remote<RemoteFuncsFromClient, RemoteFuncsFromServer>(
|
|
23
|
+
* remoteAdaptor,
|
|
24
|
+
* {
|
|
25
|
+
* deviceId: `client-${Math.random().toString(36).slice(2)}`,
|
|
26
|
+
* }
|
|
27
|
+
* )
|
|
28
|
+
*
|
|
29
|
+
* void remote._.initConnection()
|
|
20
30
|
* ```
|
|
21
31
|
*/
|
|
22
|
-
|
|
32
|
+
declare class ClientSideRemoteChannelEventManager extends EventEmitter<{
|
|
23
33
|
[key: string]: [AdaptorPackageData];
|
|
24
34
|
}> {
|
|
25
35
|
constructor(remoteChannel: RemoteChannel);
|
|
26
36
|
onEvery(fn: (args: AdaptorPackageData) => void): void;
|
|
27
37
|
}
|
|
28
|
-
|
|
38
|
+
|
|
39
|
+
export { ClientSideRemoteChannelEventManager };
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { isRemoteAdaptorData } from '../../remote';
|
|
3
|
-
/**
|
|
4
|
-
* 这是 [dao3 游戏](https://dao3.fun/) 代码客户端适配器。
|
|
5
|
-
* ```ts
|
|
6
|
-
* const remoteManager = new ClientSideRemoteChannelEventManager(remoteChannel)
|
|
7
|
-
*
|
|
8
|
-
* export const remoteAdaptor = {
|
|
9
|
-
* every: remoteManager.onEvery.bind(remoteManager),
|
|
10
|
-
* off: remoteManager.off.bind(remoteManager),
|
|
11
|
-
* on: remoteManager.on.bind(remoteManager),
|
|
12
|
-
* once: remoteManager.once.bind(remoteManager),
|
|
13
|
-
* emit: (e) => {
|
|
14
|
-
* remoteChannel.sendServerEvent(e)
|
|
15
|
-
* },
|
|
16
|
-
* } satisfies Adaptor
|
|
17
|
-
* ```
|
|
18
|
-
*/
|
|
19
|
-
export class ClientSideRemoteChannelEventManager extends EventEmitter {
|
|
20
|
-
constructor(remoteChannel) {
|
|
21
|
-
super();
|
|
22
|
-
remoteChannel.onClientEvent((e) => {
|
|
23
|
-
if (!isRemoteAdaptorData(e)) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
if (!e.name.startsWith('__REMOTE_VALUE_REQ__')) {
|
|
27
|
-
this.emit('__remote_every__', e);
|
|
28
|
-
}
|
|
29
|
-
this.emit(e.name, e);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
onEvery(fn) {
|
|
33
|
-
this.on('__remote_every__', fn);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
1
|
+
"use strict";var s=Object.create;var o=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var d=Object.getOwnPropertyNames;var p=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var a in t)o(e,a,{get:t[a],enumerable:!0})},i=(e,t,a,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of d(t))!E.call(e,n)&&n!==a&&o(e,n,{get:()=>t[n],enumerable:!(r=v(t,n))||r.enumerable});return e};var f=(e,t,a)=>(a=e!=null?s(p(e)):{},i(t||!e||!e.__esModule?o(a,"default",{value:e,enumerable:!0}):a,e)),h=e=>i(o({},"__esModule",{value:!0}),e);var g={};c(g,{ClientSideRemoteChannelEventManager:()=>l});module.exports=h(g);var m=f(require("eventemitter3")),_=require("../../remote");class l extends m.default{constructor(t){super(),t.onClientEvent(a=>{(0,_.isRemoteAdaptorData)(a)&&(a.name.startsWith("__REMOTE_VALUE_REQ__")||this.emit("__remote_every__",a),this.emit(a.name,a))})}onEvery(t){this.on("__remote_every__",t)}}0&&(module.exports={ClientSideRemoteChannelEventManager});
|
|
36
2
|
//# sourceMappingURL=client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/dao3/client.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { type AdaptorPackageData } from '../../adaptor'\r\n\r\ninterface RemoteChannel {\r\n onClientEvent(fn: (e: unknown) => void): void\r\n}\r\n\r\n/**\r\n * 这是 [dao3 游戏](https://dao3.fun/) 代码客户端适配器。\r\n * ```ts\r\n * const remoteManager = new ClientSideRemoteChannelEventManager(remoteChannel)\r\n *\r\n * export const remoteAdaptor = {\r\n * every: remoteManager.onEvery.bind(remoteManager),\r\n * off: remoteManager.off.bind(remoteManager),\r\n * on: remoteManager.on.bind(remoteManager),\r\n * once: remoteManager.once.bind(remoteManager),\r\n * emit: (e) => {\r\n * remoteChannel.sendServerEvent(e)\r\n * },\r\n * } satisfies Adaptor\r\n *\r\n * export const remote = new Remote<RemoteFuncsFromClient, RemoteFuncsFromServer>(\r\n * remoteAdaptor,\r\n * {\r\n * deviceId: `client-${Math.random().toString(36).slice(2)}`,\r\n * }\r\n * )\r\n *\r\n * void remote._.initConnection()\r\n * ```\r\n */\r\nexport class ClientSideRemoteChannelEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n constructor(remoteChannel: RemoteChannel) {\r\n super()\r\n remoteChannel.onClientEvent((e) => {\r\n if (!isRemoteAdaptorData(e)) {\r\n return\r\n }\r\n if (!e.name.startsWith('__REMOTE_VALUE_REQ__')) {\r\n this.emit('__remote_every__', e)\r\n }\r\n this.emit(e.name, e)\r\n })\r\n }\r\n\r\n onEvery(fn: (args: AdaptorPackageData) => void): void {\r\n this.on('__remote_every__', fn)\r\n }\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,4BACzBC,EAAoC,wBAgC7B,MAAMH,UAA4C,EAAAI,OAEtD,CACD,YAAYC,EAA8B,CACxC,MAAM,EACNA,EAAc,cAAeC,GAAM,IAC5B,uBAAoBA,CAAC,IAGrBA,EAAE,KAAK,WAAW,sBAAsB,GAC3C,KAAK,KAAK,mBAAoBA,CAAC,EAEjC,KAAK,KAAKA,EAAE,KAAMA,CAAC,EACrB,CAAC,CACH,CAEA,QAAQC,EAA8C,CACpD,KAAK,GAAG,mBAAoBA,CAAE,CAChC,CACF","names":["client_exports","__export","ClientSideRemoteChannelEventManager","__toCommonJS","import_eventemitter3","import_remote","EventEmitter","remoteChannel","e","fn"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import a from"eventemitter3";import{isRemoteAdaptorData as n}from"../../remote";class _ extends a{constructor(t){super(),t.onClientEvent(e=>{n(e)&&(e.name.startsWith("__REMOTE_VALUE_REQ__")||this.emit("__remote_every__",e),this.emit(e.name,e))})}onEvery(t){this.on("__remote_every__",t)}}export{_ as ClientSideRemoteChannelEventManager};
|
|
2
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/dao3/client.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { type AdaptorPackageData } from '../../adaptor'\r\n\r\ninterface RemoteChannel {\r\n onClientEvent(fn: (e: unknown) => void): void\r\n}\r\n\r\n/**\r\n * 这是 [dao3 游戏](https://dao3.fun/) 代码客户端适配器。\r\n * ```ts\r\n * const remoteManager = new ClientSideRemoteChannelEventManager(remoteChannel)\r\n *\r\n * export const remoteAdaptor = {\r\n * every: remoteManager.onEvery.bind(remoteManager),\r\n * off: remoteManager.off.bind(remoteManager),\r\n * on: remoteManager.on.bind(remoteManager),\r\n * once: remoteManager.once.bind(remoteManager),\r\n * emit: (e) => {\r\n * remoteChannel.sendServerEvent(e)\r\n * },\r\n * } satisfies Adaptor\r\n *\r\n * export const remote = new Remote<RemoteFuncsFromClient, RemoteFuncsFromServer>(\r\n * remoteAdaptor,\r\n * {\r\n * deviceId: `client-${Math.random().toString(36).slice(2)}`,\r\n * }\r\n * )\r\n *\r\n * void remote._.initConnection()\r\n * ```\r\n */\r\nexport class ClientSideRemoteChannelEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n constructor(remoteChannel: RemoteChannel) {\r\n super()\r\n remoteChannel.onClientEvent((e) => {\r\n if (!isRemoteAdaptorData(e)) {\r\n return\r\n }\r\n if (!e.name.startsWith('__REMOTE_VALUE_REQ__')) {\r\n this.emit('__remote_every__', e)\r\n }\r\n this.emit(e.name, e)\r\n })\r\n }\r\n\r\n onEvery(fn: (args: AdaptorPackageData) => void): void {\r\n this.on('__remote_every__', fn)\r\n }\r\n}\r\n"],"mappings":"AAAA,OAAOA,MAAkB,gBACzB,OAAS,uBAAAC,MAA2B,eAgC7B,MAAMC,UAA4CF,CAEtD,CACD,YAAYG,EAA8B,CACxC,MAAM,EACNA,EAAc,cAAe,GAAM,CAC5BF,EAAoB,CAAC,IAGrB,EAAE,KAAK,WAAW,sBAAsB,GAC3C,KAAK,KAAK,mBAAoB,CAAC,EAEjC,KAAK,KAAK,EAAE,KAAM,CAAC,EACrB,CAAC,CACH,CAEA,QAAQG,EAA8C,CACpD,KAAK,GAAG,mBAAoBA,CAAE,CAChC,CACF","names":["EventEmitter","isRemoteAdaptorData","ClientSideRemoteChannelEventManager","remoteChannel","fn"]}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { AdaptorPackageData } from '../../adaptor.mjs';
|
|
3
|
+
|
|
4
|
+
interface GamePlayerEntityLike {
|
|
5
|
+
player: {
|
|
6
|
+
userKey: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
interface RemoteChannel<T extends GamePlayerEntityLike> {
|
|
10
|
+
onServerEvent(fn: (e: {
|
|
11
|
+
args: unknown;
|
|
12
|
+
entity: T;
|
|
13
|
+
}) => void): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 这是 [dao3 游戏](https://dao3.fun/) 代码服务端适配器。
|
|
17
|
+
* ```ts
|
|
18
|
+
* const remoteManager = new ServerSideRemoteChannelEventManager(remoteChannel)
|
|
19
|
+
*
|
|
20
|
+
* world.onPlayerLeave(
|
|
21
|
+
* remoteManager.onPlayerLeave.bind(remoteManager)
|
|
22
|
+
* )
|
|
23
|
+
*
|
|
24
|
+
* export const remoteAdaptor = {
|
|
25
|
+
* every: remoteManager.onEvery.bind(remoteManager),
|
|
26
|
+
* off: remoteManager.off.bind(remoteManager),
|
|
27
|
+
* on: remoteManager.on.bind(remoteManager),
|
|
28
|
+
* once: remoteManager.once.bind(remoteManager),
|
|
29
|
+
* emit: (e) => {
|
|
30
|
+
* const entity = remoteManager.getEntity(e.targetDeviceId)
|
|
31
|
+
* if (!entity) {
|
|
32
|
+
* console.error('entity not found')
|
|
33
|
+
* return
|
|
34
|
+
* }
|
|
35
|
+
* remoteChannel.sendClientEvent(entity, e as unknown as JSONValue)
|
|
36
|
+
* },
|
|
37
|
+
* } satisfies Adaptor
|
|
38
|
+
*
|
|
39
|
+
* export const remote = new Remote<RemoteFuncsFromServer, RemoteFuncsFromClient>(
|
|
40
|
+
* remoteAdaptor,
|
|
41
|
+
* {
|
|
42
|
+
* deviceId: 'server',
|
|
43
|
+
* }
|
|
44
|
+
* )
|
|
45
|
+
*
|
|
46
|
+
* remote.register('initConnection', async () => {
|
|
47
|
+
* // 什么也不干,单纯的让客户端在服务端“备案”
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* export const getEntity = remoteManager.getEntity.bind(remoteManager)
|
|
51
|
+
* export const getIdByEntity = remoteManager.getIdByEntity.bind(remoteManager)
|
|
52
|
+
* export const waitForRegister = remoteManager.waitForRegister.bind(remoteManager)
|
|
53
|
+
* export const remoteTo = remoteManager.remoteTo.bind(remoteManager)
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare class ServerSideRemoteChannelEventManager<T extends GamePlayerEntityLike> extends EventEmitter<{
|
|
57
|
+
[key: string]: [AdaptorPackageData];
|
|
58
|
+
}> {
|
|
59
|
+
entityMap: [string, T][];
|
|
60
|
+
constructor(remoteChannel: RemoteChannel<T>);
|
|
61
|
+
onPlayerLeave(e: {
|
|
62
|
+
entity: T;
|
|
63
|
+
}): void;
|
|
64
|
+
onEvery(fn: (args: AdaptorPackageData) => void): void;
|
|
65
|
+
waitForRegister(entity: T): Promise<void>;
|
|
66
|
+
getEntity(deviceId: string): T | undefined;
|
|
67
|
+
getIdByEntity(entity: T): string | undefined;
|
|
68
|
+
remoteTo(config: {
|
|
69
|
+
target: T;
|
|
70
|
+
}): {
|
|
71
|
+
targetDeviceId: string;
|
|
72
|
+
};
|
|
73
|
+
remoteTo(config: {
|
|
74
|
+
target: T;
|
|
75
|
+
timeoutMs: number;
|
|
76
|
+
}): {
|
|
77
|
+
targetDeviceId: string;
|
|
78
|
+
timeoutMs: number;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { ServerSideRemoteChannelEventManager };
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3';
|
|
2
|
-
import {
|
|
2
|
+
import { AdaptorPackageData } from '../../adaptor.js';
|
|
3
|
+
|
|
3
4
|
interface GamePlayerEntityLike {
|
|
4
5
|
player: {
|
|
5
6
|
userKey: string;
|
|
@@ -26,7 +27,7 @@ interface RemoteChannel<T extends GamePlayerEntityLike> {
|
|
|
26
27
|
* on: remoteManager.on.bind(remoteManager),
|
|
27
28
|
* once: remoteManager.once.bind(remoteManager),
|
|
28
29
|
* emit: (e) => {
|
|
29
|
-
* const entity = getEntity(e.targetDeviceId)
|
|
30
|
+
* const entity = remoteManager.getEntity(e.targetDeviceId)
|
|
30
31
|
* if (!entity) {
|
|
31
32
|
* console.error('entity not found')
|
|
32
33
|
* return
|
|
@@ -35,9 +36,24 @@ interface RemoteChannel<T extends GamePlayerEntityLike> {
|
|
|
35
36
|
* },
|
|
36
37
|
* } satisfies Adaptor
|
|
37
38
|
*
|
|
39
|
+
* export const remote = new Remote<RemoteFuncsFromServer, RemoteFuncsFromClient>(
|
|
40
|
+
* remoteAdaptor,
|
|
41
|
+
* {
|
|
42
|
+
* deviceId: 'server',
|
|
43
|
+
* }
|
|
44
|
+
* )
|
|
45
|
+
*
|
|
46
|
+
* remote.register('initConnection', async () => {
|
|
47
|
+
* // 什么也不干,单纯的让客户端在服务端“备案”
|
|
48
|
+
* })
|
|
49
|
+
*
|
|
50
|
+
* export const getEntity = remoteManager.getEntity.bind(remoteManager)
|
|
51
|
+
* export const getIdByEntity = remoteManager.getIdByEntity.bind(remoteManager)
|
|
52
|
+
* export const waitForRegister = remoteManager.waitForRegister.bind(remoteManager)
|
|
53
|
+
* export const remoteTo = remoteManager.remoteTo.bind(remoteManager)
|
|
38
54
|
* ```
|
|
39
55
|
*/
|
|
40
|
-
|
|
56
|
+
declare class ServerSideRemoteChannelEventManager<T extends GamePlayerEntityLike> extends EventEmitter<{
|
|
41
57
|
[key: string]: [AdaptorPackageData];
|
|
42
58
|
}> {
|
|
43
59
|
entityMap: [string, T][];
|
|
@@ -62,4 +78,5 @@ export declare class ServerSideRemoteChannelEventManager<T extends GamePlayerEnt
|
|
|
62
78
|
timeoutMs: number;
|
|
63
79
|
};
|
|
64
80
|
}
|
|
65
|
-
|
|
81
|
+
|
|
82
|
+
export { ServerSideRemoteChannelEventManager };
|
|
@@ -1,90 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { isRemoteAdaptorData } from '../../remote';
|
|
3
|
-
import { isRemoteValueEvent } from '../../remoteValue/exposeToRemote';
|
|
4
|
-
/**
|
|
5
|
-
* 这是 [dao3 游戏](https://dao3.fun/) 代码服务端适配器。
|
|
6
|
-
* ```ts
|
|
7
|
-
* const remoteManager = new ServerSideRemoteChannelEventManager(remoteChannel)
|
|
8
|
-
*
|
|
9
|
-
* world.onPlayerLeave(
|
|
10
|
-
* remoteManager.onPlayerLeave.bind(remoteManager)
|
|
11
|
-
* )
|
|
12
|
-
*
|
|
13
|
-
* export const remoteAdaptor = {
|
|
14
|
-
* every: remoteManager.onEvery.bind(remoteManager),
|
|
15
|
-
* off: remoteManager.off.bind(remoteManager),
|
|
16
|
-
* on: remoteManager.on.bind(remoteManager),
|
|
17
|
-
* once: remoteManager.once.bind(remoteManager),
|
|
18
|
-
* emit: (e) => {
|
|
19
|
-
* const entity = getEntity(e.targetDeviceId)
|
|
20
|
-
* if (!entity) {
|
|
21
|
-
* console.error('entity not found')
|
|
22
|
-
* return
|
|
23
|
-
* }
|
|
24
|
-
* remoteChannel.sendClientEvent(entity, e as unknown as JSONValue)
|
|
25
|
-
* },
|
|
26
|
-
* } satisfies Adaptor
|
|
27
|
-
*
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export class ServerSideRemoteChannelEventManager extends EventEmitter {
|
|
31
|
-
constructor(remoteChannel) {
|
|
32
|
-
super();
|
|
33
|
-
Object.defineProperty(this, "entityMap", {
|
|
34
|
-
enumerable: true,
|
|
35
|
-
configurable: true,
|
|
36
|
-
writable: true,
|
|
37
|
-
value: []
|
|
38
|
-
});
|
|
39
|
-
remoteChannel.onServerEvent((e) => {
|
|
40
|
-
const { args } = e;
|
|
41
|
-
if (!isRemoteAdaptorData(args)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const prevItem = this.entityMap.find((item) => item[1].player.userKey === e.entity.player.userKey);
|
|
45
|
-
if (prevItem) {
|
|
46
|
-
prevItem[0] = args.deviceId;
|
|
47
|
-
prevItem[1] = e.entity;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
this.entityMap.push([args.deviceId, e.entity]);
|
|
51
|
-
}
|
|
52
|
-
if (!isRemoteValueEvent(args.name)) {
|
|
53
|
-
this.emit('__remote_every__', args);
|
|
54
|
-
}
|
|
55
|
-
this.emit(args.name, args);
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
onPlayerLeave(e) {
|
|
59
|
-
this.entityMap = this.entityMap.filter((item) => item[1].player.userKey !== e.entity.player.userKey);
|
|
60
|
-
}
|
|
61
|
-
onEvery(fn) {
|
|
62
|
-
this.on('__remote_every__', fn);
|
|
63
|
-
}
|
|
64
|
-
waitForRegister(entity) {
|
|
65
|
-
return new Promise((resolve) => {
|
|
66
|
-
if (this.entityMap.some(([_, en]) => en.player.userKey === entity.player.userKey)) {
|
|
67
|
-
resolve();
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
this.once('__remote_every__', () => {
|
|
71
|
-
resolve();
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
getEntity(deviceId) {
|
|
76
|
-
var _a;
|
|
77
|
-
return (_a = this.entityMap.find((item) => item[0] === deviceId)) === null || _a === void 0 ? void 0 : _a[1];
|
|
78
|
-
}
|
|
79
|
-
getIdByEntity(entity) {
|
|
80
|
-
var _a;
|
|
81
|
-
return (_a = this.entityMap.find((item) => item[1].player.userKey === entity.player.userKey)) === null || _a === void 0 ? void 0 : _a[0];
|
|
82
|
-
}
|
|
83
|
-
remoteTo({ target, ...rest }) {
|
|
84
|
-
return {
|
|
85
|
-
targetDeviceId: this.getIdByEntity(target),
|
|
86
|
-
...rest,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
}
|
|
1
|
+
"use strict";var d=Object.create;var a=Object.defineProperty;var u=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var v=Object.getPrototypeOf,f=Object.prototype.hasOwnProperty;var l=(r,t)=>{for(var e in t)a(r,e,{get:t[e],enumerable:!0})},o=(r,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of g(t))!f.call(r,n)&&n!==e&&a(r,n,{get:()=>t[n],enumerable:!(i=u(t,n))||i.enumerable});return r};var c=(r,t,e)=>(e=r!=null?d(v(r)):{},o(t||!r||!r.__esModule?a(e,"default",{value:r,enumerable:!0}):e,r)),h=r=>o(a({},"__esModule",{value:!0}),r);var T={};l(T,{ServerSideRemoteChannelEventManager:()=>_});module.exports=h(T);var y=c(require("eventemitter3")),s=require("../../remote"),m=require("../../remoteValue/exposeToRemote");class _ extends y.default{entityMap=[];constructor(t){super(),t.onServerEvent(e=>{const{args:i}=e;if(!(0,s.isRemoteAdaptorData)(i))return;const n=this.entityMap.find(p=>p[1].player.userKey===e.entity.player.userKey);n?(n[0]=i.deviceId,n[1]=e.entity):this.entityMap.push([i.deviceId,e.entity]),(0,m.isRemoteValueEvent)(i.name)||this.emit("__remote_every__",i),this.emit(i.name,i)})}onPlayerLeave(t){this.entityMap=this.entityMap.filter(e=>e[1].player.userKey!==t.entity.player.userKey)}onEvery(t){this.on("__remote_every__",t)}waitForRegister(t){return new Promise(e=>{if(this.entityMap.some(([i,n])=>n.player.userKey===t.player.userKey)){e();return}this.once("__remote_every__",()=>{e()})})}getEntity(t){var e;return(e=this.entityMap.find(i=>i[0]===t))==null?void 0:e[1]}getIdByEntity(t){var e;return(e=this.entityMap.find(i=>i[1].player.userKey===t.player.userKey))==null?void 0:e[0]}remoteTo({target:t,...e}){return{targetDeviceId:this.getIdByEntity(t),...e}}}0&&(module.exports={ServerSideRemoteChannelEventManager});
|
|
90
2
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/dao3/server.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { isRemoteValueEvent } from '../../remoteValue/exposeToRemote'\r\nimport { type AdaptorPackageData } from '../../adaptor'\r\n\r\ninterface GamePlayerEntityLike {\r\n player: {\r\n userKey: string\r\n }\r\n}\r\n\r\ninterface RemoteChannel<T extends GamePlayerEntityLike> {\r\n onServerEvent(fn: (e: { args: unknown; entity: T }) => void): void\r\n}\r\n\r\n/**\r\n * 这是 [dao3 游戏](https://dao3.fun/) 代码服务端适配器。\r\n * ```ts\r\n * const remoteManager = new ServerSideRemoteChannelEventManager(remoteChannel)\r\n *\r\n * world.onPlayerLeave(\r\n * remoteManager.onPlayerLeave.bind(remoteManager)\r\n * )\r\n *\r\n * export const remoteAdaptor = {\r\n * every: remoteManager.onEvery.bind(remoteManager),\r\n * off: remoteManager.off.bind(remoteManager),\r\n * on: remoteManager.on.bind(remoteManager),\r\n * once: remoteManager.once.bind(remoteManager),\r\n * emit: (e) => {\r\n * const entity = remoteManager.getEntity(e.targetDeviceId)\r\n * if (!entity) {\r\n * console.error('entity not found')\r\n * return\r\n * }\r\n * remoteChannel.sendClientEvent(entity, e as unknown as JSONValue)\r\n * },\r\n * } satisfies Adaptor\r\n *\r\n * export const remote = new Remote<RemoteFuncsFromServer, RemoteFuncsFromClient>(\r\n * remoteAdaptor,\r\n * {\r\n * deviceId: 'server',\r\n * }\r\n * )\r\n *\r\n * remote.register('initConnection', async () => {\r\n * // 什么也不干,单纯的让客户端在服务端“备案”\r\n * })\r\n *\r\n * export const getEntity = remoteManager.getEntity.bind(remoteManager)\r\n * export const getIdByEntity = remoteManager.getIdByEntity.bind(remoteManager)\r\n * export const waitForRegister = remoteManager.waitForRegister.bind(remoteManager)\r\n * export const remoteTo = remoteManager.remoteTo.bind(remoteManager)\r\n * ```\r\n */\r\nexport class ServerSideRemoteChannelEventManager<\r\n T extends GamePlayerEntityLike,\r\n> extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n entityMap: [string, T][] = []\r\n\r\n constructor(remoteChannel: RemoteChannel<T>) {\r\n super()\r\n remoteChannel.onServerEvent((e) => {\r\n const { args } = e\r\n if (!isRemoteAdaptorData(args)) {\r\n return\r\n }\r\n const prevItem = this.entityMap.find(\r\n (item) => item[1].player.userKey === e.entity.player.userKey\r\n )\r\n if (prevItem) {\r\n prevItem[0] = args.deviceId\r\n prevItem[1] = e.entity\r\n } else {\r\n this.entityMap.push([args.deviceId, e.entity])\r\n }\r\n if (!isRemoteValueEvent(args.name)) {\r\n this.emit('__remote_every__', args)\r\n }\r\n this.emit(args.name, args)\r\n })\r\n }\r\n\r\n onPlayerLeave(e: { entity: T }) {\r\n this.entityMap = this.entityMap.filter(\r\n (item) => item[1].player.userKey !== e.entity.player.userKey\r\n )\r\n }\r\n\r\n onEvery(fn: (args: AdaptorPackageData) => void): void {\r\n this.on('__remote_every__', fn)\r\n }\r\n\r\n waitForRegister(entity: T) {\r\n return new Promise<void>((resolve) => {\r\n if (\r\n this.entityMap.some(\r\n ([_, en]) => en.player.userKey === entity.player.userKey\r\n )\r\n ) {\r\n resolve()\r\n return\r\n }\r\n this.once('__remote_every__', () => {\r\n resolve()\r\n })\r\n })\r\n }\r\n\r\n getEntity(deviceId: string): T | undefined {\r\n return this.entityMap.find((item) => item[0] === deviceId)?.[1]\r\n }\r\n\r\n getIdByEntity(entity: T): string | undefined {\r\n return this.entityMap.find(\r\n (item) => item[1].player.userKey === entity.player.userKey\r\n )?.[0]\r\n }\r\n\r\n remoteTo(config: { target: T }): {\r\n targetDeviceId: string\r\n }\r\n remoteTo(config: { target: T; timeoutMs: number }): {\r\n targetDeviceId: string\r\n timeoutMs: number\r\n }\r\n remoteTo({ target, ...rest }: { target: T; timeoutMs?: number }) {\r\n return {\r\n targetDeviceId: this.getIdByEntity(target),\r\n ...rest,\r\n }\r\n }\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,yCAAAE,IAAA,eAAAC,EAAAH,GAAA,IAAAI,EAAyB,4BACzBC,EAAoC,wBACpCC,EAAmC,4CAsD5B,MAAMJ,UAEH,EAAAK,OAEP,CACD,UAA2B,CAAC,EAE5B,YAAYC,EAAiC,CAC3C,MAAM,EACNA,EAAc,cAAe,GAAM,CACjC,KAAM,CAAE,KAAAC,CAAK,EAAI,EACjB,GAAI,IAAC,uBAAoBA,CAAI,EAC3B,OAEF,MAAMC,EAAW,KAAK,UAAU,KAC7BC,GAASA,EAAK,CAAC,EAAE,OAAO,UAAY,EAAE,OAAO,OAAO,OACvD,EACID,GACFA,EAAS,CAAC,EAAID,EAAK,SACnBC,EAAS,CAAC,EAAI,EAAE,QAEhB,KAAK,UAAU,KAAK,CAACD,EAAK,SAAU,EAAE,MAAM,CAAC,KAE1C,sBAAmBA,EAAK,IAAI,GAC/B,KAAK,KAAK,mBAAoBA,CAAI,EAEpC,KAAK,KAAKA,EAAK,KAAMA,CAAI,CAC3B,CAAC,CACH,CAEA,cAAcG,EAAkB,CAC9B,KAAK,UAAY,KAAK,UAAU,OAC7BD,GAASA,EAAK,CAAC,EAAE,OAAO,UAAYC,EAAE,OAAO,OAAO,OACvD,CACF,CAEA,QAAQC,EAA8C,CACpD,KAAK,GAAG,mBAAoBA,CAAE,CAChC,CAEA,gBAAgBC,EAAW,CACzB,OAAO,IAAI,QAAeC,GAAY,CACpC,GACE,KAAK,UAAU,KACb,CAAC,CAACC,EAAGC,CAAE,IAAMA,EAAG,OAAO,UAAYH,EAAO,OAAO,OACnD,EACA,CACAC,EAAQ,EACR,MACF,CACA,KAAK,KAAK,mBAAoB,IAAM,CAClCA,EAAQ,CACV,CAAC,CACH,CAAC,CACH,CAEA,UAAUG,EAAiC,CAhH7C,IAAAC,EAiHI,OAAOA,EAAA,KAAK,UAAU,KAAMR,GAASA,EAAK,CAAC,IAAMO,CAAQ,IAAlD,YAAAC,EAAsD,EAC/D,CAEA,cAAcL,EAA+B,CApH/C,IAAAK,EAqHI,OAAOA,EAAA,KAAK,UAAU,KACnBR,GAASA,EAAK,CAAC,EAAE,OAAO,UAAYG,EAAO,OAAO,OACrD,IAFO,YAAAK,EAEH,EACN,CASA,SAAS,CAAE,OAAAC,EAAQ,GAAGC,CAAK,EAAsC,CAC/D,MAAO,CACL,eAAgB,KAAK,cAAcD,CAAM,EACzC,GAAGC,CACL,CACF,CACF","names":["server_exports","__export","ServerSideRemoteChannelEventManager","__toCommonJS","import_eventemitter3","import_remote","import_exposeToRemote","EventEmitter","remoteChannel","args","prevItem","item","e","fn","entity","resolve","_","en","deviceId","_a","target","rest"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import a from"eventemitter3";import{isRemoteAdaptorData as o}from"../../remote";import{isRemoteValueEvent as y}from"../../remoteValue/exposeToRemote";class g extends a{entityMap=[];constructor(t){super(),t.onServerEvent(e=>{const{args:r}=e;if(!o(r))return;const i=this.entityMap.find(n=>n[1].player.userKey===e.entity.player.userKey);i?(i[0]=r.deviceId,i[1]=e.entity):this.entityMap.push([r.deviceId,e.entity]),y(r.name)||this.emit("__remote_every__",r),this.emit(r.name,r)})}onPlayerLeave(t){this.entityMap=this.entityMap.filter(e=>e[1].player.userKey!==t.entity.player.userKey)}onEvery(t){this.on("__remote_every__",t)}waitForRegister(t){return new Promise(e=>{if(this.entityMap.some(([r,i])=>i.player.userKey===t.player.userKey)){e();return}this.once("__remote_every__",()=>{e()})})}getEntity(t){var e;return(e=this.entityMap.find(r=>r[0]===t))==null?void 0:e[1]}getIdByEntity(t){var e;return(e=this.entityMap.find(r=>r[1].player.userKey===t.player.userKey))==null?void 0:e[0]}remoteTo({target:t,...e}){return{targetDeviceId:this.getIdByEntity(t),...e}}}export{g as ServerSideRemoteChannelEventManager};
|
|
2
|
+
//# sourceMappingURL=server.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/dao3/server.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { isRemoteValueEvent } from '../../remoteValue/exposeToRemote'\r\nimport { type AdaptorPackageData } from '../../adaptor'\r\n\r\ninterface GamePlayerEntityLike {\r\n player: {\r\n userKey: string\r\n }\r\n}\r\n\r\ninterface RemoteChannel<T extends GamePlayerEntityLike> {\r\n onServerEvent(fn: (e: { args: unknown; entity: T }) => void): void\r\n}\r\n\r\n/**\r\n * 这是 [dao3 游戏](https://dao3.fun/) 代码服务端适配器。\r\n * ```ts\r\n * const remoteManager = new ServerSideRemoteChannelEventManager(remoteChannel)\r\n *\r\n * world.onPlayerLeave(\r\n * remoteManager.onPlayerLeave.bind(remoteManager)\r\n * )\r\n *\r\n * export const remoteAdaptor = {\r\n * every: remoteManager.onEvery.bind(remoteManager),\r\n * off: remoteManager.off.bind(remoteManager),\r\n * on: remoteManager.on.bind(remoteManager),\r\n * once: remoteManager.once.bind(remoteManager),\r\n * emit: (e) => {\r\n * const entity = remoteManager.getEntity(e.targetDeviceId)\r\n * if (!entity) {\r\n * console.error('entity not found')\r\n * return\r\n * }\r\n * remoteChannel.sendClientEvent(entity, e as unknown as JSONValue)\r\n * },\r\n * } satisfies Adaptor\r\n *\r\n * export const remote = new Remote<RemoteFuncsFromServer, RemoteFuncsFromClient>(\r\n * remoteAdaptor,\r\n * {\r\n * deviceId: 'server',\r\n * }\r\n * )\r\n *\r\n * remote.register('initConnection', async () => {\r\n * // 什么也不干,单纯的让客户端在服务端“备案”\r\n * })\r\n *\r\n * export const getEntity = remoteManager.getEntity.bind(remoteManager)\r\n * export const getIdByEntity = remoteManager.getIdByEntity.bind(remoteManager)\r\n * export const waitForRegister = remoteManager.waitForRegister.bind(remoteManager)\r\n * export const remoteTo = remoteManager.remoteTo.bind(remoteManager)\r\n * ```\r\n */\r\nexport class ServerSideRemoteChannelEventManager<\r\n T extends GamePlayerEntityLike,\r\n> extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n entityMap: [string, T][] = []\r\n\r\n constructor(remoteChannel: RemoteChannel<T>) {\r\n super()\r\n remoteChannel.onServerEvent((e) => {\r\n const { args } = e\r\n if (!isRemoteAdaptorData(args)) {\r\n return\r\n }\r\n const prevItem = this.entityMap.find(\r\n (item) => item[1].player.userKey === e.entity.player.userKey\r\n )\r\n if (prevItem) {\r\n prevItem[0] = args.deviceId\r\n prevItem[1] = e.entity\r\n } else {\r\n this.entityMap.push([args.deviceId, e.entity])\r\n }\r\n if (!isRemoteValueEvent(args.name)) {\r\n this.emit('__remote_every__', args)\r\n }\r\n this.emit(args.name, args)\r\n })\r\n }\r\n\r\n onPlayerLeave(e: { entity: T }) {\r\n this.entityMap = this.entityMap.filter(\r\n (item) => item[1].player.userKey !== e.entity.player.userKey\r\n )\r\n }\r\n\r\n onEvery(fn: (args: AdaptorPackageData) => void): void {\r\n this.on('__remote_every__', fn)\r\n }\r\n\r\n waitForRegister(entity: T) {\r\n return new Promise<void>((resolve) => {\r\n if (\r\n this.entityMap.some(\r\n ([_, en]) => en.player.userKey === entity.player.userKey\r\n )\r\n ) {\r\n resolve()\r\n return\r\n }\r\n this.once('__remote_every__', () => {\r\n resolve()\r\n })\r\n })\r\n }\r\n\r\n getEntity(deviceId: string): T | undefined {\r\n return this.entityMap.find((item) => item[0] === deviceId)?.[1]\r\n }\r\n\r\n getIdByEntity(entity: T): string | undefined {\r\n return this.entityMap.find(\r\n (item) => item[1].player.userKey === entity.player.userKey\r\n )?.[0]\r\n }\r\n\r\n remoteTo(config: { target: T }): {\r\n targetDeviceId: string\r\n }\r\n remoteTo(config: { target: T; timeoutMs: number }): {\r\n targetDeviceId: string\r\n timeoutMs: number\r\n }\r\n remoteTo({ target, ...rest }: { target: T; timeoutMs?: number }) {\r\n return {\r\n targetDeviceId: this.getIdByEntity(target),\r\n ...rest,\r\n }\r\n }\r\n}\r\n"],"mappings":"AAAA,OAAOA,MAAkB,gBACzB,OAAS,uBAAAC,MAA2B,eACpC,OAAS,sBAAAC,MAA0B,mCAsD5B,MAAMC,UAEHH,CAEP,CACD,UAA2B,CAAC,EAE5B,YAAYI,EAAiC,CAC3C,MAAM,EACNA,EAAc,cAAe,GAAM,CACjC,KAAM,CAAE,KAAAC,CAAK,EAAI,EACjB,GAAI,CAACJ,EAAoBI,CAAI,EAC3B,OAEF,MAAMC,EAAW,KAAK,UAAU,KAC7BC,GAASA,EAAK,CAAC,EAAE,OAAO,UAAY,EAAE,OAAO,OAAO,OACvD,EACID,GACFA,EAAS,CAAC,EAAID,EAAK,SACnBC,EAAS,CAAC,EAAI,EAAE,QAEhB,KAAK,UAAU,KAAK,CAACD,EAAK,SAAU,EAAE,MAAM,CAAC,EAE1CH,EAAmBG,EAAK,IAAI,GAC/B,KAAK,KAAK,mBAAoBA,CAAI,EAEpC,KAAK,KAAKA,EAAK,KAAMA,CAAI,CAC3B,CAAC,CACH,CAEA,cAAcG,EAAkB,CAC9B,KAAK,UAAY,KAAK,UAAU,OAC7BD,GAASA,EAAK,CAAC,EAAE,OAAO,UAAYC,EAAE,OAAO,OAAO,OACvD,CACF,CAEA,QAAQC,EAA8C,CACpD,KAAK,GAAG,mBAAoBA,CAAE,CAChC,CAEA,gBAAgBC,EAAW,CACzB,OAAO,IAAI,QAAeC,GAAY,CACpC,GACE,KAAK,UAAU,KACb,CAAC,CAACC,EAAGC,CAAE,IAAMA,EAAG,OAAO,UAAYH,EAAO,OAAO,OACnD,EACA,CACAC,EAAQ,EACR,MACF,CACA,KAAK,KAAK,mBAAoB,IAAM,CAClCA,EAAQ,CACV,CAAC,CACH,CAAC,CACH,CAEA,UAAUG,EAAiC,CAhH7C,IAAAC,EAiHI,OAAOA,EAAA,KAAK,UAAU,KAAMR,GAASA,EAAK,CAAC,IAAMO,CAAQ,IAAlD,YAAAC,EAAsD,EAC/D,CAEA,cAAcL,EAA+B,CApH/C,IAAAK,EAqHI,OAAOA,EAAA,KAAK,UAAU,KACnBR,GAASA,EAAK,CAAC,EAAE,OAAO,UAAYG,EAAO,OAAO,OACrD,IAFO,YAAAK,EAEH,EACN,CASA,SAAS,CAAE,OAAAC,EAAQ,GAAGC,CAAK,EAAsC,CAC/D,MAAO,CACL,eAAgB,KAAK,cAAcD,CAAM,EACzC,GAAGC,CACL,CACF,CACF","names":["EventEmitter","isRemoteAdaptorData","isRemoteValueEvent","ServerSideRemoteChannelEventManager","remoteChannel","args","prevItem","item","e","fn","entity","resolve","_","en","deviceId","_a","target","rest"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var r=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var m=(_,e)=>{for(var E in e)o(_,E,{get:e[E],enumerable:!0})},N=(_,e,E,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of r(e))!c.call(_,t)&&t!==E&&o(_,t,{get:()=>e[t],enumerable:!(n=s(e,t))||n.enumerable});return _};var S=_=>N(o({},"__esModule",{value:!0}),_);var G={};m(G,{KEYOF_GET_ID:()=>x,MESSENGER_EVENT_NAME:()=>g,MESSENGER_KEY:()=>p});module.exports=S(G);const g="__remote-messenger-event__",p="__remote_messenger__",x="__get-webcontents-id__";0&&(module.exports={KEYOF_GET_ID,MESSENGER_EVENT_NAME,MESSENGER_KEY});
|
|
2
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/constants.ts"],"sourcesContent":["export const MESSENGER_EVENT_NAME = '__remote-messenger-event__'\r\nexport const MESSENGER_KEY = '__remote_messenger__'\r\nexport const KEYOF_GET_ID = '__get-webcontents-id__'\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,EAAA,yBAAAC,EAAA,kBAAAC,IAAA,eAAAC,EAAAL,GAAO,MAAMG,EAAuB,6BACvBC,EAAgB,uBAChBF,EAAe","names":["constants_exports","__export","KEYOF_GET_ID","MESSENGER_EVENT_NAME","MESSENGER_KEY","__toCommonJS"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/constants.ts"],"sourcesContent":["export const MESSENGER_EVENT_NAME = '__remote-messenger-event__'\r\nexport const MESSENGER_KEY = '__remote_messenger__'\r\nexport const KEYOF_GET_ID = '__get-webcontents-id__'\r\n"],"mappings":"AAAO,MAAMA,EAAuB,6BACvBC,EAAgB,uBAChBC,EAAe","names":["MESSENGER_EVENT_NAME","MESSENGER_KEY","KEYOF_GET_ID"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdaptorPackageData, Adaptor } from '../../adaptor.mjs';
|
|
2
|
+
|
|
3
|
+
declare function onElectronMainEmit(data: AdaptorPackageData): void;
|
|
4
|
+
interface Options {
|
|
5
|
+
onEmit?: (data: AdaptorPackageData) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function createElectronMainAdaptor(options?: Options): Adaptor;
|
|
8
|
+
declare function initMessengerInMain(): void;
|
|
9
|
+
|
|
10
|
+
export { createElectronMainAdaptor, initMessengerInMain, onElectronMainEmit };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AdaptorPackageData, Adaptor } from '../../adaptor.js';
|
|
2
|
+
|
|
3
|
+
declare function onElectronMainEmit(data: AdaptorPackageData): void;
|
|
4
|
+
interface Options {
|
|
5
|
+
onEmit?: (data: AdaptorPackageData) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function createElectronMainAdaptor(options?: Options): Adaptor;
|
|
8
|
+
declare function initMessengerInMain(): void;
|
|
9
|
+
|
|
10
|
+
export { createElectronMainAdaptor, initMessengerInMain, onElectronMainEmit };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var p=Object.create;var E=Object.defineProperty;var _=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var M=(e,n)=>{for(var t in n)E(e,t,{get:n[t],enumerable:!0})},d=(e,n,t,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of f(n))!g.call(e,r)&&r!==t&&E(e,r,{get:()=>n[r],enumerable:!(o=_(n,r))||o.enumerable});return e};var l=(e,n,t)=>(t=e!=null?p(A(e)):{},d(n||!e||!e.__esModule?E(t,"default",{value:e,enumerable:!0}):t,e)),v=e=>d(E({},"__esModule",{value:!0}),e);var V={};M(V,{createElectronMainAdaptor:()=>D,initMessengerInMain:()=>w,onElectronMainEmit:()=>m});module.exports=v(V);var s=l(require("eventemitter3")),a=require("electron"),c=require("../../remote"),i=require("./constants");class N extends s.default{EVERY_EVENT_NAME="__remote_every__";constructor(){super(),a.ipcMain.on(i.MESSENGER_EVENT_NAME,(n,t)=>{(0,c.isRemoteAdaptorData)(t)&&(this.emit(t.name,t),this.emit(this.EVERY_EVENT_NAME,t))})}onEvery(n){this.on(this.EVERY_EVENT_NAME,n)}}function m(e){const t=a.BrowserWindow.getAllWindows().find(o=>o.webContents.id.toString()===e.targetDeviceId);t==null||t.webContents.send(i.MESSENGER_EVENT_NAME,e)}function D(e){const n=(e==null?void 0:e.onEmit)??m,t=new N;return{every:t.onEvery.bind(t),on:t.on.bind(t),once:t.once.bind(t),off:t.off.bind(t),emit:n}}function w(){a.ipcMain.handle(i.KEYOF_GET_ID,e=>e.sender.id.toString())}0&&(module.exports={createElectronMainAdaptor,initMessengerInMain,onElectronMainEmit});
|
|
2
|
+
//# sourceMappingURL=main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/main.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\n\r\nimport { BrowserWindow, ipcMain } from 'electron'\r\nimport { Adaptor, AdaptorPackageData } from '../../adaptor'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { KEYOF_GET_ID, MESSENGER_EVENT_NAME } from './constants'\r\n\r\nclass RemoteEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n EVERY_EVENT_NAME = '__remote_every__'\r\n\r\n constructor() {\r\n super()\r\n ipcMain.on(MESSENGER_EVENT_NAME, (_, data) => {\r\n if (isRemoteAdaptorData(data)) {\r\n this.emit(data.name, data)\r\n // 一定要抛出 every 事件,remote 包基于此处理远端的响应\r\n this.emit(this.EVERY_EVENT_NAME, data)\r\n }\r\n })\r\n }\r\n\r\n onEvery(fn: (data: AdaptorPackageData) => void) {\r\n this.on(this.EVERY_EVENT_NAME, fn)\r\n }\r\n}\r\n\r\nexport function onElectronMainEmit(data: AdaptorPackageData) {\r\n // 主进程通过 webContents 发送消息到渲染进程\r\n const allWindows = BrowserWindow.getAllWindows()\r\n const win = allWindows.find(\r\n (w) => w.webContents.id.toString() === data.targetDeviceId\r\n )\r\n win?.webContents.send(MESSENGER_EVENT_NAME, data)\r\n}\r\n\r\ninterface Options {\r\n onEmit?: (data: AdaptorPackageData) => void\r\n}\r\n\r\nexport function createElectronMainAdaptor(options?: Options) {\r\n const onEmit = options?.onEmit ?? onElectronMainEmit\r\n const remoteEventManager = new RemoteEventManager()\r\n\r\n const adaptor: Adaptor = {\r\n every: remoteEventManager.onEvery.bind(remoteEventManager),\r\n on: remoteEventManager.on.bind(remoteEventManager),\r\n once: remoteEventManager.once.bind(remoteEventManager),\r\n off: remoteEventManager.off.bind(remoteEventManager),\r\n emit: onEmit,\r\n }\r\n\r\n return adaptor\r\n}\r\n\r\nexport function initMessengerInMain() {\r\n ipcMain.handle(KEYOF_GET_ID, (event) => event.sender.id.toString())\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,+BAAAE,EAAA,wBAAAC,EAAA,uBAAAC,IAAA,eAAAC,EAAAL,GAAA,IAAAM,EAAyB,4BAEzBC,EAAuC,oBAEvCC,EAAoC,wBACpCC,EAAmD,uBAEnD,MAAMC,UAA2B,EAAAC,OAE9B,CACD,iBAAmB,mBAEnB,aAAc,CACZ,MAAM,EACN,UAAQ,GAAG,uBAAsB,CAACC,EAAGC,IAAS,IACxC,uBAAoBA,CAAI,IAC1B,KAAK,KAAKA,EAAK,KAAMA,CAAI,EAEzB,KAAK,KAAK,KAAK,iBAAkBA,CAAI,EAEzC,CAAC,CACH,CAEA,QAAQC,EAAwC,CAC9C,KAAK,GAAG,KAAK,iBAAkBA,CAAE,CACnC,CACF,CAEO,SAASV,EAAmBS,EAA0B,CAG3D,MAAME,EADa,gBAAc,cAAc,EACxB,KACpBC,GAAMA,EAAE,YAAY,GAAG,SAAS,IAAMH,EAAK,cAC9C,EACAE,GAAA,MAAAA,EAAK,YAAY,KAAK,uBAAsBF,EAC9C,CAMO,SAASX,EAA0Be,EAAmB,CAC3D,MAAMC,GAASD,GAAA,YAAAA,EAAS,SAAUb,EAC5Be,EAAqB,IAAIT,EAU/B,MARyB,CACvB,MAAOS,EAAmB,QAAQ,KAAKA,CAAkB,EACzD,GAAIA,EAAmB,GAAG,KAAKA,CAAkB,EACjD,KAAMA,EAAmB,KAAK,KAAKA,CAAkB,EACrD,IAAKA,EAAmB,IAAI,KAAKA,CAAkB,EACnD,KAAMD,CACR,CAGF,CAEO,SAASf,GAAsB,CACpC,UAAQ,OAAO,eAAeiB,GAAUA,EAAM,OAAO,GAAG,SAAS,CAAC,CACpE","names":["main_exports","__export","createElectronMainAdaptor","initMessengerInMain","onElectronMainEmit","__toCommonJS","import_eventemitter3","import_electron","import_remote","import_constants","RemoteEventManager","EventEmitter","_","data","fn","win","w","options","onEmit","remoteEventManager","event"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import i from"eventemitter3";import{BrowserWindow as E,ipcMain as r}from"electron";import{isRemoteAdaptorData as d}from"../../remote";import{KEYOF_GET_ID as s,MESSENGER_EVENT_NAME as a}from"./constants";class c extends i{EVERY_EVENT_NAME="__remote_every__";constructor(){super(),r.on(a,(n,t)=>{d(t)&&(this.emit(t.name,t),this.emit(this.EVERY_EVENT_NAME,t))})}onEvery(n){this.on(this.EVERY_EVENT_NAME,n)}}function m(e){const t=E.getAllWindows().find(o=>o.webContents.id.toString()===e.targetDeviceId);t==null||t.webContents.send(a,e)}function v(e){const n=(e==null?void 0:e.onEmit)??m,t=new c;return{every:t.onEvery.bind(t),on:t.on.bind(t),once:t.once.bind(t),off:t.off.bind(t),emit:n}}function N(){r.handle(s,e=>e.sender.id.toString())}export{v as createElectronMainAdaptor,N as initMessengerInMain,m as onElectronMainEmit};
|
|
2
|
+
//# sourceMappingURL=main.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/main.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\n\r\nimport { BrowserWindow, ipcMain } from 'electron'\r\nimport { Adaptor, AdaptorPackageData } from '../../adaptor'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { KEYOF_GET_ID, MESSENGER_EVENT_NAME } from './constants'\r\n\r\nclass RemoteEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n EVERY_EVENT_NAME = '__remote_every__'\r\n\r\n constructor() {\r\n super()\r\n ipcMain.on(MESSENGER_EVENT_NAME, (_, data) => {\r\n if (isRemoteAdaptorData(data)) {\r\n this.emit(data.name, data)\r\n // 一定要抛出 every 事件,remote 包基于此处理远端的响应\r\n this.emit(this.EVERY_EVENT_NAME, data)\r\n }\r\n })\r\n }\r\n\r\n onEvery(fn: (data: AdaptorPackageData) => void) {\r\n this.on(this.EVERY_EVENT_NAME, fn)\r\n }\r\n}\r\n\r\nexport function onElectronMainEmit(data: AdaptorPackageData) {\r\n // 主进程通过 webContents 发送消息到渲染进程\r\n const allWindows = BrowserWindow.getAllWindows()\r\n const win = allWindows.find(\r\n (w) => w.webContents.id.toString() === data.targetDeviceId\r\n )\r\n win?.webContents.send(MESSENGER_EVENT_NAME, data)\r\n}\r\n\r\ninterface Options {\r\n onEmit?: (data: AdaptorPackageData) => void\r\n}\r\n\r\nexport function createElectronMainAdaptor(options?: Options) {\r\n const onEmit = options?.onEmit ?? onElectronMainEmit\r\n const remoteEventManager = new RemoteEventManager()\r\n\r\n const adaptor: Adaptor = {\r\n every: remoteEventManager.onEvery.bind(remoteEventManager),\r\n on: remoteEventManager.on.bind(remoteEventManager),\r\n once: remoteEventManager.once.bind(remoteEventManager),\r\n off: remoteEventManager.off.bind(remoteEventManager),\r\n emit: onEmit,\r\n }\r\n\r\n return adaptor\r\n}\r\n\r\nexport function initMessengerInMain() {\r\n ipcMain.handle(KEYOF_GET_ID, (event) => event.sender.id.toString())\r\n}\r\n"],"mappings":"AAAA,OAAOA,MAAkB,gBAEzB,OAAS,iBAAAC,EAAe,WAAAC,MAAe,WAEvC,OAAS,uBAAAC,MAA2B,eACpC,OAAS,gBAAAC,EAAc,wBAAAC,MAA4B,cAEnD,MAAMC,UAA2BN,CAE9B,CACD,iBAAmB,mBAEnB,aAAc,CACZ,MAAM,EACNE,EAAQ,GAAGG,EAAsB,CAACE,EAAGC,IAAS,CACxCL,EAAoBK,CAAI,IAC1B,KAAK,KAAKA,EAAK,KAAMA,CAAI,EAEzB,KAAK,KAAK,KAAK,iBAAkBA,CAAI,EAEzC,CAAC,CACH,CAEA,QAAQC,EAAwC,CAC9C,KAAK,GAAG,KAAK,iBAAkBA,CAAE,CACnC,CACF,CAEO,SAASC,EAAmBF,EAA0B,CAG3D,MAAMG,EADaV,EAAc,cAAc,EACxB,KACpBW,GAAMA,EAAE,YAAY,GAAG,SAAS,IAAMJ,EAAK,cAC9C,EACAG,GAAA,MAAAA,EAAK,YAAY,KAAKN,EAAsBG,EAC9C,CAMO,SAASK,EAA0BC,EAAmB,CAC3D,MAAMC,GAASD,GAAA,YAAAA,EAAS,SAAUJ,EAC5BM,EAAqB,IAAIV,EAU/B,MARyB,CACvB,MAAOU,EAAmB,QAAQ,KAAKA,CAAkB,EACzD,GAAIA,EAAmB,GAAG,KAAKA,CAAkB,EACjD,KAAMA,EAAmB,KAAK,KAAKA,CAAkB,EACrD,IAAKA,EAAmB,IAAI,KAAKA,CAAkB,EACnD,KAAMD,CACR,CAGF,CAEO,SAASE,GAAsB,CACpCf,EAAQ,OAAOE,EAAec,GAAUA,EAAM,OAAO,GAAG,SAAS,CAAC,CACpE","names":["EventEmitter","BrowserWindow","ipcMain","isRemoteAdaptorData","KEYOF_GET_ID","MESSENGER_EVENT_NAME","RemoteEventManager","_","data","fn","onElectronMainEmit","win","w","createElectronMainAdaptor","options","onEmit","remoteEventManager","initMessengerInMain","event"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var o=Object.defineProperty;var a=Object.getOwnPropertyDescriptor;var g=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var M=(n,e)=>{for(var r in e)o(n,r,{get:e[r],enumerable:!0})},f=(n,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of g(e))!d.call(n,s)&&s!==r&&o(n,s,{get:()=>e[s],enumerable:!(i=a(e,s))||i.enumerable});return n};var E=n=>f(o({},"__esModule",{value:!0}),n);var m={};M(m,{getMessenger:()=>c});module.exports=E(m);var t=require("./constants");function c(){return window[t.MESSENGER_KEY]}0&&(module.exports={getMessenger});
|
|
2
|
+
//# sourceMappingURL=messenger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/messenger.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\n\r\nimport { MESSENGER_KEY } from './constants'\r\n\r\ninterface Messenger {\r\n postMessage: (data: any) => void\r\n getId: () => Promise<string>\r\n on: (channel: string, listener: (...args: any[]) => void) => void\r\n}\r\n\r\nexport function getMessenger() {\r\n return window[MESSENGER_KEY as keyof Window] as Messenger\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,kBAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAA8B,uBAQvB,SAASF,GAAe,CAC7B,OAAO,OAAO,eAA6B,CAC7C","names":["messenger_exports","__export","getMessenger","__toCommonJS","import_constants"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/messenger.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\n\r\nimport { MESSENGER_KEY } from './constants'\r\n\r\ninterface Messenger {\r\n postMessage: (data: any) => void\r\n getId: () => Promise<string>\r\n on: (channel: string, listener: (...args: any[]) => void) => void\r\n}\r\n\r\nexport function getMessenger() {\r\n return window[MESSENGER_KEY as keyof Window] as Messenger\r\n}\r\n"],"mappings":"AAEA,OAAS,iBAAAA,MAAqB,cAQvB,SAASC,GAAe,CAC7B,OAAO,OAAOD,CAA6B,CAC7C","names":["MESSENGER_KEY","getMessenger"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var r=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var i=Object.getOwnPropertyNames;var M=Object.prototype.hasOwnProperty;var _=(n,o)=>{for(var e in o)r(n,e,{get:o[e],enumerable:!0})},I=(n,o,e,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let E of i(o))!M.call(n,E)&&E!==e&&r(n,E,{get:()=>o[E],enumerable:!(s=g(o,E))||s.enumerable});return n};var d=n=>I(r({},"__esModule",{value:!0}),n);var p={};_(p,{initMessengerInPreload:()=>l});module.exports=d(p);var t=require("./constants");function l(n,o){n.exposeInMainWorld(t.MESSENGER_KEY,{postMessage:e=>{o.postMessage(t.MESSENGER_EVENT_NAME,e)},getId:()=>o.invoke(t.KEYOF_GET_ID),on:(e,s)=>{o.on(e,(E,...a)=>s(...a))}})}0&&(module.exports={initMessengerInPreload});
|
|
2
|
+
//# sourceMappingURL=preload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/preload.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\n\r\nimport { KEYOF_GET_ID, MESSENGER_EVENT_NAME, MESSENGER_KEY } from './constants'\r\n\r\n/**\r\n * 在 preload 进程中初始化 messenger 对象\r\n */\r\nexport function initMessengerInPreload(\r\n contextBridge: Electron.ContextBridge,\r\n ipcRenderer: Electron.IpcRenderer\r\n) {\r\n contextBridge.exposeInMainWorld(MESSENGER_KEY, {\r\n postMessage: (data: any) => {\r\n ipcRenderer.postMessage(MESSENGER_EVENT_NAME, data)\r\n },\r\n getId: () => ipcRenderer.invoke(KEYOF_GET_ID),\r\n on: (channel: string, listener: (...args: any[]) => void) => {\r\n ipcRenderer.on(channel, (_, ...args) => listener(...args))\r\n },\r\n })\r\n}\r\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,4BAAAE,IAAA,eAAAC,EAAAH,GAEA,IAAAI,EAAkE,uBAK3D,SAASF,EACdG,EACAC,EACA,CACAD,EAAc,kBAAkB,gBAAe,CAC7C,YAAcE,GAAc,CAC1BD,EAAY,YAAY,uBAAsBC,CAAI,CACpD,EACA,MAAO,IAAMD,EAAY,OAAO,cAAY,EAC5C,GAAI,CAACE,EAAiBC,IAAuC,CAC3DH,EAAY,GAAGE,EAAS,CAACE,KAAMC,IAASF,EAAS,GAAGE,CAAI,CAAC,CAC3D,CACF,CAAC,CACH","names":["preload_exports","__export","initMessengerInPreload","__toCommonJS","import_constants","contextBridge","ipcRenderer","data","channel","listener","_","args"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{KEYOF_GET_ID as s,MESSENGER_EVENT_NAME as r,MESSENGER_KEY as a}from"./constants";function M(e,o){e.exposeInMainWorld(a,{postMessage:n=>{o.postMessage(r,n)},getId:()=>o.invoke(s),on:(n,E)=>{o.on(n,(g,...t)=>E(...t))}})}export{M as initMessengerInPreload};
|
|
2
|
+
//# sourceMappingURL=preload.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/preload.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\r\n\r\nimport { KEYOF_GET_ID, MESSENGER_EVENT_NAME, MESSENGER_KEY } from './constants'\r\n\r\n/**\r\n * 在 preload 进程中初始化 messenger 对象\r\n */\r\nexport function initMessengerInPreload(\r\n contextBridge: Electron.ContextBridge,\r\n ipcRenderer: Electron.IpcRenderer\r\n) {\r\n contextBridge.exposeInMainWorld(MESSENGER_KEY, {\r\n postMessage: (data: any) => {\r\n ipcRenderer.postMessage(MESSENGER_EVENT_NAME, data)\r\n },\r\n getId: () => ipcRenderer.invoke(KEYOF_GET_ID),\r\n on: (channel: string, listener: (...args: any[]) => void) => {\r\n ipcRenderer.on(channel, (_, ...args) => listener(...args))\r\n },\r\n })\r\n}\r\n"],"mappings":"AAEA,OAAS,gBAAAA,EAAc,wBAAAC,EAAsB,iBAAAC,MAAqB,cAK3D,SAASC,EACdC,EACAC,EACA,CACAD,EAAc,kBAAkBF,EAAe,CAC7C,YAAcI,GAAc,CAC1BD,EAAY,YAAYJ,EAAsBK,CAAI,CACpD,EACA,MAAO,IAAMD,EAAY,OAAOL,CAAY,EAC5C,GAAI,CAACO,EAAiBC,IAAuC,CAC3DH,EAAY,GAAGE,EAAS,CAACE,KAAMC,IAASF,EAAS,GAAGE,CAAI,CAAC,CAC3D,CACF,CAAC,CACH","names":["KEYOF_GET_ID","MESSENGER_EVENT_NAME","MESSENGER_KEY","initMessengerInPreload","contextBridge","ipcRenderer","data","channel","listener","_","args"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdaptorPackageData, Adaptor } from '../../adaptor.mjs';
|
|
2
|
+
|
|
3
|
+
declare function onElectronRendererEmit(data: AdaptorPackageData): void;
|
|
4
|
+
interface Options {
|
|
5
|
+
onEmit?: (data: AdaptorPackageData) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function createElectronRendererAdaptor(options?: Options): Adaptor;
|
|
8
|
+
|
|
9
|
+
export { createElectronRendererAdaptor, onElectronRendererEmit };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AdaptorPackageData, Adaptor } from '../../adaptor.js';
|
|
2
|
+
|
|
3
|
+
declare function onElectronRendererEmit(data: AdaptorPackageData): void;
|
|
4
|
+
interface Options {
|
|
5
|
+
onEmit?: (data: AdaptorPackageData) => void;
|
|
6
|
+
}
|
|
7
|
+
declare function createElectronRendererAdaptor(options?: Options): Adaptor;
|
|
8
|
+
|
|
9
|
+
export { createElectronRendererAdaptor, onElectronRendererEmit };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var s=Object.create;var a=Object.defineProperty;var f=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,g=Object.prototype.hasOwnProperty;var v=(e,t)=>{for(var o in t)a(e,o,{get:t[o],enumerable:!0})},i=(e,t,o,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of A(t))!g.call(e,r)&&r!==o&&a(e,r,{get:()=>t[r],enumerable:!(n=f(t,r))||n.enumerable});return e};var M=(e,t,o)=>(o=e!=null?s(_(e)):{},i(t||!e||!e.__esModule?a(o,"default",{value:e,enumerable:!0}):o,e)),N=e=>i(a({},"__esModule",{value:!0}),e);var V={};v(V,{createElectronRendererAdaptor:()=>u,onElectronRendererEmit:()=>p});module.exports=N(V);var m=M(require("eventemitter3")),d=require("../../remote"),E=require("./messenger"),c=require("./constants");class R extends m.default{EVERY_EVENT_NAME="__remote_every__";constructor(){super(),!(typeof window>"u")&&(0,E.getMessenger)().on(c.MESSENGER_EVENT_NAME,t=>{(0,d.isRemoteAdaptorData)(t)&&(this.emit(t.name,t),this.emit(this.EVERY_EVENT_NAME,t))})}onEvery(t){this.on(this.EVERY_EVENT_NAME,t)}}function p(e){(0,E.getMessenger)().postMessage(e)}function u(e){const t=(e==null?void 0:e.onEmit)??p,o=new R;return{every:o.onEvery.bind(o),on:o.on.bind(o),once:o.once.bind(o),off:o.off.bind(o),emit:t}}0&&(module.exports={createElectronRendererAdaptor,onElectronRendererEmit});
|
|
2
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/renderer.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { Adaptor, AdaptorPackageData } from '../../adaptor'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { getMessenger } from './messenger'\r\nimport { MESSENGER_EVENT_NAME } from './constants'\r\n\r\nclass RemoteEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n EVERY_EVENT_NAME = '__remote_every__'\r\n\r\n constructor() {\r\n super()\r\n if (typeof window === 'undefined') {\r\n return\r\n }\r\n getMessenger().on(MESSENGER_EVENT_NAME, (data) => {\r\n if (isRemoteAdaptorData(data)) {\r\n this.emit(data.name, data)\r\n // 一定要抛出 every 事件,remote 包基于此处理远端的响应\r\n this.emit(this.EVERY_EVENT_NAME, data)\r\n }\r\n })\r\n }\r\n\r\n onEvery(fn: (data: AdaptorPackageData) => void) {\r\n this.on(this.EVERY_EVENT_NAME, fn)\r\n }\r\n}\r\n\r\nexport function onElectronRendererEmit(data: AdaptorPackageData) {\r\n getMessenger().postMessage(data)\r\n}\r\n\r\ninterface Options {\r\n onEmit?: (data: AdaptorPackageData) => void\r\n}\r\n\r\nexport function createElectronRendererAdaptor(options?: Options) {\r\n const onEmit = options?.onEmit ?? onElectronRendererEmit\r\n const remoteEventManager = new RemoteEventManager()\r\n\r\n const adaptor: Adaptor = {\r\n every: remoteEventManager.onEvery.bind(remoteEventManager),\r\n on: remoteEventManager.on.bind(remoteEventManager),\r\n once: remoteEventManager.once.bind(remoteEventManager),\r\n off: remoteEventManager.off.bind(remoteEventManager),\r\n emit: onEmit,\r\n }\r\n\r\n return adaptor\r\n}\r\n"],"mappings":"0jBAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mCAAAE,EAAA,2BAAAC,IAAA,eAAAC,EAAAJ,GAAA,IAAAK,EAAyB,4BAEzBC,EAAoC,wBACpCC,EAA6B,uBAC7BC,EAAqC,uBAErC,MAAMC,UAA2B,EAAAC,OAE9B,CACD,iBAAmB,mBAEnB,aAAc,CACZ,MAAM,EACF,SAAO,OAAW,SAGtB,gBAAa,EAAE,GAAG,uBAAuBC,GAAS,IAC5C,uBAAoBA,CAAI,IAC1B,KAAK,KAAKA,EAAK,KAAMA,CAAI,EAEzB,KAAK,KAAK,KAAK,iBAAkBA,CAAI,EAEzC,CAAC,CACH,CAEA,QAAQC,EAAwC,CAC9C,KAAK,GAAG,KAAK,iBAAkBA,CAAE,CACnC,CACF,CAEO,SAAST,EAAuBQ,EAA0B,IAC/D,gBAAa,EAAE,YAAYA,CAAI,CACjC,CAMO,SAAST,EAA8BW,EAAmB,CAC/D,MAAMC,GAASD,GAAA,YAAAA,EAAS,SAAUV,EAC5BY,EAAqB,IAAIN,EAU/B,MARyB,CACvB,MAAOM,EAAmB,QAAQ,KAAKA,CAAkB,EACzD,GAAIA,EAAmB,GAAG,KAAKA,CAAkB,EACjD,KAAMA,EAAmB,KAAK,KAAKA,CAAkB,EACrD,IAAKA,EAAmB,IAAI,KAAKA,CAAkB,EACnD,KAAMD,CACR,CAGF","names":["renderer_exports","__export","createElectronRendererAdaptor","onElectronRendererEmit","__toCommonJS","import_eventemitter3","import_remote","import_messenger","import_constants","RemoteEventManager","EventEmitter","data","fn","options","onEmit","remoteEventManager"]}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import a from"eventemitter3";import{isRemoteAdaptorData as n}from"../../remote";import{getMessenger as r}from"./messenger";import{MESSENGER_EVENT_NAME as E}from"./constants";class i extends a{EVERY_EVENT_NAME="__remote_every__";constructor(){super(),!(typeof window>"u")&&r().on(E,e=>{n(e)&&(this.emit(e.name,e),this.emit(this.EVERY_EVENT_NAME,e))})}onEvery(e){this.on(this.EVERY_EVENT_NAME,e)}}function m(o){r().postMessage(o)}function v(o){const e=(o==null?void 0:o.onEmit)??m,t=new i;return{every:t.onEvery.bind(t),on:t.on.bind(t),once:t.once.bind(t),off:t.off.bind(t),emit:e}}export{v as createElectronRendererAdaptor,m as onElectronRendererEmit};
|
|
2
|
+
//# sourceMappingURL=renderer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/adaptors/electron/renderer.ts"],"sourcesContent":["import EventEmitter from 'eventemitter3'\r\nimport { Adaptor, AdaptorPackageData } from '../../adaptor'\r\nimport { isRemoteAdaptorData } from '../../remote'\r\nimport { getMessenger } from './messenger'\r\nimport { MESSENGER_EVENT_NAME } from './constants'\r\n\r\nclass RemoteEventManager extends EventEmitter<{\r\n [key: string]: [AdaptorPackageData]\r\n}> {\r\n EVERY_EVENT_NAME = '__remote_every__'\r\n\r\n constructor() {\r\n super()\r\n if (typeof window === 'undefined') {\r\n return\r\n }\r\n getMessenger().on(MESSENGER_EVENT_NAME, (data) => {\r\n if (isRemoteAdaptorData(data)) {\r\n this.emit(data.name, data)\r\n // 一定要抛出 every 事件,remote 包基于此处理远端的响应\r\n this.emit(this.EVERY_EVENT_NAME, data)\r\n }\r\n })\r\n }\r\n\r\n onEvery(fn: (data: AdaptorPackageData) => void) {\r\n this.on(this.EVERY_EVENT_NAME, fn)\r\n }\r\n}\r\n\r\nexport function onElectronRendererEmit(data: AdaptorPackageData) {\r\n getMessenger().postMessage(data)\r\n}\r\n\r\ninterface Options {\r\n onEmit?: (data: AdaptorPackageData) => void\r\n}\r\n\r\nexport function createElectronRendererAdaptor(options?: Options) {\r\n const onEmit = options?.onEmit ?? onElectronRendererEmit\r\n const remoteEventManager = new RemoteEventManager()\r\n\r\n const adaptor: Adaptor = {\r\n every: remoteEventManager.onEvery.bind(remoteEventManager),\r\n on: remoteEventManager.on.bind(remoteEventManager),\r\n once: remoteEventManager.once.bind(remoteEventManager),\r\n off: remoteEventManager.off.bind(remoteEventManager),\r\n emit: onEmit,\r\n }\r\n\r\n return adaptor\r\n}\r\n"],"mappings":"AAAA,OAAOA,MAAkB,gBAEzB,OAAS,uBAAAC,MAA2B,eACpC,OAAS,gBAAAC,MAAoB,cAC7B,OAAS,wBAAAC,MAA4B,cAErC,MAAMC,UAA2BJ,CAE9B,CACD,iBAAmB,mBAEnB,aAAc,CACZ,MAAM,EACF,SAAO,OAAW,MAGtBE,EAAa,EAAE,GAAGC,EAAuBE,GAAS,CAC5CJ,EAAoBI,CAAI,IAC1B,KAAK,KAAKA,EAAK,KAAMA,CAAI,EAEzB,KAAK,KAAK,KAAK,iBAAkBA,CAAI,EAEzC,CAAC,CACH,CAEA,QAAQC,EAAwC,CAC9C,KAAK,GAAG,KAAK,iBAAkBA,CAAE,CACnC,CACF,CAEO,SAASC,EAAuBF,EAA0B,CAC/DH,EAAa,EAAE,YAAYG,CAAI,CACjC,CAMO,SAASG,EAA8BC,EAAmB,CAC/D,MAAMC,GAASD,GAAA,YAAAA,EAAS,SAAUF,EAC5BI,EAAqB,IAAIP,EAU/B,MARyB,CACvB,MAAOO,EAAmB,QAAQ,KAAKA,CAAkB,EACzD,GAAIA,EAAmB,GAAG,KAAKA,CAAkB,EACjD,KAAMA,EAAmB,KAAK,KAAKA,CAAkB,EACrD,IAAKA,EAAmB,IAAI,KAAKA,CAAkB,EACnD,KAAMD,CACR,CAGF","names":["EventEmitter","isRemoteAdaptorData","getMessenger","MESSENGER_EVENT_NAME","RemoteEventManager","data","fn","onElectronRendererEmit","createElectronRendererAdaptor","options","onEmit","remoteEventManager"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import EventEmitter from 'eventemitter3';
|
|
2
|
+
import { AdaptorPackageData, Adaptor } from '../adaptor.mjs';
|
|
3
|
+
|
|
4
|
+
declare class RemoteEventManager extends EventEmitter<{
|
|
5
|
+
[key: string]: [AdaptorPackageData];
|
|
6
|
+
}> {
|
|
7
|
+
EVERY_EVENT_NAME: string;
|
|
8
|
+
onEvery(fn: (data: AdaptorPackageData) => void): void;
|
|
9
|
+
}
|
|
10
|
+
declare const remoteEventManager: RemoteEventManager;
|
|
11
|
+
declare function createHttpAdaptor({ onEmit, }: {
|
|
12
|
+
onEmit: (data: AdaptorPackageData) => void;
|
|
13
|
+
}): Adaptor;
|
|
14
|
+
|
|
15
|
+
export { createHttpAdaptor, remoteEventManager };
|