> For the complete documentation index, see [llms.txt](https://adaptix-framework.gitbook.io/adaptix-framework/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adaptix-framework.gitbook.io/adaptix-framework/development/axscript/axevent-type.md).

# AxEvent type

AdaptixClient generates events for various situations. To register a handler for a specific event, there are functions from the `event` namespace. Several handlers can be connected to one event.

To assign a `handler` to a specific event use the function

```javascript
void event.on_EVENT_TYPE(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

* `handler` - a handler that will be triggered when the event occurs.
* `agents` - an array of strings containing the names of agents for which the event will be triggered. Available options are "beacon", "gopher", etc.&#x20;
* `os` - an array of strings with the names of the operating systems for which the event will be triggered. The following options are available: "windows", "linux", "macos". If an empty array `[]` is specified, the command group will be registered for all operating systems.
* `listeners` - An array of strings with the names of registered listeners for which the event will be triggered. The following options are available: "BeaconHTTP", "BeaconSMB", etc. If an empty array \[] is specified, the command group will be registered for all listeners.
* `event_id` - id for `handler`

You can remove a handler that has an id set.

```javascript
void event.remove(string event_id);
```

***

## on\_new\_agent

This event occurs every time a new agent registers.

```javascript
void event.on_new_agent(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_ag = function(id) {
    ax.show_message("New agent", id);
}
event.on_new_agent(event_ag, ["beacon", "gopher"]);
```

***

## on\_filebrowser\_disks

This event occurs when the user clicks the Disks button in the File Browser.

```javascript
void event.on_filebrowser_disks(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_disks_action = function(id) {
    ax.execute_browser(id, "disks");
}
event.on_filebrowser_disks(event_disks_action, ["beacon"]);
```

***

## on\_filebrowser\_list

This event occurs whenever the user requests a list of files in the File Browser.

```javascript
void event.on_filebrowser_list(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id, string path);
```

* `id` - agent ID
* `path` - current path in File Browser

```javascript
var event_files_action = function(id, path) {
    ax.execute_browser(id, "ls " + path);
}
event.on_filebrowser_list(event_files_action, ["beacon"]);
```

***

## on\_filebrowser\_upload

This event occurs whenever the user requests a list of processes in the Process Browser.

```javascript
void event.on_processbrowser_list(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id, string path, string filepath );
```

* `id` - agent ID
* `path` - current path in File Browser
* `filepath` - path to the local file to upload

**Example**

```javascript
var event_upload_action = function(id, path, filepath) {
    let filename = ax.file_basename(filepath);
    ax.execute_browser(id, "upload " + filepath + " " + path + filename);
}
event.on_filebrowser_upload(event_upload_action, ["beacon"]);
```

***

## on\_processbrowser\_list

This event occurs when a user uploads a file in a File Browser.

```javascript
void event.on_filebrowser_upload(handler(){}, string[] agents, string[] os = [], string[] listeners = [], string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler(string id);
```

* `id` - agent ID

**Example**

```javascript
var event_process_action = function(id) {
    ax.execute_browser(id, "ps list");
}
event.on_processbrowser_list(event_process_action, ["beacon"]);
```

***

## on\_disconnect

This event occurs when a client disconnects from the server.

```javascript
void event.on_disconnect(handler(){}, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_disc = function() {
    ax.show_message("Event", "Client disconnected!");
}
event.on_disconnect(event_disc);
```

***

## on\_ready

This event occurs when the client has finished synchronizing with the server.

```javascript
void event.on_ready(handler(){}, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_ready = function() {
    ax.show_message("Event", "Client connected!");
}
event.on_ready(event_ready);
```

***

## on\_interval

The `handler` will be executed every `n` seconds. The method returns the ID with which the event was registered.

```javascript
string on_interval(handler(){}, int n, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_timer = function() {
    ax.show_message("Timeout", "5 seconds out");
}
event.on_interval(event_timer, 5);
```

***

## on\_timeout

The `handler` will be executed once in `n` seconds. The method returns the ID with which the event was registered.

```javascript
string on_timeout(handler(){}, int n, string event_id = "");
```

This event must have a `handler` assigned in the following format.

```javascript
function handler();
```

**Example**

```javascript
var event_timer = function() {
    ax.show_message("Timeout", "5 seconds out");
}
event.on_timeout(event_timer, 5);
```

***

## list

The method returns a list of IDs of all registered handlers.

```javascript
string list();
```

**Example**

<div align="left"><figure><img src="/files/7DZX9MnNQ7REdqG6oAzq" alt=""><figcaption></figcaption></figure></div>

***

## remove

The method removes handler for the event whose ID is provided.

```javascript
string remove(string event_id);
```

**Example**

<div align="left"><figure><img src="/files/XeTAMaPKK7fxAMCW4yYb" alt=""><figcaption></figcaption></figure></div>

***
