Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1>Update Player Version</h1>
<section class="bcls-section">
<h2 id="infoinput">Player info input</h2>

  <p>Player ID: <input class="checkForValue" id="player_id_input" type="text" size="40" name="player_id" /></p>
  
<p>Account ID: <input class="checkForValue" id="account_id_input" type="text" size="40" name="account_id" /></p>
  
 <p>Client ID: <input class="checkForValue" id="client_id_input" type="text" size="100" name="client_id_input" /></p>

<p>Client Secret: <input class="checkForValue" id="client_secrect_input" type="password" size="100" name="client_secrect_input" /></p>

<p><button id="update_player" class="bcls-button">Update Player Version</span></p>
</section>

<section class="bcls-section">
<h2 id="jsonText">JSON response</h2>

<p>Below is the JSON data returned by the player version update:</p>

<pre><code id="create_response">Response will appear here...</code></pre>
  
 <p>Below is the JSON data returned by the player publish:</p>

<pre><code id="publish_response">Response will appear here...</code></pre>
</section>

<section class="bcls-section">
<h2 id="embedded_player">Processed response</h2>
<p>
  <button class="bcls-button" id="preview_player">Preview the Player</button>
</p>

<p>Note publishing is asynchrounous; if the player doesn't immediately appear, wait a few seconds and try again or go to your Video Cloud Studio and review the player. </p>

<div id="player_embedded"></div>
</section>
              
            
!

CSS

              
                /* * The body style is just for the
 * background color of the codepen.
 * Do not include in your code.
 */
body {
  background-color: #111;
  color: #f5f5f5;
  font-family: sans-serif;
  margin: 2em;
}
/*
 * Styles essential to the sample
 * are below
 */
.bcls-code {
  color: #111;
  font-family: 'Source Code Pro',monospace;
  padding: 1em;
  width: 90%;
  min-height: 5em;
  background-color: #cfcfcf;
  font-size: 1rem;
}
.bcls-button {
  padding: .5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: .5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64AAB2;
  border: 1px #64AAB2 solid;
  border-radius: .5em;
}
code {
  color: #E4B842;
  font-family: 'Source Code Pro',monospace;
}
              
            
!

JS

              
                let BCLS = (function (window, document) {
    // account id calue is the default
    let player_id,
        player_code,
        player_id_input = document.getElementById('player_id_input'),
        account_id_input = document.getElementById('account_id_input'),
        client_id_input = document.getElementById('client_id_input'),
        client_secrect_input = document.getElementById('client_secrect_input'),
        update_player = document.getElementById('update_player'),
        create_response = document.getElementById('create_response'),
        publish_response = document.getElementById('publish_response'),
        player_embedded = document.getElementById('player_embedded'),
        preview_player = document.getElementById('preview_player');

    // event handlers
    update_player.addEventListener('click', function () {
        createRequest('updatePlayer');
    });

    preview_player.addEventListener('click', function () {
        // inject the player - clear the div first to allow repeated clicks
        player_embedded.innerHTML = '';
        player_embedded.insertAdjacentHTML('afterbegin', player_code);
    });


    /**
     * createRequest sets up requests, send them to makeRequest(), and handles responses
     * @param  {string} type the request type
     */
    function createRequest(type) {
        let options = {},
            requestBody = {},
            proxyURL = 'https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php',
            baseURL = 'https://players.api.brightcove.com/v2/accounts/',
            endpoint,
            responseDecoded;

        if (client_id_input.value.length > 0 && client_secrect_input.value.length > 0 && player_id_input.value.length > 0 && account_id_input.value.length > 0) {

            options.player_id_input = player_id_input.value;
            options.account_id_input = account_id_input.value;
            options.client_id = client_id_input.value;
            options.client_secret = client_secrect_input.value;

        }else{
          alert('Enter data in all fields');
        }

        options.proxyURL = proxyURL;

        switch (type) {
            case 'updatePlayer':
                endpoint = options.account_id_input + '/players/' + options.player_id_input + '/configuration';
                options.url = baseURL + endpoint;
                options.requestType = 'PATCH';
                requestBody.player = {};
                requestBody.player.template = {};
                requestBody.player.template.locked = false;
                requestBody.player.template.version = "7.2.0";

                options.requestBody = JSON.stringify(requestBody);

                makeRequest(options, function (response) {
                    responseDecoded = JSON.parse(response);
                    player_id = responseDecoded.id;
                    create_response.textContent = JSON.stringify(responseDecoded, null, 2);

                    if (player_id) {
                        createRequest('publishPlayer');
                    }
                });
                break;
            case 'publishPlayer':
                endpoint = options.account_id_input + '/players/' + player_id_input.value + '/publish';
                options.url = baseURL + endpoint;
                options.requestType = 'POST';

                makeRequest(options, function (response) {
                    responseDecoded = JSON.parse(response);
                    player_code = responseDecoded.embed_code;
                    publish_response.textContent = JSON.stringify(responseDecoded, null, 2);
                });
                break;

            // additional cases
            default:
                console.log('Should not be getting to the default case - bad request type sent');
                break;
        }
    }

    /**
     * send API request to the proxy
     * @param {Object} options for the request
     * @param {String} options.url the full API request URL
      * @param {String} options.client_id client id for the account( default is in the proxy)
     * @param {String} options.client_secret client secret for the account(default is in the proxy)
     * @param {String = "GET", "POST", "PATCH", "PUT", "DELETE"} requestData[options.requestType = "GET"] HTTP type for the request
     * @param {String} options.proxyURL proxyURL to send the request to
     *@param {Function} [callback] callback function that will process the response
     */

    function makeRequest(options, callback) {
        let httpRequest = new XMLHttpRequest(),
            response,
            proxyURL = options.proxyURL,
            // response handler
            getResponse = function () {
                try {
                    if (httpRequest.readyState === 4) {
                        if (httpRequest.status >= 200 && httpRequest.status < 300) {
                            response = httpRequest.responseText;
                            // some API requests return '{null}' for empty responses - breaks JSON.parse
                            if (response === '{null}') {
                                response = null;
                            }
                            // return the response
                            callback(response);
                        } else {
                            alert('There was a problem with the request. Request returned ' + httpRequest.status);
                        }
                    }
                } catch (e) {
                    alert('Caught Exception: ' + e);
                }
            };
        /**
         * set up request data
         * the proxy used here takes the following request body:
         * JSON.strinify(options)
         */
        // set response handler
        httpRequest.onreadystatechange = getResponse;
        // open the request
        httpRequest.open('POST', proxyURL);
        // set headers if there is a set header line, remove it
        // open and send request
        httpRequest.send(JSON.stringify(options));
    }

})(window, document);
              
            
!
999px

Console