Examples

Setup

Browser

<script type="text/javascript" src="path/to/amper-tango.js"></script>

Node

const AmperTango = require('path/to/amper-tango.node');

NOTE: You must install the required dependencies by running npm install or yarn install with the provided package.json.

Things To Do

Test Your Connection

amper_tango
    .get_ping()
    .then(({data: ping}) => {
        console.log('Ping', ping.attributes.ping); // Should equal: "pong"
    })
    .catch((err) => {
        console.error('Could not ping', err);
    });

Create A Simple Render

amper_tango
    .post_simple_render({
        timeline: {...},
        preset: 'MASTER_MP3'
    })
    .then(({data: simple_render}) => {
        console.log('Simple Render ID:', simple_render.id);
        console.log('Simple Render Status:', simple_render.attributes.status);
        console.log('Simple Render Files:', simple_render.attributes.files);
    })
    .catch((err) => {
        console.error('Could not create a simple render', err);
    });

Get A Simple Render

const simple_render_id = '...';

amper_tango
    .get_simple_render(simple_render_id)
    .then(({data: simple_render}) => {
        console.log('Simple Render ID:', simple_render.id);
        console.log('Simple Render Status:', simple_render.attributes.status);
        console.log('Simple Render Files:', simple_render.attributes.files);
    })
    .catch((err) => {
        console.error('Could not get simple render', err);
    });

Poll For A Simple Render

const simple_render_id = '...';

amper_tango
    .poll_simple_render(simple_render_id, {
        timeout: 1000,
        onPoll: ({data: simple_render}) => {
            console.log('Simple Render Progress:', simple_render.attributes.progress_percent);
        }
    })
    .then(({data: simple_render}) => {
        console.log('Simple Render ID:', simple_render.id);
        console.log('Simple Render Status:', simple_render.attributes.status);
        console.log('Simple Render Files:', simple_render.attributes.files);
    })
    .catch((err) => {
        console.error('Could not get simple render', err);
    });