onDataRead = function(dataBuffer) {
      var a = new Uint8Array(dataBuffer);
      for (var i = 0; i < a.length; i++)
        data.push(a[i]);

      while (data.length) {
        var length_code = -1;
        var data_start = 6;
        var mask;
        var fin = (data[0] & 128) >> 7;
        var op = data[0] & 15;

        if (data.length > 1)
          length_code = data[1] & 127;
        if (length_code > 125) {
          if ((length_code == 126 && data.length > 7) ||
              (length_code == 127 && data.length > 14)) {
            if (length_code == 126) {
              length_code = data[2] * 256 + data[3];
              mask = data.slice(4, 8);
              data_start = 8;
            } else if (length_code == 127) {
              length_code = 0;
              for (var i = 0; i < 8; i++) {
                length_code = length_code * 256 + data[2 + i];
              }
              mask = data.slice(10, 14);
              data_start = 14;
            }
          } else {
            length_code = -1; // Insufficient data to compute length
          }
        } else {
          if (data.length > 5)
            mask = data.slice(2, 6);
        }

        if (length_code > -1 && data.length >= data_start + length_code) {
          var decoded = data.slice(data_start, data_start + length_code).map(function(byte, index) {
            return byte ^ mask[index % 4];
          });
          if (op == 1) {
            decoded = ary2utf8(decoded);
          }
          data = data.slice(data_start + length_code);
          if (fin && op > 0) {
            // Unfragmented message.
            if (!t.onFrame_(op, decoded))
              return;
          } else {
            // Fragmented message.
            fragmentedOp = fragmentedOp || op;
            fragmentedMessages.push(decoded);
            if (fin) {
              var joinMessage = null;
              if (op == 1) {
                joinMessage = fragmentedMessagess.join('');
              } else {
                joinMessage = fragmentedMessages.reduce(function(pre, cur) {
                  return Array.prototype.push.apply(pre, cur);
                }, []);
              }
              if (!t.onFrame_(fragmentedOp, joinMessage))
                return;
              fragmentedOp = 0;
              fragmentedMessages = [];
            }
          }
        } else {
          break; // Insufficient data, wait for more.
        }
      }

      return t.pSocket_.read().then(onDataRead);
    }
Begin closing the WebSocket. Note that the WebSocket protocol uses a
handshake to close the connection, so this call will begin the closing
process.