|
| 1 | +declare module "nodejs-mobile-react-native" { |
| 2 | + export interface NodeJs { |
| 3 | + /** |
| 4 | + * Starts the nodejs-mobile runtime thread with a file inside the nodejs-project directory |
| 5 | + * @param scriptFileName |
| 6 | + * @param options |
| 7 | + */ |
| 8 | + start: (scriptFileName: string, options?: StartupOptions) => void |
| 9 | + /** |
| 10 | + * Starts the nodejs-mobile runtime thread with a script body |
| 11 | + * @param scriptBody |
| 12 | + * @param options |
| 13 | + */ |
| 14 | + startWithScript: (scriptBody: string, options?: StartupOptions) => void |
| 15 | + channel: Channel; |
| 16 | + } |
| 17 | + export interface Channel { |
| 18 | + /** |
| 19 | + * Registers a callback for user-defined events raised from the nodejs-mobile side |
| 20 | + * @param event |
| 21 | + * @param callback a function that accepts any JS type that can be serialized with JSON.stringify |
| 22 | + * and deserialized with JSON.parse of the type: `boolean`, `number`, `string`, `object`, or `array` |
| 23 | + * @param context |
| 24 | + */ |
| 25 | + addListener: (event: string, callback: ChannelCallback, context?: any) => void; |
| 26 | + /** |
| 27 | + * Removes the listener for the user-defined events raised from the nodejs-mobile side |
| 28 | + * @param event |
| 29 | + * @param callback a function that accepts any JS type that can be serialized with JSON.stringify |
| 30 | + * and deserialized with JSON.parse of the type: `boolean`, `number`, `string`, `object`, or `array` |
| 31 | + * @param context |
| 32 | + */ |
| 33 | + removeListener: (event: string, callback: ChannelCallback, context?: any) => void; |
| 34 | + /** |
| 35 | + * Raises a user-defined event on the nodejs-mobile side |
| 36 | + * - accepts any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
| 37 | + * - can accept multiple message arguments |
| 38 | + * @param event |
| 39 | + * @param message can be of type: `boolean`, `number`, `string`, `object`, or `array` |
| 40 | + */ |
| 41 | + post: (event: string, ...message: any[]) => void; |
| 42 | + /** |
| 43 | + * Raises a `'message'` event on the nodejs-mobile side |
| 44 | + * It is an alias for `nodejs.channel.post('message', ...message)` |
| 45 | + * - accepts any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
| 46 | + * - can accept multiple message arguments |
| 47 | + * @param message can be of type: `boolean`, `number`, `string`, `object`, or `array` |
| 48 | + */ |
| 49 | + send: (...message: any[]) => void; |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * Handles messages sent through the nodejs-mobile channel. |
| 54 | + * - accepts any JS type that can be serialized with JSON.stringify and deserialized with JSON.parse |
| 55 | + * - can accept multiple arguments |
| 56 | + * @param arg can be of type: `boolean`, `number`, `string`, `object`, or `array` |
| 57 | + */ |
| 58 | + export type ChannelCallback = (...arg: any[]) => void |
| 59 | + |
| 60 | + /** |
| 61 | + * Optional options for `start` and `startWithScript` |
| 62 | + */ |
| 63 | + export interface StartupOptions { |
| 64 | + redirectOutputToLogcat?: boolean |
| 65 | + } |
| 66 | + |
| 67 | + const nodejs: NodeJs |
| 68 | + |
| 69 | + export default nodejs |
| 70 | +} |
0 commit comments