# Contributing

The Raydiant SDK was bootstrapped with [`typescript-starter`](https://github.com/bitjson/typescript-starter) and supports running in 4 different environments:

1. On a physical device: Electron playlist runtime using `BrowserWindow`s for window management.
2. On a virtual device (ex. [SecondScreen](secondscreen.raydiant.com)): Browser playlist runtime using `<iframe>`s for window management.
3. Local development: No playlist runtime but helpful methods for simulating the runtime are exposed through developer tools.
4. Dashboard preview: Local previews and builder inputs.

When developing locally be sure to test in all environments.

## Local Development

Run one of the example apps to test in the SDK when developing locally.

```bash
yarn watch:build:module # Build the sdk on file change.

# From another terminal window:
cd examples/next-app
yarn dev
```

Opening the example app directly in the browser will enable the developer tools.

```bash
open http://localhost:3000
```

## Testing

### Unit

Unit tests use the [ava](https://github.com/avajs/ava) test runner. To run the test suite:

```bash
yarn watch:build:main # Build the sdk (do not use build:module!)

# From another terminal window:
yarn watch:test

# Or watch a single test file:
yarn watch:test src/lib/runtime.test.ts
```

### Integration

To test the SDK in various environments you'll need to create an app in your Dashboard for the running example app.

You can do this one of two ways:

1. Enable the `web_pages_v1` app for your account and create a Web Page presentation for the localhost URL.
2. Enable the `developer` role for your account and create a new Developer Portal application for the localhost URL.

Once a presentation is created for your local example app, add can test the SDK in the Dashboard preview or in the playlist runtime by adding it to a playlist and publishing to a device.

#### Electron Playlist Runtime

To test your app an Electron environment you'll need to run [`photon`](https://github.com/mirainc/photon) locally.

Publish one of the example apps to one of your devices and run photon with:

```bash
DEVICE_ID=<device-id> ACCESS_TOKEN=<device-access-token> CONNECTIVITY_SERVICE_URL=none NODE_ENV=staging ENABLE_DEVTOOLS=true ENABLE_MAIN_SERVER=true MAIN_SERVER_PORT=3001 DEBUG=true yarn start
```

##### `playlist-window-manager`

When adding a feature to the SDK you may also need to make changes to the [`playlist-window-manager`](https://github.com/mirainc/playlist-renderer).

Use `yarn link` or `npm link` to link your local `playlist-window-manager` package into `photon`.

If you also need to make changes to the `app-renderer` you can tell photon to use your local `app-renderer` url with the `APP_RENDERER_URL` environment variable:

```bash
DEVICE_ID=<device-id> ACCESS_TOKEN=<device-access-token> CONNECTIVITY_SERVICE_URL=none NODE_ENV=staging ENABLE_DEVTOOLS=true ENABLE_MAIN_SERVER=true MAIN_SERVER_PORT=3001 APP_RENDERER_URL=http://localhost:8082 DEBUG=true yarn start
```

#### Browser Playlist Runtime

TODO

# Deployment

TODO
