> For the complete documentation index, see [llms.txt](https://docs.sonoransoftware.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonoransoftware.com/store/cctv/developer-api.md).

# Developer API

Use the supported Events CCTV server exports for remote viewing integrations.

Resource name:

```
eventsCctv
```

CCTV currently exposes two server exports for trusted remote-view integrations. It does not expose client exports or public camera-management functions.

## Setup

Remote access is disabled by default. Enable it and allowlist each calling server resource in `eventsCctv/config/remote.lua`:

```lua
Config.RemotePanel = {
    Enabled = true,
    SessionTtlSeconds = 300,
    TrustedResources = {
        ['my-cctv-web-bridge'] = true
    }
}
```

The player must also be online and authorized for the requested terminal. The terminal must be enabled with `RemoteAccessEnabled = true`.

## Server exports

### `CreateRemoteSession(playerSource, terminalId)`

Creates a short-lived session for an authorized player and terminal.

```lua
local token, err = exports.eventsCctv:CreateRemoteSession(source, 'mission-row')

if not token then
    print(err)
end
```

| Parameter      | Type   | Description               |
| -------------- | ------ | ------------------------- |
| `playerSource` | number | Online player's server ID |
| `terminalId`   | string | Existing CCTV terminal ID |

Returns `token, nil` on success or `nil, errorMessage` on failure. The token is a 48-character secret. Do not log it or send it to another player.

### `ValidateRemoteSession(token)`

Validates a session and returns the cameras available through its terminal.

```lua
local session, err = exports.eventsCctv:ValidateRemoteSession(token)

if session then
    print(session.terminalId, session.expiresAt, #session.cameras)
end
```

The result contains:

| Field        | Type   | Description                              |
| ------------ | ------ | ---------------------------------------- |
| `terminalId` | string | Authorized terminal ID                   |
| `cameras`    | array  | Enabled cameras assigned to the terminal |
| `expiresAt`  | number | Session expiration as a Unix timestamp   |

Returns `nil, errorMessage` when the token is expired, belongs to another calling resource, or access has been revoked. Validation re-checks the player, terminal, remote-access setting, and permissions each time.

## Security boundary

Both exports must be called from an allowlisted server resource. A token is bound to the resource that created it and cannot be validated by a different resource.

Events named `eventsCctv:server:*` and `eventsCctv:client:*` are internal request and synchronization routes. They are not a stable public API. Do not call them from integrations.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sonoransoftware.com/store/cctv/developer-api.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
