css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <p>Updating desired players.</p>
            
          
!
            
              /* * 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;
}


            
          
!
            
              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
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console