From e5421effd5d952ea37529b0d8870c11316280398 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Wed, 7 Aug 2013 17:11:29 -0700 Subject: [PATCH 1/2] Allow hooking of the Server WebSocket constructor object --- src/js/ripple/index.js | 1 + src/js/ripple/server.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) 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..a31d0f80 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.websocketConstructor = 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.websocketConstructor(); var ws = this._ws = new WebSocket(this._opts.url); this._should_connect = true; From e8144128d083b01615f1da05f8588e77eb71f500 Mon Sep 17 00:00:00 2001 From: Nicholas Dudfield Date: Wed, 7 Aug 2013 17:20:23 -0700 Subject: [PATCH 2/2] Naming style, oopz --- src/js/ripple/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/ripple/server.js b/src/js/ripple/server.js index a31d0f80..1d7127bc 100644 --- a/src/js/ripple/server.js +++ b/src/js/ripple/server.js @@ -95,7 +95,7 @@ Server.prototype._remote_address = function() { // 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 () { +Server.prototype.websocket_constructor = function () { return require('ws'); }; @@ -119,7 +119,7 @@ Server.prototype.connect = function () { // We require this late, because websocket shims may be loaded after // ripple-lib. - var WebSocket = this.websocketConstructor(); + var WebSocket = this.websocket_constructor(); var ws = this._ws = new WebSocket(this._opts.url); this._should_connect = true;