diff --git a/src/js/ripple/index.js b/src/js/ripple/index.js index 1cbf2d1e..692155f3 100644 --- a/src/js/ripple/index.js +++ b/src/js/ripple/index.js @@ -10,6 +10,7 @@ exports.SerializedObject = require('./serializedobject').SerializedObject; exports.binformat = require('./binformat'); exports.utils = require('./utils'); +exports.Server = require('./server').Server; // Important: We do not guarantee any specific version of SJCL or for any // specific features to be included. The version and configuration may change at diff --git a/src/js/ripple/server.js b/src/js/ripple/server.js index ec68c704..1d7127bc 100644 --- a/src/js/ripple/server.js +++ b/src/js/ripple/server.js @@ -89,6 +89,16 @@ Server.prototype._remote_address = function() { return address; }; +// This is the final interface between client code and a socket connection to a +// `rippled` server. As such, this is a decent hook point to allow a WebSocket +// interface conforming object to be used as a basis to mock rippled. This +// avoids the need to bind a websocket server to a port and allows a more +// synchronous style of code to represent a client <-> server message sequence. +// We can also use this to log a message sequence to a buffer. +Server.prototype.websocket_constructor = function () { + return require('ws'); +}; + Server.prototype.connect = function () { var self = this; @@ -109,7 +119,7 @@ Server.prototype.connect = function () { // We require this late, because websocket shims may be loaded after // ripple-lib. - var WebSocket = require('ws'); + var WebSocket = this.websocket_constructor(); var ws = this._ws = new WebSocket(this._opts.url); this._should_connect = true;