# Web Application Integration

The best way to integrate with the Bridge Media Player using a web app is to use the [Bridge.js library](https://www.npmjs.com/package/@lookingglass/bridge). This is the same library that we use for [Looking Glass Blocks](http://blocks.glass). The Bridge.js library exposes typesafe objects and methods for interacting with the Bridge REST API. See [the Bridge.js README file](https://github.com/looking-Glass/bridge.js#readme) for detailed information on how to use Bridge.js in your web application.

## REST API Reference <a href="#rest-api-reference" id="rest-api-reference"></a>

### Get Bridge version

Endpoint: `/bridge_version`

Example Payload: `none`

Example Response:&#x20;

```json
{
    "name": "value",
    "payload": {
        "name": "payload",
        "type": "STRING",
        "value": "2.4.7"
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Start media player session

Endpoint: `/enter_orchestration`

Example Payload:

```json
{
    "name": "default"
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "default"
    },
    "payload": {
        "name": "payload",
        "type": "WSTRING",
        "value": "1a6aed0d-77bf-4129-8e01-71d61c58473d"
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Query Looking Glass displays

Endpoint: `/available_output_devices`

Example Payload:

```json
{
    "orchestration": "1a6aed0d-77bf-4129-8e01-71d61c58473d"
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "1a6aed0d-77bf-4129-8e01-71d61c58473d"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "0": {
                "name": "0",
                "type": "VARIANT_MAP",
                "value": {
                    "calibration": {
                        "name": "calibration",
                        "type": "WSTRING",
                        "value": ""
                    },
                    "defaultQuilt": {
                        "name": "defaultQuilt",
                        "type": "WSTRING",
                        "value": "{}"
                    },
                    "hardwareVersion": {
                        "name": "hardwareVersion",
                        "type": "WSTRING",
                        "value": "thirdparty"
                    },
                    "hwid": {
                        "name": "hwid",
                        "type": "WSTRING",
                        "value": ""
                    },
                    "index": {
                        "name": "index",
                        "type": "UNSIGNED_INT",
                        "value": 0
                    },
                    "state": {
                        "name": "state",
                        "type": "WSTRING",
                        "value": "ok"
                    },
                    "windowCoords": {
                        "name": "windowCoords",
                        "type": "INT2",
                        "value": {
                            "x": 0,
                            "y": 0
                        }
                    }
                }
            },
            "1": {
                "name": "1",
                "type": "VARIANT_MAP",
                "value": {
                    "calibration": {
                        "name": "calibration",
                        "type": "WSTRING",
                        "value": "{\"DPI\":{\"value\":491.0},\"center\":{\"value\":0.22076533734798431},\"configVersion\":\"3.0\",\"flipImageX\":{\"value\":0.0},\"flipImageY\":{\"value\":0.0},\"flipSubp\":{\"value\":0.0},\"fringe\":{\"value\":0.0},\"invView\":{\"value\":1.0},\"pitch\":{\"value\":80.75597381591797},\"screenH\":{\"value\":2560.0},\"screenW\":{\"value\":1440.0},\"serial\":\"LKG-E\",\"slope\":{\"value\":-6.619636058807373},\"verticalAngle\":{\"value\":0.0},\"viewCone\":{\"value\":54.0}}"
                    },
                    "defaultQuilt": {
                        "name": "defaultQuilt",
                        "type": "WSTRING",
                        "value": "{ \"quiltAspect\" : 0.5625,   \"quiltX\" : 4092,  \"quiltY\" : 4092,  \"tileX\" : 11, \"tileY\" : 6}"
                    },
                    "hardwareVersion": {
                        "name": "hardwareVersion",
                        "type": "WSTRING",
                        "value": "go_p"
                    },
                    "hwid": {
                        "name": "hwid",
                        "type": "WSTRING",
                        "value": "LKG-E00194"
                    },
                    "index": {
                        "name": "index",
                        "type": "UNSIGNED_INT",
                        "value": 1
                    },
                    "state": {
                        "name": "state",
                        "type": "WSTRING",
                        "value": "ok"
                    },
                    "windowCoords": {
                        "name": "windowCoords",
                        "type": "INT2",
                        "value": {
                            "x": -1440,
                            "y": 0
                        }
                    }
                }
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Show the media player window

Endpoint: `/show_window`

Example Payload:&#x20;

```json
{
    orchestration: "1a6aed0d-77bf-4129-8e01-71d61c58473d",
    show_window: true,
    head_index: -1
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "1a6aed0d-77bf-4129-8e01-71d61c58473d"
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Create new playlist

Endpoint: `/instance_playlist`

Example Payload:

```json
{
    "orchestration":"57a075eb-2350-46e2-9a9c-f9754fc5a4fb",
    "name":"Cast_a7gj4o",
    "loop":true
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "name": {
                "name": "name",
                "type": "WSTRING",
                "value": "Cast_a7gj4o"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Add new playlist item

Endpoint: `/insert_playlist_entry`

Example Payload:

```json
{
    "orchestration": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb",
    "id": 0,
    "name": "Cast_a7gj4o",
    "index": 0,
    "uri": "https://s3.amazonaws.com/lkg-blocks/u/9aa4b54a7346471d/steampunk_qs8x13.jpg",
    "rows": 13,
    "cols": 8,
    "focus": 0,
    "zoom": 1,
    "aspect": 0.75,
    "view_count": 104,
    "isRGBD": 0,
    "tag": "steampunk"
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "index": {
                "name": "index",
                "type": "WSTRING",
                "value": "https://s3.amazonaws.com/lkg-blocks/u/9aa4b54a7346471d/steampunk_qs8x13.jpg"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Play a playlist

Endpoint: `/play_playlist`

Example Payload:

```json
{
    "orchestration": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb",
    "name": "Cast_a7gj4o",
    "head_index": -1
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "id": {
                "name": "id",
                "type": "WSTRING",
                "value": "4b3090db-f2f3-45cd-9817-406d938d4630"
            },
            "message": {
                "name": "message",
                "type": "WSTRING",
                "value": "playing playlist"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Completion"
    }
}
```

### Playback controls

Endpoints:&#x20;

`/transport_control_play`

`/transport_control_pause`

`/transport_control_next`

`/transport_control_previous`

Example Payload:

```json
{
    "orchestration":"57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "event": {
                "name": "event",
                "type": "WSTRING",
                "value": "Transport Control Pause"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Pending"
    }
}
```

### Seek to playlist index

Endpoint: `/transport_control_seek_to_index`

Example Payload:&#x20;

```json
{
    "orchestration": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb",
    "index": 2
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "event": {
                "name": "event",
                "type": "WSTRING",
                "value": "Transport Control Seek To Index"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "Pending"
    }
}
```

### Delete playlist

Endpoint: `/delete_playlist`

Example Payload:&#x20;

```json
{
    "orchestration":"57a075eb-2350-46e2-9a9c-f9754fc5a4fb",
    "name":"Cast_a7gj4o",
    "loop":true
}
```

Example Response:

```json
{
    "name": "value",
    "orchestration": {
        "name": "orchestration",
        "type": "WSTRING",
        "value": "57a075eb-2350-46e2-9a9c-f9754fc5a4fb"
    },
    "payload": {
        "name": "payload",
        "type": "VARIANT_MAP",
        "value": {
            "name": {
                "name": "name",
                "type": "WSTRING",
                "value": "Studio Playlist"
            }
        }
    },
    "status": {
        "name": "status",
        "type": "WSTRING",
        "value": "UnknownPlaylist"
    }
}
```
