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