mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-27 23:55:49 +00:00
Allow hooking of the Server WebSocket constructor object
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user