@capawesome/capacitor-nodejs 0.0.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.swift +42 -0
- package/README.md +443 -0
- package/android/CMakeLists.txt +32 -0
- package/android/build.gradle +123 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/native-lib.cpp +192 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/Nodejs.java +256 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/NodejsConfig.java +30 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/NodejsPlugin.java +159 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/CustomExceptions.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/events/MessageEvent.java +27 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/options/SendOptions.java +48 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/options/StartOptions.java +81 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/classes/results/IsReadyResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/nodejs/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +432 -0
- package/dist/esm/definitions.d.ts +214 -0
- package/dist/esm/definitions.js +38 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +8 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +68 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +71 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Assets/builtin_modules/bridge/index.js +205 -0
- package/ios/Plugin/Classes/Events/MessageEvent.swift +19 -0
- package/ios/Plugin/Classes/Options/SendOptions.swift +19 -0
- package/ios/Plugin/Classes/Options/StartOptions.swift +32 -0
- package/ios/Plugin/Classes/Results/IsReadyResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +46 -0
- package/ios/Plugin/Nodejs.swift +148 -0
- package/ios/Plugin/NodejsConfig.swift +6 -0
- package/ios/Plugin/NodejsPlugin.swift +102 -0
- package/ios/Plugin/Protocols/Result.swift +6 -0
- package/ios/PluginNative/NodeRunner.mm +221 -0
- package/ios/PluginNative/bridge.cpp +225 -0
- package/ios/PluginNative/bridge.h +15 -0
- package/ios/PluginNative/include/NodeRunner.h +12 -0
- package/package.json +93 -0
- package/scripts/postinstall.js +109 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
declare module '@capacitor/cli' {
|
|
3
|
+
interface PluginsConfig {
|
|
4
|
+
Nodejs?: {
|
|
5
|
+
/**
|
|
6
|
+
* The directory of the Node.js project, relative to the Capacitor `webDir`.
|
|
7
|
+
*
|
|
8
|
+
* Only available on Android and iOS.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
* @default 'nodejs'
|
|
12
|
+
* @example 'custom-nodejs'
|
|
13
|
+
*/
|
|
14
|
+
nodeDir?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The start mode of the Node.js runtime.
|
|
17
|
+
*
|
|
18
|
+
* If set to `auto`, the Node.js runtime starts automatically when the app is launched.
|
|
19
|
+
* If set to `manual`, the Node.js runtime must be started manually using the `start(...)` method.
|
|
20
|
+
*
|
|
21
|
+
* Only available on Android and iOS.
|
|
22
|
+
*
|
|
23
|
+
* @since 0.0.1
|
|
24
|
+
* @default 'auto'
|
|
25
|
+
* @example 'manual'
|
|
26
|
+
*/
|
|
27
|
+
startMode?: 'auto' | 'manual';
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @since 0.0.1
|
|
33
|
+
*/
|
|
34
|
+
export interface NodejsPlugin {
|
|
35
|
+
/**
|
|
36
|
+
* Check if the Node.js runtime is ready to receive messages.
|
|
37
|
+
*
|
|
38
|
+
* The Node.js runtime is considered ready as soon as the Node.js project
|
|
39
|
+
* has required the `bridge` module.
|
|
40
|
+
*
|
|
41
|
+
* Only available on Android and iOS.
|
|
42
|
+
*
|
|
43
|
+
* @since 0.0.1
|
|
44
|
+
*/
|
|
45
|
+
isReady(): Promise<IsReadyResult>;
|
|
46
|
+
/**
|
|
47
|
+
* Send a message to the Node.js runtime.
|
|
48
|
+
*
|
|
49
|
+
* This method is only available when the Node.js runtime is ready.
|
|
50
|
+
* Use the `isReady()` method or the `ready` event to check if the
|
|
51
|
+
* Node.js runtime is ready.
|
|
52
|
+
*
|
|
53
|
+
* Only available on Android and iOS.
|
|
54
|
+
*
|
|
55
|
+
* @since 0.0.1
|
|
56
|
+
*/
|
|
57
|
+
send(options: SendOptions): Promise<void>;
|
|
58
|
+
/**
|
|
59
|
+
* Start the Node.js runtime manually.
|
|
60
|
+
*
|
|
61
|
+
* This method is only available if the `startMode` configuration option
|
|
62
|
+
* is set to `manual`.
|
|
63
|
+
*
|
|
64
|
+
* **Attention**: The Node.js runtime can only be started once per app
|
|
65
|
+
* launch. Stopping and restarting the Node.js runtime is not supported.
|
|
66
|
+
*
|
|
67
|
+
* Only available on Android and iOS.
|
|
68
|
+
*
|
|
69
|
+
* @since 0.0.1
|
|
70
|
+
*/
|
|
71
|
+
start(options?: StartOptions): Promise<void>;
|
|
72
|
+
/**
|
|
73
|
+
* Called when a message is received from the Node.js runtime.
|
|
74
|
+
*
|
|
75
|
+
* Only available on Android and iOS.
|
|
76
|
+
*
|
|
77
|
+
* @since 0.0.1
|
|
78
|
+
*/
|
|
79
|
+
addListener(eventName: 'message', listenerFunc: (event: MessageEvent) => void): Promise<PluginListenerHandle>;
|
|
80
|
+
/**
|
|
81
|
+
* Called when the Node.js runtime is ready to receive messages.
|
|
82
|
+
*
|
|
83
|
+
* Only available on Android and iOS.
|
|
84
|
+
*
|
|
85
|
+
* @since 0.0.1
|
|
86
|
+
*/
|
|
87
|
+
addListener(eventName: 'ready', listenerFunc: () => void): Promise<PluginListenerHandle>;
|
|
88
|
+
/**
|
|
89
|
+
* Remove all listeners for this plugin.
|
|
90
|
+
*
|
|
91
|
+
* @since 0.0.1
|
|
92
|
+
*/
|
|
93
|
+
removeAllListeners(): Promise<void>;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @since 0.0.1
|
|
97
|
+
*/
|
|
98
|
+
export interface IsReadyResult {
|
|
99
|
+
/**
|
|
100
|
+
* Whether or not the Node.js runtime is ready to receive messages.
|
|
101
|
+
*
|
|
102
|
+
* @since 0.0.1
|
|
103
|
+
* @example true
|
|
104
|
+
*/
|
|
105
|
+
ready: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @since 0.0.1
|
|
109
|
+
*/
|
|
110
|
+
export interface SendOptions {
|
|
111
|
+
/**
|
|
112
|
+
* The arguments to send to the Node.js runtime.
|
|
113
|
+
*
|
|
114
|
+
* @since 0.0.1
|
|
115
|
+
* @example ['Hello from Capacitor!']
|
|
116
|
+
*/
|
|
117
|
+
args?: MessageArg[];
|
|
118
|
+
/**
|
|
119
|
+
* The name of the event to send to the Node.js runtime.
|
|
120
|
+
*
|
|
121
|
+
* @since 0.0.1
|
|
122
|
+
* @example 'my-event'
|
|
123
|
+
*/
|
|
124
|
+
eventName: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* @since 0.0.1
|
|
128
|
+
*/
|
|
129
|
+
export interface StartOptions {
|
|
130
|
+
/**
|
|
131
|
+
* The arguments to pass to the Node.js process.
|
|
132
|
+
*
|
|
133
|
+
* @since 0.0.1
|
|
134
|
+
* @example ['--option', 'value']
|
|
135
|
+
*/
|
|
136
|
+
args?: string[];
|
|
137
|
+
/**
|
|
138
|
+
* The environment variables to set for the Node.js process.
|
|
139
|
+
*
|
|
140
|
+
* @since 0.0.1
|
|
141
|
+
* @example { MY_ENV_VAR: 'value' }
|
|
142
|
+
*/
|
|
143
|
+
env?: {
|
|
144
|
+
[key: string]: string;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* The path of the script file to run, relative to the Node.js project directory.
|
|
148
|
+
*
|
|
149
|
+
* @since 0.0.1
|
|
150
|
+
* @default The `main` field of the `package.json` file of the Node.js project.
|
|
151
|
+
* @example 'custom-main.js'
|
|
152
|
+
*/
|
|
153
|
+
script?: string;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @since 0.0.1
|
|
157
|
+
*/
|
|
158
|
+
export interface MessageEvent {
|
|
159
|
+
/**
|
|
160
|
+
* The arguments received from the Node.js runtime.
|
|
161
|
+
*
|
|
162
|
+
* @since 0.0.1
|
|
163
|
+
* @example ['Hello from Node.js!']
|
|
164
|
+
*/
|
|
165
|
+
args: MessageArg[];
|
|
166
|
+
/**
|
|
167
|
+
* The name of the event received from the Node.js runtime.
|
|
168
|
+
*
|
|
169
|
+
* @since 0.0.1
|
|
170
|
+
* @example 'my-event'
|
|
171
|
+
*/
|
|
172
|
+
eventName: string;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A single argument of a message that is exchanged with the Node.js runtime.
|
|
176
|
+
*
|
|
177
|
+
* @since 0.0.1
|
|
178
|
+
*/
|
|
179
|
+
export type MessageArg = string | number | boolean;
|
|
180
|
+
/**
|
|
181
|
+
* @since 0.0.1
|
|
182
|
+
*/
|
|
183
|
+
export declare enum ErrorCode {
|
|
184
|
+
/**
|
|
185
|
+
* The event name is missing.
|
|
186
|
+
*
|
|
187
|
+
* @since 0.0.1
|
|
188
|
+
*/
|
|
189
|
+
EventNameMissing = "EVENT_NAME_MISSING",
|
|
190
|
+
/**
|
|
191
|
+
* The Node.js runtime is already running.
|
|
192
|
+
*
|
|
193
|
+
* @since 0.0.1
|
|
194
|
+
*/
|
|
195
|
+
NodeAlreadyRunning = "NODE_ALREADY_RUNNING",
|
|
196
|
+
/**
|
|
197
|
+
* The Node.js runtime is not ready to receive messages.
|
|
198
|
+
*
|
|
199
|
+
* @since 0.0.1
|
|
200
|
+
*/
|
|
201
|
+
NodeNotReady = "NODE_NOT_READY",
|
|
202
|
+
/**
|
|
203
|
+
* The Node.js project directory was not found.
|
|
204
|
+
*
|
|
205
|
+
* @since 0.0.1
|
|
206
|
+
*/
|
|
207
|
+
ProjectNotFound = "PROJECT_NOT_FOUND",
|
|
208
|
+
/**
|
|
209
|
+
* The `startMode` configuration option is not set to `manual`.
|
|
210
|
+
*
|
|
211
|
+
* @since 0.0.1
|
|
212
|
+
*/
|
|
213
|
+
StartModeNotManual = "START_MODE_NOT_MANUAL"
|
|
214
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference types="@capacitor/cli" />
|
|
2
|
+
/**
|
|
3
|
+
* @since 0.0.1
|
|
4
|
+
*/
|
|
5
|
+
export var ErrorCode;
|
|
6
|
+
(function (ErrorCode) {
|
|
7
|
+
/**
|
|
8
|
+
* The event name is missing.
|
|
9
|
+
*
|
|
10
|
+
* @since 0.0.1
|
|
11
|
+
*/
|
|
12
|
+
ErrorCode["EventNameMissing"] = "EVENT_NAME_MISSING";
|
|
13
|
+
/**
|
|
14
|
+
* The Node.js runtime is already running.
|
|
15
|
+
*
|
|
16
|
+
* @since 0.0.1
|
|
17
|
+
*/
|
|
18
|
+
ErrorCode["NodeAlreadyRunning"] = "NODE_ALREADY_RUNNING";
|
|
19
|
+
/**
|
|
20
|
+
* The Node.js runtime is not ready to receive messages.
|
|
21
|
+
*
|
|
22
|
+
* @since 0.0.1
|
|
23
|
+
*/
|
|
24
|
+
ErrorCode["NodeNotReady"] = "NODE_NOT_READY";
|
|
25
|
+
/**
|
|
26
|
+
* The Node.js project directory was not found.
|
|
27
|
+
*
|
|
28
|
+
* @since 0.0.1
|
|
29
|
+
*/
|
|
30
|
+
ErrorCode["ProjectNotFound"] = "PROJECT_NOT_FOUND";
|
|
31
|
+
/**
|
|
32
|
+
* The `startMode` configuration option is not set to `manual`.
|
|
33
|
+
*
|
|
34
|
+
* @since 0.0.1
|
|
35
|
+
*/
|
|
36
|
+
ErrorCode["StartModeNotManual"] = "START_MODE_NOT_MANUAL";
|
|
37
|
+
})(ErrorCode || (ErrorCode = {}));
|
|
38
|
+
//# sourceMappingURL=definitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC;AAiMxC;;GAEG;AACH,MAAM,CAAN,IAAY,SA+BX;AA/BD,WAAY,SAAS;IACnB;;;;OAIG;IACH,oDAAuC,CAAA;IACvC;;;;OAIG;IACH,wDAA2C,CAAA;IAC3C;;;;OAIG;IACH,4CAA+B,CAAA;IAC/B;;;;OAIG;IACH,kDAAqC,CAAA;IACrC;;;;OAIG;IACH,yDAA4C,CAAA;AAC9C,CAAC,EA/BW,SAAS,KAAT,SAAS,QA+BpB","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\nimport type { PluginListenerHandle } from '@capacitor/core';\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n Nodejs?: {\n /**\n * The directory of the Node.js project, relative to the Capacitor `webDir`.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n * @default 'nodejs'\n * @example 'custom-nodejs'\n */\n nodeDir?: string;\n /**\n * The start mode of the Node.js runtime.\n *\n * If set to `auto`, the Node.js runtime starts automatically when the app is launched.\n * If set to `manual`, the Node.js runtime must be started manually using the `start(...)` method.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n * @default 'auto'\n * @example 'manual'\n */\n startMode?: 'auto' | 'manual';\n };\n }\n}\n\n/**\n * @since 0.0.1\n */\nexport interface NodejsPlugin {\n /**\n * Check if the Node.js runtime is ready to receive messages.\n *\n * The Node.js runtime is considered ready as soon as the Node.js project\n * has required the `bridge` module.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n */\n isReady(): Promise<IsReadyResult>;\n /**\n * Send a message to the Node.js runtime.\n *\n * This method is only available when the Node.js runtime is ready.\n * Use the `isReady()` method or the `ready` event to check if the\n * Node.js runtime is ready.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n */\n send(options: SendOptions): Promise<void>;\n /**\n * Start the Node.js runtime manually.\n *\n * This method is only available if the `startMode` configuration option\n * is set to `manual`.\n *\n * **Attention**: The Node.js runtime can only be started once per app\n * launch. Stopping and restarting the Node.js runtime is not supported.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n */\n start(options?: StartOptions): Promise<void>;\n /**\n * Called when a message is received from the Node.js runtime.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n */\n addListener(\n eventName: 'message',\n listenerFunc: (event: MessageEvent) => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Called when the Node.js runtime is ready to receive messages.\n *\n * Only available on Android and iOS.\n *\n * @since 0.0.1\n */\n addListener(\n eventName: 'ready',\n listenerFunc: () => void,\n ): Promise<PluginListenerHandle>;\n /**\n * Remove all listeners for this plugin.\n *\n * @since 0.0.1\n */\n removeAllListeners(): Promise<void>;\n}\n\n/**\n * @since 0.0.1\n */\nexport interface IsReadyResult {\n /**\n * Whether or not the Node.js runtime is ready to receive messages.\n *\n * @since 0.0.1\n * @example true\n */\n ready: boolean;\n}\n\n/**\n * @since 0.0.1\n */\nexport interface SendOptions {\n /**\n * The arguments to send to the Node.js runtime.\n *\n * @since 0.0.1\n * @example ['Hello from Capacitor!']\n */\n args?: MessageArg[];\n /**\n * The name of the event to send to the Node.js runtime.\n *\n * @since 0.0.1\n * @example 'my-event'\n */\n eventName: string;\n}\n\n/**\n * @since 0.0.1\n */\nexport interface StartOptions {\n /**\n * The arguments to pass to the Node.js process.\n *\n * @since 0.0.1\n * @example ['--option', 'value']\n */\n args?: string[];\n /**\n * The environment variables to set for the Node.js process.\n *\n * @since 0.0.1\n * @example { MY_ENV_VAR: 'value' }\n */\n env?: { [key: string]: string };\n /**\n * The path of the script file to run, relative to the Node.js project directory.\n *\n * @since 0.0.1\n * @default The `main` field of the `package.json` file of the Node.js project.\n * @example 'custom-main.js'\n */\n script?: string;\n}\n\n/**\n * @since 0.0.1\n */\nexport interface MessageEvent {\n /**\n * The arguments received from the Node.js runtime.\n *\n * @since 0.0.1\n * @example ['Hello from Node.js!']\n */\n args: MessageArg[];\n /**\n * The name of the event received from the Node.js runtime.\n *\n * @since 0.0.1\n * @example 'my-event'\n */\n eventName: string;\n}\n\n/**\n * A single argument of a message that is exchanged with the Node.js runtime.\n *\n * @since 0.0.1\n */\nexport type MessageArg = string | number | boolean;\n\n/**\n * @since 0.0.1\n */\nexport enum ErrorCode {\n /**\n * The event name is missing.\n *\n * @since 0.0.1\n */\n EventNameMissing = 'EVENT_NAME_MISSING',\n /**\n * The Node.js runtime is already running.\n *\n * @since 0.0.1\n */\n NodeAlreadyRunning = 'NODE_ALREADY_RUNNING',\n /**\n * The Node.js runtime is not ready to receive messages.\n *\n * @since 0.0.1\n */\n NodeNotReady = 'NODE_NOT_READY',\n /**\n * The Node.js project directory was not found.\n *\n * @since 0.0.1\n */\n ProjectNotFound = 'PROJECT_NOT_FOUND',\n /**\n * The `startMode` configuration option is not set to `manual`.\n *\n * @since 0.0.1\n */\n StartModeNotManual = 'START_MODE_NOT_MANUAL',\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,MAAM,GAAG,cAAc,CAAe,QAAQ,EAAE;IACpD,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;CACxD,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,CAAC","sourcesContent":["import { registerPlugin } from '@capacitor/core';\n\nimport type { NodejsPlugin } from './definitions';\n\nconst Nodejs = registerPlugin<NodejsPlugin>('Nodejs', {\n web: () => import('./web').then(m => new m.NodejsWeb()),\n});\n\nexport * from './definitions';\nexport { Nodejs };\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { IsReadyResult, NodejsPlugin } from './definitions';
|
|
3
|
+
export declare class NodejsWeb extends WebPlugin implements NodejsPlugin {
|
|
4
|
+
isReady(): Promise<IsReadyResult>;
|
|
5
|
+
send(): Promise<void>;
|
|
6
|
+
start(): Promise<void>;
|
|
7
|
+
private createUnimplementedException;
|
|
8
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';
|
|
2
|
+
export class NodejsWeb extends WebPlugin {
|
|
3
|
+
async isReady() {
|
|
4
|
+
throw this.createUnimplementedException();
|
|
5
|
+
}
|
|
6
|
+
async send() {
|
|
7
|
+
throw this.createUnimplementedException();
|
|
8
|
+
}
|
|
9
|
+
async start() {
|
|
10
|
+
throw this.createUnimplementedException();
|
|
11
|
+
}
|
|
12
|
+
createUnimplementedException() {
|
|
13
|
+
return new CapacitorException('This plugin method is not implemented on this platform.', ExceptionCode.Unimplemented);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=web.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAI/E,MAAM,OAAO,SAAU,SAAQ,SAAS;IACtC,KAAK,CAAC,OAAO;QACX,MAAM,IAAI,CAAC,4BAA4B,EAAE,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,4BAA4B,EAAE,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,4BAA4B,EAAE,CAAC;IAC5C,CAAC;IAEO,4BAA4B;QAClC,OAAO,IAAI,kBAAkB,CAC3B,yDAAyD,EACzD,aAAa,CAAC,aAAa,CAC5B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\n\nimport type { IsReadyResult, NodejsPlugin } from './definitions';\n\nexport class NodejsWeb extends WebPlugin implements NodejsPlugin {\n async isReady(): Promise<IsReadyResult> {\n throw this.createUnimplementedException();\n }\n\n async send(): Promise<void> {\n throw this.createUnimplementedException();\n }\n\n async start(): Promise<void> {\n throw this.createUnimplementedException();\n }\n\n private createUnimplementedException(): CapacitorException {\n return new CapacitorException(\n 'This plugin method is not implemented on this platform.',\n ExceptionCode.Unimplemented,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@capacitor/core');
|
|
4
|
+
|
|
5
|
+
/// <reference types="@capacitor/cli" />
|
|
6
|
+
/**
|
|
7
|
+
* @since 0.0.1
|
|
8
|
+
*/
|
|
9
|
+
exports.ErrorCode = void 0;
|
|
10
|
+
(function (ErrorCode) {
|
|
11
|
+
/**
|
|
12
|
+
* The event name is missing.
|
|
13
|
+
*
|
|
14
|
+
* @since 0.0.1
|
|
15
|
+
*/
|
|
16
|
+
ErrorCode["EventNameMissing"] = "EVENT_NAME_MISSING";
|
|
17
|
+
/**
|
|
18
|
+
* The Node.js runtime is already running.
|
|
19
|
+
*
|
|
20
|
+
* @since 0.0.1
|
|
21
|
+
*/
|
|
22
|
+
ErrorCode["NodeAlreadyRunning"] = "NODE_ALREADY_RUNNING";
|
|
23
|
+
/**
|
|
24
|
+
* The Node.js runtime is not ready to receive messages.
|
|
25
|
+
*
|
|
26
|
+
* @since 0.0.1
|
|
27
|
+
*/
|
|
28
|
+
ErrorCode["NodeNotReady"] = "NODE_NOT_READY";
|
|
29
|
+
/**
|
|
30
|
+
* The Node.js project directory was not found.
|
|
31
|
+
*
|
|
32
|
+
* @since 0.0.1
|
|
33
|
+
*/
|
|
34
|
+
ErrorCode["ProjectNotFound"] = "PROJECT_NOT_FOUND";
|
|
35
|
+
/**
|
|
36
|
+
* The `startMode` configuration option is not set to `manual`.
|
|
37
|
+
*
|
|
38
|
+
* @since 0.0.1
|
|
39
|
+
*/
|
|
40
|
+
ErrorCode["StartModeNotManual"] = "START_MODE_NOT_MANUAL";
|
|
41
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
42
|
+
|
|
43
|
+
const Nodejs = core.registerPlugin('Nodejs', {
|
|
44
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NodejsWeb()),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
class NodejsWeb extends core.WebPlugin {
|
|
48
|
+
async isReady() {
|
|
49
|
+
throw this.createUnimplementedException();
|
|
50
|
+
}
|
|
51
|
+
async send() {
|
|
52
|
+
throw this.createUnimplementedException();
|
|
53
|
+
}
|
|
54
|
+
async start() {
|
|
55
|
+
throw this.createUnimplementedException();
|
|
56
|
+
}
|
|
57
|
+
createUnimplementedException() {
|
|
58
|
+
return new core.CapacitorException('This plugin method is not implemented on this platform.', core.ExceptionCode.Unimplemented);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
63
|
+
__proto__: null,
|
|
64
|
+
NodejsWeb: NodejsWeb
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
exports.Nodejs = Nodejs;
|
|
68
|
+
//# sourceMappingURL=plugin.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * @since 0.0.1\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The event name is missing.\n *\n * @since 0.0.1\n */\n ErrorCode[\"EventNameMissing\"] = \"EVENT_NAME_MISSING\";\n /**\n * The Node.js runtime is already running.\n *\n * @since 0.0.1\n */\n ErrorCode[\"NodeAlreadyRunning\"] = \"NODE_ALREADY_RUNNING\";\n /**\n * The Node.js runtime is not ready to receive messages.\n *\n * @since 0.0.1\n */\n ErrorCode[\"NodeNotReady\"] = \"NODE_NOT_READY\";\n /**\n * The Node.js project directory was not found.\n *\n * @since 0.0.1\n */\n ErrorCode[\"ProjectNotFound\"] = \"PROJECT_NOT_FOUND\";\n /**\n * The `startMode` configuration option is not set to `manual`.\n *\n * @since 0.0.1\n */\n ErrorCode[\"StartModeNotManual\"] = \"START_MODE_NOT_MANUAL\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Nodejs = registerPlugin('Nodejs', {\n web: () => import('./web').then(m => new m.NodejsWeb()),\n});\nexport * from './definitions';\nexport { Nodejs };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class NodejsWeb extends WebPlugin {\n async isReady() {\n throw this.createUnimplementedException();\n }\n async send() {\n throw this.createUnimplementedException();\n }\n async start() {\n throw this.createUnimplementedException();\n }\n createUnimplementedException() {\n return new CapacitorException('This plugin method is not implemented on this platform.', ExceptionCode.Unimplemented);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;;AAAA;AACA;AACA;AACA;AACWA;AACX,CAAC,UAAU,SAAS,EAAE;AACtB;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;AACxD;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;AAC5D;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,cAAc,CAAC,GAAG,gBAAgB;AAChD;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,iBAAiB,CAAC,GAAG,mBAAmB;AACtD;AACA;AACA;AACA;AACA;AACA,IAAI,SAAS,CAAC,oBAAoB,CAAC,GAAG,uBAAuB;AAC7D,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACnC5B,MAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;AACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;AAC3D,CAAC;;ACFM,MAAM,SAAS,SAASC,cAAS,CAAC;AACzC,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;AACjD,IAAI;AACJ,IAAI,MAAM,IAAI,GAAG;AACjB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;AACjD,IAAI;AACJ,IAAI,MAAM,KAAK,GAAG;AAClB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;AACjD,IAAI;AACJ,IAAI,4BAA4B,GAAG;AACnC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,yDAAyD,EAAEC,kBAAa,CAAC,aAAa,CAAC;AAC7H,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
var capacitorNodejs = (function (exports, core) {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/// <reference types="@capacitor/cli" />
|
|
5
|
+
/**
|
|
6
|
+
* @since 0.0.1
|
|
7
|
+
*/
|
|
8
|
+
exports.ErrorCode = void 0;
|
|
9
|
+
(function (ErrorCode) {
|
|
10
|
+
/**
|
|
11
|
+
* The event name is missing.
|
|
12
|
+
*
|
|
13
|
+
* @since 0.0.1
|
|
14
|
+
*/
|
|
15
|
+
ErrorCode["EventNameMissing"] = "EVENT_NAME_MISSING";
|
|
16
|
+
/**
|
|
17
|
+
* The Node.js runtime is already running.
|
|
18
|
+
*
|
|
19
|
+
* @since 0.0.1
|
|
20
|
+
*/
|
|
21
|
+
ErrorCode["NodeAlreadyRunning"] = "NODE_ALREADY_RUNNING";
|
|
22
|
+
/**
|
|
23
|
+
* The Node.js runtime is not ready to receive messages.
|
|
24
|
+
*
|
|
25
|
+
* @since 0.0.1
|
|
26
|
+
*/
|
|
27
|
+
ErrorCode["NodeNotReady"] = "NODE_NOT_READY";
|
|
28
|
+
/**
|
|
29
|
+
* The Node.js project directory was not found.
|
|
30
|
+
*
|
|
31
|
+
* @since 0.0.1
|
|
32
|
+
*/
|
|
33
|
+
ErrorCode["ProjectNotFound"] = "PROJECT_NOT_FOUND";
|
|
34
|
+
/**
|
|
35
|
+
* The `startMode` configuration option is not set to `manual`.
|
|
36
|
+
*
|
|
37
|
+
* @since 0.0.1
|
|
38
|
+
*/
|
|
39
|
+
ErrorCode["StartModeNotManual"] = "START_MODE_NOT_MANUAL";
|
|
40
|
+
})(exports.ErrorCode || (exports.ErrorCode = {}));
|
|
41
|
+
|
|
42
|
+
const Nodejs = core.registerPlugin('Nodejs', {
|
|
43
|
+
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.NodejsWeb()),
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
class NodejsWeb extends core.WebPlugin {
|
|
47
|
+
async isReady() {
|
|
48
|
+
throw this.createUnimplementedException();
|
|
49
|
+
}
|
|
50
|
+
async send() {
|
|
51
|
+
throw this.createUnimplementedException();
|
|
52
|
+
}
|
|
53
|
+
async start() {
|
|
54
|
+
throw this.createUnimplementedException();
|
|
55
|
+
}
|
|
56
|
+
createUnimplementedException() {
|
|
57
|
+
return new core.CapacitorException('This plugin method is not implemented on this platform.', core.ExceptionCode.Unimplemented);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var web = /*#__PURE__*/Object.freeze({
|
|
62
|
+
__proto__: null,
|
|
63
|
+
NodejsWeb: NodejsWeb
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
exports.Nodejs = Nodejs;
|
|
67
|
+
|
|
68
|
+
return exports;
|
|
69
|
+
|
|
70
|
+
})({}, capacitorExports);
|
|
71
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n/**\n * @since 0.0.1\n */\nexport var ErrorCode;\n(function (ErrorCode) {\n /**\n * The event name is missing.\n *\n * @since 0.0.1\n */\n ErrorCode[\"EventNameMissing\"] = \"EVENT_NAME_MISSING\";\n /**\n * The Node.js runtime is already running.\n *\n * @since 0.0.1\n */\n ErrorCode[\"NodeAlreadyRunning\"] = \"NODE_ALREADY_RUNNING\";\n /**\n * The Node.js runtime is not ready to receive messages.\n *\n * @since 0.0.1\n */\n ErrorCode[\"NodeNotReady\"] = \"NODE_NOT_READY\";\n /**\n * The Node.js project directory was not found.\n *\n * @since 0.0.1\n */\n ErrorCode[\"ProjectNotFound\"] = \"PROJECT_NOT_FOUND\";\n /**\n * The `startMode` configuration option is not set to `manual`.\n *\n * @since 0.0.1\n */\n ErrorCode[\"StartModeNotManual\"] = \"START_MODE_NOT_MANUAL\";\n})(ErrorCode || (ErrorCode = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst Nodejs = registerPlugin('Nodejs', {\n web: () => import('./web').then(m => new m.NodejsWeb()),\n});\nexport * from './definitions';\nexport { Nodejs };\n//# sourceMappingURL=index.js.map","import { CapacitorException, ExceptionCode, WebPlugin } from '@capacitor/core';\nexport class NodejsWeb extends WebPlugin {\n async isReady() {\n throw this.createUnimplementedException();\n }\n async send() {\n throw this.createUnimplementedException();\n }\n async start() {\n throw this.createUnimplementedException();\n }\n createUnimplementedException() {\n return new CapacitorException('This plugin method is not implemented on this platform.', ExceptionCode.Unimplemented);\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["ErrorCode","registerPlugin","WebPlugin","CapacitorException","ExceptionCode"],"mappings":";;;IAAA;IACA;IACA;IACA;AACWA;IACX,CAAC,UAAU,SAAS,EAAE;IACtB;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,kBAAkB,CAAC,GAAG,oBAAoB;IACxD;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,oBAAoB,CAAC,GAAG,sBAAsB;IAC5D;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,cAAc,CAAC,GAAG,gBAAgB;IAChD;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,iBAAiB,CAAC,GAAG,mBAAmB;IACtD;IACA;IACA;IACA;IACA;IACA,IAAI,SAAS,CAAC,oBAAoB,CAAC,GAAG,uBAAuB;IAC7D,CAAC,EAAEA,iBAAS,KAAKA,iBAAS,GAAG,EAAE,CAAC,CAAC;;ACnC5B,UAAC,MAAM,GAAGC,mBAAc,CAAC,QAAQ,EAAE;IACxC,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,SAAS,EAAE,CAAC;IAC3D,CAAC;;ICFM,MAAM,SAAS,SAASC,cAAS,CAAC;IACzC,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;IACjD,IAAI;IACJ,IAAI,MAAM,IAAI,GAAG;IACjB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;IACjD,IAAI;IACJ,IAAI,MAAM,KAAK,GAAG;IAClB,QAAQ,MAAM,IAAI,CAAC,4BAA4B,EAAE;IACjD,IAAI;IACJ,IAAI,4BAA4B,GAAG;IACnC,QAAQ,OAAO,IAAIC,uBAAkB,CAAC,yDAAyD,EAAEC,kBAAa,CAAC,aAAa,CAAC;IAC7H,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bridge module between the Capacitor app and the Node.js runtime.
|
|
3
|
+
*
|
|
4
|
+
* Based on the `rn-bridge` module of the `nodejs-mobile-react-native`
|
|
5
|
+
* project (MIT licensed, https://github.com/nodejs-mobile/nodejs-mobile-react-native).
|
|
6
|
+
*/
|
|
7
|
+
const EventEmitter = require('events');
|
|
8
|
+
|
|
9
|
+
const NativeBridge = process._linkedBinding('capacitor_bridge');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Built-in events channel to exchange events between the Capacitor app
|
|
13
|
+
* and the Node.js app. It allows to emit user defined event types with
|
|
14
|
+
* optional arguments.
|
|
15
|
+
*/
|
|
16
|
+
const EVENT_CHANNEL = '_EVENTS_';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Built-in, one-way event channel reserved for sending events from
|
|
20
|
+
* the plugin's native layer to the Node.js app.
|
|
21
|
+
*/
|
|
22
|
+
const SYSTEM_CHANNEL = '_SYSTEM_';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The MessageCodec class provides two static methods to serialize and
|
|
26
|
+
* deserialize the data sent through the events channel. The same codec
|
|
27
|
+
* is implemented in the plugin's native layer.
|
|
28
|
+
*/
|
|
29
|
+
class MessageCodec {
|
|
30
|
+
constructor(event, ...payload) {
|
|
31
|
+
this.event = event;
|
|
32
|
+
this.payload = JSON.stringify(payload);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static serialize(event, ...payload) {
|
|
36
|
+
const envelope = new MessageCodec(event, ...payload);
|
|
37
|
+
return JSON.stringify(envelope);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
static deserialize(message) {
|
|
41
|
+
const envelope = JSON.parse(message);
|
|
42
|
+
if (typeof envelope.payload !== 'undefined') {
|
|
43
|
+
envelope.payload = JSON.parse(envelope.payload);
|
|
44
|
+
}
|
|
45
|
+
return envelope;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Channel super class. The `emit` method is renamed to `emitLocal` to
|
|
51
|
+
* clarify that emitting on this object has a local scope: it emits the
|
|
52
|
+
* event on the Node.js side only, it doesn't send the event to the
|
|
53
|
+
* Capacitor app.
|
|
54
|
+
*/
|
|
55
|
+
class ChannelSuper extends EventEmitter {
|
|
56
|
+
constructor(name) {
|
|
57
|
+
super();
|
|
58
|
+
this.name = name;
|
|
59
|
+
this.emitLocal = this.emit;
|
|
60
|
+
delete this.emit;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
emitWrapper(type, ...msg) {
|
|
64
|
+
setImmediate(() => {
|
|
65
|
+
this.emitLocal(type, ...msg);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Events channel class that supports user defined event types with
|
|
72
|
+
* optional arguments. Allows to send any serializable JavaScript object
|
|
73
|
+
* supported by `JSON.stringify()`.
|
|
74
|
+
*/
|
|
75
|
+
class EventChannel extends ChannelSuper {
|
|
76
|
+
post(event, ...msg) {
|
|
77
|
+
NativeBridge.sendMessage(this.name, MessageCodec.serialize(event, ...msg));
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
send(...msg) {
|
|
81
|
+
this.post('message', ...msg);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
processData(data) {
|
|
85
|
+
const envelope = MessageCodec.deserialize(data);
|
|
86
|
+
this.emitWrapper(envelope.event, ...envelope.payload);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Helper class to handle lock acquisition and release in system event
|
|
92
|
+
* handlers. Calls a callback after every lock has been released.
|
|
93
|
+
*/
|
|
94
|
+
class SystemEventLock {
|
|
95
|
+
constructor(callback, startingLocks) {
|
|
96
|
+
this._locksAcquired = startingLocks;
|
|
97
|
+
this._callback = callback;
|
|
98
|
+
this._hasReleased = false;
|
|
99
|
+
this._checkRelease();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
release() {
|
|
103
|
+
if (this._hasReleased) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
this._locksAcquired--;
|
|
107
|
+
this._checkRelease();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
_checkRelease() {
|
|
111
|
+
if (this._locksAcquired <= 0) {
|
|
112
|
+
this._hasReleased = true;
|
|
113
|
+
this._callback();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* System channel class. Emits `pause` and `resume` events when the app
|
|
120
|
+
* goes to the background and foreground.
|
|
121
|
+
*/
|
|
122
|
+
class SystemChannel extends ChannelSuper {
|
|
123
|
+
constructor(name) {
|
|
124
|
+
super(name);
|
|
125
|
+
this._cacheDataDir = null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
emitWrapper(type) {
|
|
129
|
+
if (type.startsWith('pause')) {
|
|
130
|
+
setImmediate(() => {
|
|
131
|
+
// The expected format for the release message is
|
|
132
|
+
// "release-pause-event|{eventId}" where eventId comes from the
|
|
133
|
+
// pause event, with the format "pause|{eventId}".
|
|
134
|
+
let releaseMessage = 'release-pause-event';
|
|
135
|
+
const eventArguments = type.split('|');
|
|
136
|
+
if (eventArguments.length >= 2) {
|
|
137
|
+
releaseMessage = releaseMessage + '|' + eventArguments[1];
|
|
138
|
+
}
|
|
139
|
+
// Create a lock for each current event listener. All listeners
|
|
140
|
+
// need to call release() before the native side is signaled.
|
|
141
|
+
const eventLock = new SystemEventLock(() => {
|
|
142
|
+
NativeBridge.sendMessage(this.name, releaseMessage);
|
|
143
|
+
}, this.listenerCount('pause'));
|
|
144
|
+
this.emitLocal('pause', eventLock);
|
|
145
|
+
});
|
|
146
|
+
} else {
|
|
147
|
+
setImmediate(() => {
|
|
148
|
+
this.emitLocal(type);
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
processData(data) {
|
|
154
|
+
this.emitWrapper(data);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Get a writable data directory for persistent file storage.
|
|
159
|
+
*/
|
|
160
|
+
datadir() {
|
|
161
|
+
if (this._cacheDataDir === null) {
|
|
162
|
+
this._cacheDataDir = NativeBridge.getDataDir();
|
|
163
|
+
}
|
|
164
|
+
return this._cacheDataDir;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Manage the registered channels to emit events/messages received by the
|
|
170
|
+
* Capacitor app or by the plugin itself (i.e. the system channel).
|
|
171
|
+
*/
|
|
172
|
+
const channels = {};
|
|
173
|
+
|
|
174
|
+
function bridgeListener(channelName, data) {
|
|
175
|
+
if (Object.prototype.hasOwnProperty.call(channels, channelName)) {
|
|
176
|
+
channels[channelName].processData(data);
|
|
177
|
+
} else {
|
|
178
|
+
console.error('ERROR: Channel not found:', channelName);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* The bridge's native code processes each channel's messages in a
|
|
184
|
+
* dedicated per-channel queue, therefore each channel needs to be
|
|
185
|
+
* registered within the native code.
|
|
186
|
+
*/
|
|
187
|
+
function registerChannel(channel) {
|
|
188
|
+
channels[channel.name] = channel;
|
|
189
|
+
NativeBridge.registerChannel(channel.name, bridgeListener);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const systemChannel = new SystemChannel(SYSTEM_CHANNEL);
|
|
193
|
+
registerChannel(systemChannel);
|
|
194
|
+
|
|
195
|
+
const eventChannel = new EventChannel(EVENT_CHANNEL);
|
|
196
|
+
registerChannel(eventChannel);
|
|
197
|
+
|
|
198
|
+
// Signal that the Node.js app is ready to receive events, so the native
|
|
199
|
+
// code won't send events before Node.js is ready to handle those.
|
|
200
|
+
NativeBridge.sendMessage(SYSTEM_CHANNEL, 'ready-for-app-events');
|
|
201
|
+
|
|
202
|
+
module.exports = exports = {
|
|
203
|
+
app: systemChannel,
|
|
204
|
+
channel: eventChannel,
|
|
205
|
+
};
|