More net stub
This commit is contained in:
parent
5e85ae4ab7
commit
0fd8fb595f
|
@ -1,5 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* TCP transport for Node. Should be compatible with PyBitmessage.
|
* TCP transport. Should be compatible with PyBitmessage. Available only
|
||||||
|
* for Node.js.
|
||||||
* @module bitmessage/net/tcp
|
* @module bitmessage/net/tcp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
/**
|
||||||
|
* WebSocket transport. Generally needed because browsers can't handle
|
||||||
|
* TCP sockets so we proxy messages from clients via WebSocket into TCP
|
||||||
|
* data packets.
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var inherits = require("inherits");
|
||||||
|
var assert = require("../_util").assert;
|
||||||
|
var BaseTransport = require("./base").BaseTransport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket transport constructor.
|
||||||
|
* @constructor
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function Transport() {
|
||||||
|
Transport.super_.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inherits(Transport, BaseTransport);
|
||||||
|
|
||||||
|
Transport.prototype.connect = function(opts) {
|
||||||
|
assert(!this._client, "Already connected");
|
||||||
|
this._client = new WebSocket(opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.Transport = Transport;
|
|
@ -0,0 +1,38 @@
|
||||||
|
/**
|
||||||
|
* WebSocket transport. Generally needed because browsers can't handle
|
||||||
|
* TCP sockets so we proxy messages from clients via WebSocket into TCP
|
||||||
|
* data packets.
|
||||||
|
* @module bitmessage/net/ws
|
||||||
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var inherits = require("inherits");
|
||||||
|
var WebSocket = require("ws"); // jshint ignore:line
|
||||||
|
var assert = require("../_util").assert;
|
||||||
|
var BaseTransport = require("./base").BaseTransport;
|
||||||
|
|
||||||
|
var WebSocketServer = WebSocket.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WebSocket transport constructor.
|
||||||
|
* @constructor
|
||||||
|
* @static
|
||||||
|
*/
|
||||||
|
function Transport() {
|
||||||
|
Transport.super_.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
inherits(Transport, BaseTransport);
|
||||||
|
|
||||||
|
Transport.prototype.connect = function(opts) {
|
||||||
|
assert(!this._client, "Already connected");
|
||||||
|
this._client = new WebSocket(opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
Transport.prototype.listen = function(opts) {
|
||||||
|
assert(!this._server, "Already listening");
|
||||||
|
this._server = new WebSocketServer(opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.Transport = Transport;
|
|
@ -1,7 +1,7 @@
|
||||||
var bitmessage = require("../lib");
|
var bitmessage = require("../lib");
|
||||||
var structs = bitmessage.structs;
|
var structs = bitmessage.structs;
|
||||||
var message = structs.message;
|
var message = structs.message;
|
||||||
// var WsTransport = require("../lib/net/ws").Transport;
|
var WsTransport = require("../lib/net/ws").Transport;
|
||||||
|
|
||||||
if (!process.browser) {
|
if (!process.browser) {
|
||||||
var TcpTransport = require("../lib/net/tcp").Transport;
|
var TcpTransport = require("../lib/net/tcp").Transport;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user