/* jshint -W078 */

'use strict';

let stream = require('stream');

function BidiTransform(options) {
  this._clientToServer = new stream.Transform();
  this._serverToClient = new stream.Transform();

  if (options.client) {
    this.clientEndState = options.client;
  }
  if (options.server) {
    this.serverEndState = options.server;
  }
}

BidiTransform.prototype = {

  get to() {
    return {
      client: this._serverToClient,
      server: this._clientToServer
    };
  },

  get from() {
    return {
      client: this._clientToServer,
      server: this._serverToClient
    };
  },

  set clientEndState(options) {
    for (let option in options) {
      this._clientToServer._writableState[option] = options[option];
      this._serverToClient._readableState[option] = options[option];
    }
  },

  set serverEndState(options) {
    for (let option in options) {
      this._clientToServer._readableState[option] = options[option];
      this._serverToClient._writableState[option] = options[option];
    }
  }

};

module.exports = BidiTransform;

/* jshint -W078 */

'use strict';

let stream = require('stream');

function BidiTransform(options) {
  this._externalToInternal = new stream.Transform();
  this._internalToExternal = new stream.Transform();

  if (options.external) {
    this.externalState = options.external;
  }
  if (options.internal) {
    this.internalState = options.internal;
  }
}

BidiTransform.prototype = {

  get to() {
    return {
      external: this._internalToExternal,
      internal: this._externalToInternal
    };
  },

  get from() {
    return {
      external: this._externalToInternal,
      internal: this._internalToExternal
    };
  },

  set externalState(options) {
    for (let option in options) {
      this._externalToInternal._writableState[option] = options[option];
      this._internalToExternal._readableState[option] = options[option];
    }
  },

  set internalState(options) {
    for (let option in options) {
      this._externalToInternal._readableState[option] = options[option];
      this._internalToExternal._writableState[option] = options[option];
    }
  }

};

module.exports = BidiTransform;

Rename to internal / external