API Documentation: liveswitcher.add

Synopsis

The Live Switcher API creates a live stream that switches its source from a list of streams. When one of listed streams is published, the "Live Switch" stream will play that source until a higher priority stream is published, or until the source is unpublished. The priority is determined by the order the streams are listed in the "stream_list" property with first being the highest. To create a Live Switcher stream provide the application name, the stream name to play out on, and a list of streams to play when they are published. New stream lists will be sent to primary servers, but will not take place until the application is restarted or the recheck_list param is set to true.

Example Request (JSON)

Example Code (PHP)

    $request = array(
        'command' => 'liveswitcher.add',
        'api_key' => 'APX4GKLM0RKQLSP2FBO1ROPKSSW47DZE',
        'timestamp' => time(),
        'cdn' => 158,
        'app' => 'demo-origin',
        'stream' => 'live_switch_stream',
        'stream_list' => array("stream1","stream2","stream3"),
        'recheck_list' => true, //optional
        
        'origin_url' => 'jb-chorigin.secdn.net', // optional
    );
    
        //Create request signature
    $json_request = json_encode($request);
    $sig = base64_encode(hash_hmac('sha256', $json_request,
        '8fc8c48da81e6a2a06a9556379bf798af508dc0792497c678b4c3532ba8b637f', true));
    $request['signature'] = $sig;
    $json_request = json_encode($request);
    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://api.scaleengine.net/stable/'); // Set the URL
    curl_setopt($ch, CURLOPT_POST, true); // Perform a POST
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // If not set, curl prints output to the browser
    curl_setopt($ch, CURLOPT_HEADER, false); // If set, curl returns headers as part of the data stream
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('json' => $json_request)); //'Json' string or 'PHP' serialized return
    
    //If your PHP host does not have a proper SSL certificate bundle, you will need to turn off SSL Certificate Verification
    //This is dangerous, and should only be done temporarily until a proper certificate bundle can be installed
    //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // Turns off verification of the SSL certificate.
    //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // Turns off verification of the SSL certificate.
    
    $response = curl_exec($ch); //Execute the API Call
    if (!$response) {
        die('Failed to connect to ScaleEngine API');
    }
    
    //Decode the response as an associative array 
    $arrResponse = json_decode($response, true); 
    if ($arrResponse) {
        //Operation completed successfully
        //TODO Add work here
        print_r($arrResponse);
    } else {
        //Operation failed
        echo 'An error occured processing your request:';
        print_r($response);
    }
        

Request Fields

command [REQUIRED] [string] - API command to execute
cdn_id [REQUIRED] [int] - The ScaleEngine CDN ID of your account
api_key [REQUIRED] [string] - The API key provided as part of your account
app [REQUIRED] [string] - The ScaleEngine Application name
stream [REQUIRED] [string] - Stream name
stream_list [REQUIRED] [array] - Array of Stream Names
timestamp [REQUIRED] [int] - The unix timestamp of your request, used to prevent authenticated API requests from being replayed
recheck_list [OPTIONAL] [boolean] - Servers are notified when a list is added, modified, or removed, but will not interrupt the current source unless set to true. Default false.
origin_url [OPTIONAL] [string] - Defines the url address of an origin to be called. Defaults to jb-origin.secdn.net for origins and jb-chorigin.secdn.net for channels.

Example Result (JSON)

    {
    "message": "Live Switch List created",
    "status": "success",
    "handle_time":"0.3795 seconds"
    "live_switcher_id" : 1,
    }
    

Result Fields

message [string] - Debugging message
status [string] - "success" or "failure"
live_switcher_id [int] - ID of the Live Switch List
handle_time [float] - The amount of time spent processing your request