<commit_before>'use strict';

import * as dbcrelic from 'dbc-node-newrelic-wrapper';

/**
 * A dummy socket client used for server side rendering.
 * @type {{on: Function, emit: Function}}
 */
const serverSideSocketDummy = {
  on: function() {
  },
  emit: function() {
  }
};

/**
 * socket.io-client cannot be loaded on the server, so if window object
 * @type {boolean|{on: Function, emit: Function}}
 */
const socket = (typeof window !== 'undefined') && require('socket.io-client').connect() || serverSideSocketDummy;

/**
 * Reqistrer an event for the ServiceProvider
 *
 * Returns a class with a method for request and response which are wrappers
 * around the socket.emit and socket.on methods
 *
 * @param {String} event
 * @returns {{request: request, response: response}}
 * @constructor
 */
export default function ServiceProviderSocketClient(event) {
  function request(data) {
    const requestEvent = event + 'Request';
    dbcrelic.addPageAction(requestEvent, {request: data});
    socket.emit(requestEvent, data);
  }

  function addListener(listener) {
    listener(data => socket.emit(event + 'Request', data));
  }

  function response(cb) {
    const responseEvent = event + 'Response';
    socket.on(responseEvent, (data) => {
      dbcrelic.addPageAction(responseEvent, {response: data});
      cb(data);<commit_msg>Accumulated commit of the following from branch 'origin/ready/cleanup':<commit_after>'use strict';

import * as dbcrelic from 'dbc-node-newrelic-wrapper';

/**
 * A dummy socket client used for server side rendering.
 * @type {{on: Function, emit: Function}}
 */
const serverSideSocketDummy = {
  on: function() {
  },
  emit: function() {
  }
};

/**
 * socket.io-client cannot be loaded on the server, so if window object
 * @type {boolean|{on: Function, emit: Function}}
 */
const socket = (typeof window !== 'undefined') && require('socket.io-client').connect() || serverSideSocketDummy;

/**
 * Reqistrer an event for the ServiceProvider
 *
 * Returns a class with a method for request and response which are wrappers
 * around the socket.emit and socket.on methods
 *
 * @param {String} event
 * @returns {{request: request, response: response}}
 * @constructor
 */
export default function ServiceProviderSocketClient(event) {
  function request(data) {
    const requestEvent = event + 'Request';
    socket.emit(requestEvent, data);
    dbcrelic.addPageAction(requestEvent, {request: data});
  }

  function addListener(listener) {
    listener(data => socket.emit(event + 'Request', data));
  }

  function response(cb) {
    const responseEvent = event + 'Response';
    socket.on(responseEvent, (data) => {
      cb(data);
      dbcrelic.addPageAction(responseEvent, {response: data});
{'fraction_non_alphanumeric': 0.13350402340892464, 'fraction_numerical': 0.0, 'mean_word_length': 4.219465648854962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3387151', 'n_tokens_mistral': 786, 'n_tokens_neox': 781, 'n_words': 242}