> 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` - a non-empty array of agent type names, such as `"beacon"` or `"gopher"`. An empty array is an error and the handler is not registered.
* `os` - operating system names: `"windows"`, `"linux"`, `"macos"`. An empty array registers the handler for every operating system.
* `listeners` - listener type names, such as `"BeaconHTTP"` or `"BeaconSMB"`. An empty array registers the handler for every listener.
* `event_id` - id used later by `event.remove` and `event.list`. If it is empty, the client assigns one.

These handlers run in the client. On the teamserver every `event.on_*` is a no-op, `event.list` returns `[]`, and `event.remove` does nothing. The teamserver does have `event.emit(string type, text)`, which publishes an event and returns `true`. `text` may be a string or an object with a `text` field.

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(int 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(int 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(int 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 when the user uploads a file in the 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(int 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 the user requests the process list 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(int 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 event.on_interval(handler(){}, int n, string event_id = "");
```

* `n` — is the period in seconds. A negative value is treated as `0`. The return value is `event_id`, or a generated `interval_` id when `event_id` is empty. A handler that is not a function returns `""`.

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 event.on_timeout(handler(){}, int n, string event_id = "");
```

* `n` — is the delay in seconds. A negative value is treated as `0`. The handler runs once, then the client removes the registration. The return value is `event_id`, or a generated `timeout_` id when `event_id` is empty. A handler that is not a function returns `""`.

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[] event.list();
```

***

## remove

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

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

**Example**

<div align="left"><figure><img src="https://2104178602-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FS8p8XLFtLmf0NkofQvoa%2Fuploads%2Fgit-blob-1d9f7ce11d6c0502fa68aaec577ba3d84893ab56%2FScreenshot_20250828_125336.png?alt=media" alt=""><figcaption></figcaption></figure></div>

***
