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

              
                <p>Updating desired players.</p>
              
            
!

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: 0.5em;
  background-color: #333;
  border: 1px yellow solid;
  border-radius: 0.5em;
  color: yellow;
  cursor: pointer;
}
fieldset {
  color: #64aab2;
  border: 1px #64aab2 solid;
  border-radius: 0.5em;
}
code {
  color: #e4b842;
  font-family: "Source Code Pro", monospace;
}
.bcls-table {
  border-collapse: collapse;
  border: 1px #64aab2 solid;
}

.bcls-table .bcls-table__head th {
  border: 1px #64aab2 solid;
  padding: 0.5em;
}
.bcls-table .bcls-table__body td {
  border: 1px #64aab2 solid;
  padding: 0.5em;
}


              
            
!

JS

              
                var BCLS = (function(window, document) {
  var baseURL = "https://players.api.brightcove.com/v2/accounts/",
    accountId = "1752604059001",
    returnedPlayers = [],
    callNumber = 0,
    callNumberPublish = 0,
    playerIDsAra = [];
  setRequestGetPlayers();

  // +++ Configure the request to get players and extract their IDs +++
  function setRequestGetPlayers() {
    var responseParsed,
      options = {},
      endPoint = accountId + "/players";
    options.proxyURL =
      "https://solutions.brightcove.com/bcls/bcls-proxy/bcls-proxy-v2.php";
    options.url = baseURL + endPoint;
    options.requestType = "GET";
    // Call function that  calls the proxy which makes the actual call to the API
    makeRequest(options, function(response) {
      responseParsed = JSON.parse(response);
      returnedPlayers = responseParsed.items;
      // Use the filter_players function in conjunction JavaScript filter function extract wanted players
      var filtered_players = returnedPlayers.filter(filter_players);
      filteredPlayersAraLength = filtered_players.length;
      //  Extract IDs into a separate array
      for (var i = 0; i < filteredPlayersAraLength; i++) {
        playerIDsAra.push(filtered_players[i].id);
      }
      // Call function to configure calls to update players
      setRequestMakeUpdate();
    });
    // Define the criteria for set of players to update
    function filter_players(event) {
      return event.description == "For patch players Player Mgmt Sample";
    }
  }

  // +++ Configure the request to update filtered players +++
  function setRequestMakeUpdate() {
    var responseParsed,
      options = {},
      // Define what updates to make on each player
      requestBody = {
        muted: true,
        autoplay: true
      },
      baseURL = "https://players.api.brightcove.com/v2/accounts/",
      endPoint = accountId + "/players/",
      playerIDsAraLength = playerIDsAra.length;
    options.proxyURL =
      "https://solutions.brightcove.com/bcls/bcls-proxy/doc-samples-proxy-v2.php";
    options.url = baseURL + endPoint;
    var currentId = playerIDsAra[callNumber];
    options.url += currentId + "/configuration";
    options.requestBody = JSON.stringify(requestBody);
    options.requestType = "PATCH";
    // Call function that calls the proxy which makes the actual call to the API
    makeRequest(options, function(response) {
      responseParsed = JSON.parse(response);
      callNumber++;
      // If call not made for all players, recursively call this function
      if (callNumber < playerIDsAraLength) {
        setRequestMakeUpdate();
      }
      // Call function to configure calls to publish players
      setRequestPublish();
    });
  }

  // +++ Configure the request to publish updated players +++
  function setRequestPublish() {
    var responseParsed,
      options = {},
      baseURL = "https://players.api.brightcove.com/v2/accounts/",
      endPoint = accountId + "/players/",
      playerIDsAraLength = playerIDsAra.length;
    options.proxyURL =
      "https://solutions.brightcove.com/bcls/bcls-proxy/doc-samples-proxy-v2.php";
    options.url = baseURL + endPoint;
    var currentId = playerIDsAra[callNumberPublish];
    options.url += currentId + "/publish";
    options.requestType = "POST";
    // Call function that calls the proxy which makes the actual call to the API
    makeRequest(options, function(response) {
      responseParsed = JSON.parse(response);
      callNumberPublish++;
      // If call not made for all players, recursively call this function
      if (callNumberPublish < playerIDsAraLength) {
        setRequestPublish();
      }
    });
  }

  // +++ Make the call to the proxy, which in turn make actual call to API +++
  // This function generally should not be changed, if passed proper options it will just work
  function makeRequest(options, callback) {
    var httpRequest = new XMLHttpRequest(),
      response,
      requestParams,
      dataString,
      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