send(message, value) {

    // Check to make sure that we can access the communication channel
    if (!this._server || !this._server.contentWindow) {
      return Promise.reject(
        {
          status: false,
          message: 'PBSMessageAPI failed to connect to a player instance'
        }
      );
    }

    let sendPromise = new Promise(
      function (resolve, reject) {

        // Do not listen for a response for the message types that PBS will not
        // send a response for. Additionally responses are never sent back for
        // commands that pass a value
        if (typeof value === 'undefined' && noResponse.indexOf(message) === -1) {

          // Define the event handler that will resolve the promise, pass along
          // the response, and finally detach from the window
          let messageHandler = function (event) {

            // Make sure that this is a valid event for this player and that
            // it is a response to the same message type that was requested
            if (this._validateEvent(event) &&
              this._testMessageType(event, message)) {

              // Unhook this handler from the window so it is not called again
              this._client.removeEventListener(
                'message',
                messageHandler
              );

              let index = this._pending.indexOf(messageHandler);

              if (index > -1) {
                this._pending.splice(index, 1);
              }

              // Successfully resolve the event and pass along the message event
              resolve(event);
            }
          }.bind(this);

          // Attach the event handler to listen for the response
          this._client.addEventListener(
            'message',
            messageHandler
          );

          this._pending.push(messageHandler);
        } else {

          // For the messages without a response, resolve the promise immediately
          resolve(null);
        }
      }.bind(this)
    );

    // Generate the message based on if the value is present
    var postMessage = typeof value !== 'undefined' ? message + '::' + value : message;

    // Store the event in the list of outgoing messages
    this._messages.outgoing = lastElements(
      this._messages.outgoing.concat([postMessage]),
      25
    );

    // Send the message off to the Cove video player
    this._server.contentWindow.postMessage(postMessage, playerOrigin);

    // Return the promise
    return sendPromise;
  }
/**
   * Sends a post message to the window of the underlying player element. Takes
   * a message and a value and combines them in to the format requested by the
   * PBS Cove API. Returns back a Promise that will resolve when the PBS Cove
   * API responds with the same message. For messages that PBS does not send
   * responses to, the Promise will resolve with null. Otherwise the Promise
   * will resolve with the raw message event from Cove.
   *
   * @param {String} message The message to pass to the PBS Cove API
   * @param {String} [value] The value to associate with the message
   * @returns {Promise.<T>} A Promise that will resolve with either the raw
   *                           event message from Cove or null if the method is
   *                           one that Cove does not send a response to
   * @private
   */
Sends a post message to the window of the underlying player element. Takes
a message and a value and combines them in to the format requested by the
PBS Cove API. Returns back a Promise that will resolve when the PBS Cove
API responds with the same message. For messages that PBS does not send
responses to, the Promise will resolve with null. Otherwise the Promise
will resolve with the raw message event from Cove.

@param {String} message The message to pass to the PBS Cove API
@param {String} [value] The value to associate with the message
@returns {Promise.} A Promise that will resolve with either the raw
event message from Cove or null if the method is
one that Cove does not send a response to
@private
Sends a post message to the window of the underlying player element . Takes a message and a value and combines them in to the format requested by the PBS Cove API . Returns back a Promise that will resolve when the PBS Cove API responds with the same message . For messages that PBS does not send responses to the Promise will resolve with null . Otherwise the Promise will resolve with the raw message event from Cove . @param { String } message The message to pass to the PBS Cove API @param { String } [ value ] The value to associate with the message @returns { Promise . } A Promise that will resolve with either the raw event message from Cove or null if the method is one that Cove does not send a response to @private
send(message, value) {
    if (!this._server || !this._server.contentWindow) {
      return Promise.reject(
        {
          status: false,
          message: 'PBSMessageAPI failed to connect to a player instance'
        }
      );
    }
    let sendPromise = new Promise(
      function (resolve, reject) {
        if (typeof value === 'undefined' && noResponse.indexOf(message) === -1) {
          let messageHandler = function (event) {
            if (this._validateEvent(event) &&
              this._testMessageType(event, message)) {
              this._client.removeEventListener(
                'message',
                messageHandler
              );
              let index = this._pending.indexOf(messageHandler);
              if (index > -1) {
                this._pending.splice(index, 1);
              }
              resolve(event);
            }
          }.bind(this);
          this._client.addEventListener(
            'message',
            messageHandler
          );
          this._pending.push(messageHandler);
        } else {
          resolve(null);
        }
      }.bind(this)
    );
    var postMessage = typeof value !== 'undefined' ? message + '::' + value : message;
    this._messages.outgoing = lastElements(
      this._messages.outgoing.concat([postMessage]),
      25
    );
    this._server.contentWindow.postMessage(postMessage, playerOrigin);
    return sendPromise;
  }
send ( message , value ) { if ( ! this . _server || ! this . _server . contentWindow ) { return Promise . reject ( { status : false , message : 'PBSMessageAPI failed to connect to a player instance' } ) ; } let sendPromise = new Promise ( function ( resolve , reject ) { if ( typeof value === 'undefined' && noResponse . indexOf ( message ) === - 1 ) { let messageHandler = function ( event ) { if ( this . _validateEvent ( event ) && this . _testMessageType ( event , message ) ) { this . _client . removeEventListener ( 'message' , messageHandler ) ; let index = this . _pending . indexOf ( messageHandler ) ; if ( index > - 1 ) { this . _pending . splice ( index , 1 ) ; } resolve ( event ) ; } } . bind ( this ) ; this . _client . addEventListener ( 'message' , messageHandler ) ; this . _pending . push ( messageHandler ) ; } else { resolve ( null ) ; } } . bind ( this ) ) ; var postMessage = typeof value !== 'undefined' ? message + '::' + value : message ; this . _messages . outgoing = lastElements ( this . _messages . outgoing . concat ( [ postMessage ] ) , 25 ) ; this . _server . contentWindow . postMessage ( postMessage , playerOrigin ) ; return sendPromise ; }
Sends a post message to the window of the underlying player element.
Sends a post message to the window of the underlying player element .
// Check to make sure that we can access the communication channel // Do not listen for a response for the message types that PBS will not // send a response for. Additionally responses are never sent back for // commands that pass a value // Define the event handler that will resolve the promise, pass along // the response, and finally detach from the window // Make sure that this is a valid event for this player and that // it is a response to the same message type that was requested // Unhook this handler from the window so it is not called again // Successfully resolve the event and pass along the message event // Attach the event handler to listen for the response // For the messages without a response, resolve the promise immediately // Generate the message based on if the value is present // Store the event in the list of outgoing messages // Send the message off to the Cove video player // Return the promise