Allow hooking of the Server WebSocket constructor object

This commit is contained in:
Nicholas Dudfield
2013-08-07 17:11:29 -07:00
parent 67d100796d
commit e5421effd5
2 changed files with 12 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ exports.SerializedObject = require('./serializedobject').SerializedObject;
exports.binformat = require('./binformat'); exports.binformat = require('./binformat');
exports.utils = require('./utils'); exports.utils = require('./utils');
exports.Server = require('./server').Server;
// Important: We do not guarantee any specific version of SJCL or for any // 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 // specific features to be included. The version and configuration may change at

View File

@@ -89,6 +89,16 @@ Server.prototype._remote_address = function() {
return address; 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.websocketConstructor = function () {
return require('ws');
};
Server.prototype.connect = function () { Server.prototype.connect = function () {
var self = this; var self = this;
@@ -109,7 +119,7 @@ Server.prototype.connect = function () {
// We require this late, because websocket shims may be loaded after // We require this late, because websocket shims may be loaded after
// ripple-lib. // ripple-lib.
var WebSocket = require('ws'); var WebSocket = this.websocketConstructor();
var ws = this._ws = new WebSocket(this._opts.url); var ws = this._ws = new WebSocket(this._opts.url);
this._should_connect = true; this._should_connect = true;