
# Agent Walrus
The official JavaScript SDK for [Agent Walrus](https://agentwalrus.com/).

Agent Walrus lets engineering teams visualize, analyze and troubleshoot their video conferencing software. Improve uptime, performance and scalability of your product without the need for WebRTC expertise.  

## Contents
1. [Installation](#installation)
2. [Example Usage](#example-usage)
3. [API](#api)
4. [Platform Integration](#platform-integration)
5. [License](#license)

## Installation
Just the good old:
```bash
npm install --save @agent-walrus/agent-walrus
```

## Example Usage
```js
import { AgentWalrus } from  "@agent-walrus/agent-walrus";  

// Start data collection
AgentWalrus.init("<Your app token>");

// Identify the user with unique id and optional traits
AgentWalrus.identify({
    id:  "Your app unique user id",
    yourCustomAttribute:  "customValue",
});  

// Add more traits later
AgentWalrus.identify({
    name:  "Example User",
    email:  "user@example.com",
});
```

## API
All the methods are called on the main `AgentWalrus` object.

###  `.init(token: string, config?: AgentWalrusConfig)`
Starts the data collection. Must be run before the local media acquisition and WebRTC connection setup.
- `token` - String identificator for your app. You'll find it in Agent Walrus' Settings/App Setup page.
- `config` - Optional object with the following properties:
	- `gatewayUrl?` - URL where the data should be reported to. Change only if running a custom Agent Walrus deployment.
    - `logLevel?` - Level of collected console logs. One of: *error*, *warning*, *info*, *debug*. Defaults to *warning*.

### `.terminate()`
Stops the data collection.

### `.identify(traits: Record<string, string | number>)`
Used to add user-related traits to the session. You will be able to see the traits in Agent Walrus interface and search sessions by trait type and value.

`Special traits`:
    - `id` - Unique user identifier. Used to group same user's sessions together.
    - `name` - User's name or nickname. Will be displayed in the UI instead of the id.
    - `email` - User's email. Will be displayed next to the user's name or id. 

### `.submitUserFeedback(score: number, description?: string)`
Add user feedback to the session.
    - `score` - 1 - 5 numeric score
    - `description` - Optional textual feedback

## Platform integration
Extra steps to get the most data out of your platform or media servers.

### Twilio
```js
import { AgentWalrus } from "@agent-walrus/agent-walrus";  

// Line below is just an example; you might be creating the room differently
const room = await Video.connect(token, { name: room, tracks: localParticipant.tracks });

AgentWalrus.monitorPlatform("twilio", room);
```

### Other
If your platform is not fully supported by Agent Walrus, [let us know](mailto:support@agentwalrus.com). We're happy to add the support to our SDK.

## License
MIT
