<commit_before>/**
 * <NAME>
 * University of South Carolina, 2016
 * http://www.seis.sc.edu
 */

import * as miniseed from 'seisplotjs-miniseed';
import * as RSVP from 'rsvp';
import moment from 'moment';

/* reexport */
export { miniseed };

RSVP.on('error', function(reason) {
  console.assert(false, reason);
});

export class SeedlinkConnection {

  /** creates a seedlink connection to the given url.
    * requestConfig is an array of seedlink commands
    * like: 
    *   [ 'STATION JSC CO',
    *     'SELECT 00BHZ.D' ]
    * and receiveMiniseedFn is the callback function that
    * will be invoked for each seedlink packet received
    * which contains 'sequence', a sequence number
    * and 'miniseed', a single miniseed record.
    * The connection is not made until the connect() method is called.
    */
  constructor(url, requestConfig, receiveMiniseedFn, errorFn) {
    this.url = url;
    this.requestConfig = requestConfig;
    this.receiveMiniseedFn = receiveMiniseedFn;
    this.errorFn = errorFn;
    this.command = 'DATA';
  }

  setTimeCommand(startDate) {
    this.command = "TIME "+moment(startDate).format("YYYY,MM,DD,HH,mm,ss");
  }

  connect() {
    this.webSocket = new WebSocket(this.url, "seedlink");
//    this.webSocket.onmessage(this.handle);
    this.webSocket.binaryType = 'arraybuffer';
    const that = this;
    this.webSocket.onopen = function(event) {
      console.log("In onopen");
      that.sendHello(that.webSocket)
      .then(function(val) {
        return that.sendCmdArray(that.webSocket, that.requestConfig);
      })
      .then(function(val) {
        console.log("before send "+that.command);
        return that.sendCmdArray(that.webSocket, [ that.command ]);
      })
      .then(function(val) {
        console.log("wait for miniseed ");
        that.webSocket.onmessage = function(event) {
          that.handle(event);
        };
        that.webSocket.send('END\r');
        return val;
      }, function(err) {
        console.log("reject: "+err);
        that.close();
      });
    };
  }
<commit_msg>do not send protocol string until/if server supports it, causes chrome to not work<commit_after>/**
 * <NAME>
 * University of South Carolina, 2016
 * http://www.seis.sc.edu
 */

import * as miniseed from 'seisplotjs-miniseed';
import * as RSVP from 'rsvp';
import moment from 'moment';

/* reexport */
export { miniseed };

RSVP.on('error', function(reason) {
  console.assert(false, reason);
});

export class SeedlinkConnection {

  /** creates a seedlink connection to the given url.
    * requestConfig is an array of seedlink commands
    * like: 
    *   [ 'STATION JSC CO',
    *     'SELECT 00BHZ.D' ]
    * and receiveMiniseedFn is the callback function that
    * will be invoked for each seedlink packet received
    * which contains 'sequence', a sequence number
    * and 'miniseed', a single miniseed record.
    * The connection is not made until the connect() method is called.
    */
  constructor(url, requestConfig, receiveMiniseedFn, errorFn) {
    this.url = url;
    this.requestConfig = requestConfig;
    this.receiveMiniseedFn = receiveMiniseedFn;
    this.errorFn = errorFn;
    this.command = 'DATA';
  }

  setTimeCommand(startDate) {
    this.command = "TIME "+moment(startDate).format("YYYY,MM,DD,HH,mm,ss");
  }

  connect() {
//    this.webSocket = new WebSocket(this.url, "seedlink");
    this.webSocket = new WebSocket(this.url);
//    this.webSocket.onmessage(this.handle);
    this.webSocket.binaryType = 'arraybuffer';
    const that = this;
    this.webSocket.onopen = function(event) {
      console.log("In onopen");
      that.sendHello(that.webSocket)
      .then(function(val) {
        return that.sendCmdArray(that.webSocket, that.requestConfig);
      })
      .then(function(val) {
        console.log("before send "+that.command);
        return that.sendCmdArray(that.webSocket, [ that.command ]);
      })
      .then(function(val) {
        console.log("wait for miniseed ");
        that.webSocket.onmessage = function(event) {
          that.handle(event);
        };
        that.webSocket.send('END\r');
        return val;
      }, function(err) {
        console.log("reject: "+err);
        that.close();
      });
    };
  }

{'fraction_non_alphanumeric': 0.1307312485304491, 'fraction_numerical': 0.0028215377380672465, 'mean_word_length': 2.8920402561756635, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '604952', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1312, 'n_words': 316}