# Develop Guide

![](https://858958132-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LDCTepm-NIh5ojz-G9T%2F-LDL6YKu3i6-58lWcIr5%2F-LDL6e5t-VjLNzWgVEZo%2Fd.png?alt=media\&token=cc14444a-399d-46f5-93f9-516531a6fc3b)

## Robotmon scripts APIs

[RBM library](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23rbm-library-apis\&sa=D\&sntz=1\&usg=AFQjCNGAWRMaOj1XNmB4vkDIkun_b4_gIg) for beginner (auto support different resolution)

[Raw APIs](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23javascript-raw-apis\&sa=D\&sntz=1\&usg=AFQjCNGenvrLNAHKC2NYZuOOPzAU-QvKyA) for efficiency, You should hold every thing yourself.

## Web view APIs

[Javascript interface](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23javascript-interface\&sa=D\&sntz=1\&usg=AFQjCNFcL3J-4v-x9R3XzHjV_6D9LK1FIA) for controlling **Floating Window** and **Robotmon Service (**`JavascriptInterface.runScript();`**)**

[Javascript Events](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23javascript-events\&sa=D\&sntz=1\&usg=AFQjCNFH57LvAMH2mLctuUZmiK8YqgFzzA) for receiving events from **Floating Window** and **Robotmon Service (**`onLog()`**)**

## GRPC Commands

[GRPC commands](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23grpc-apis\&sa=D\&sntz=1\&usg=AFQjCNF8eI5ff0GL6PbuAHW0CprnzZt8OA) for communicating with **Robotmon Service**. You can connect to robotmon service anywhere.

## Robotmon Developer Tool

1. [Download Develop IDE](https://drive.google.com/drive/folders/1aLpa4N8OpuE6dGIJQhhRVVOj4EKbZdLK?usp=sharing) (or [Build it yourself](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-desktop\&sa=D\&sntz=1\&usg=AFQjCNEBFejE34esJt-6vwLNMhCffXV5nQ))
2. Unzip it (If using MAC OS, move app to Applications folder)
3. Open It. Success!

![](https://858958132-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LDCTepm-NIh5ojz-G9T%2F-LDL6YKu3i6-58lWcIr5%2F-LDL74TzVQdFJqcnWjEb%2Fide.png?alt=media\&token=da6820ef-f32d-4d66-a547-a251a0975b57)

### Service Controller

IDE will receive broadcast from phones, and show on left side. If not received you can add a service by IP

### **You should choice one service (device) to start**

If use emulator, you should forward port first, then connect to `127.0.0.1`

```
adb forward tcp:8081 tcp:8081
```

### Script Controller

Open JS file, and Run it (execute JS script in editor) or Stop it (call stop() function)

### Script Editor

Simple JS editor, you can use other editor too

Just do a test!

```
console.log('Hello world!');
```

Then click 'Run'

### Log

Show console log

### Screen Controller

Start/Stop sync Screen.

* Tap: tap screen by click
* Color: get color info by click
* Crop: crop an image (by selection) in to /sdcard/Robotmon/scripts/com.my.newProject/images (You may want to editor app name first) (This function is base on [RBM library](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%23rbm-library-apis\&sa=D\&sntz=1\&usg=AFQjCNGAWRMaOj1XNmB4vkDIkun_b4_gIg))

## Floating window

After opening **floating window** by click scripts, it will do two things:

1. Create a web view and load **index.html** file.
2. Load **index.js** and inject to **Robotmon Service**.

(\*\*\* So **index.js** and **index.html** are independent \*\*\*)

There are 6 buttons on menu of Floating window. And onEvent will receive 6 events with them. You should control with them yourself.

* Icon button - show/hide menu and inject event OnMenuClick
* Start button - inject event OnPlayClick
* Pause button - inject event OnPauseClick
* Log button - show/hide log and inject event OnLogClick
* Setting button - show/hide setting UI (web view) and inject event OnSettingClick
* Close button - close script and inject event OnCloseClick

In index.html, you should put UI of settings in `<body></body>` and controller in `<script></scripts>` (like function `onEvent(){}`)

#### Example <a href="#h.p_gtr6qt2rjjzs" id="h.p_gtr6qt2rjjzs"></a>

```
<html>
<!-- You can load any library here like jQuery -->
<script>
  function onEvent(eventType) {
    if (eventType == 'OnPlayClick') {
      JavaScriptInterface.runScript('start();'); // call start function in index.js
      // you can also put parameters like 'start(10, "run", "stop")'
    } else if (eventType == 'OnPauseClick') {
      JavaScriptInterface.runScript('stop();'); // call stop function in index.js
    }
  }
  function onLog(message) {
    console.log(message);
  }
</script>
<body>
  <div>Setting UI</div>
  <button>Setting</button>
</body>
</html>
```

[More examples](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts%2Ftree%2Fmaster%2Fscripts\&sa=D\&sntz=1\&usg=AFQjCNHWfZtJsFiJ30lJqqWXwdB8ckzLzA)

### Test Your Scripts <a href="#h.p_wpx0g_c2cl9o" id="h.p_wpx0g_c2cl9o"></a>

### With IDE

You can just click **Run** in **Developer Tool**, then developer tool will send your scripts to **Robotmon service** and run it.

### With Robotmon App (Web view APIs)

Preparing two file **index.js** and **index.html** (Or zip two file as **index.zip**) and put them into phone `/sdcard/Robotmon/scripts/your.script.name/index.(js)(html)(zip)`

### Publish your scripts

1\. Git fork and clone [https://github.com/r2-studio/robotmon-scripts](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts\&sa=D\&sntz=1\&usg=AFQjCNHf2aoIE0Jomx2PovXkME8_7WBKlA)

2\. Add your scripts in **scripts** folder

3\. ZIP all your files as index.zip

4\. Editor **script-config.json** and add information about your scripts

5\. Commit and push to your branch

Make a pull request to [https://github.com/r2-studio/robotmon-scripts](https://www.google.com/url?q=https%3A%2F%2Fgithub.com%2Fr2-studio%2Frobotmon-scripts\&sa=D\&sntz=1\&usg=AFQjCNHf2aoIE0Jomx2PovXkME8_7WBKlA)
