mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2024-11-19 09:50:15 +01:00
47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
/**
|
|
* @fileOverview adapter for ReactNative TCP module
|
|
* This module mimics the nodejs tls api and is intended to work in RN environment.
|
|
* @see https://github.com/Rapsssito/react-native-tcp-socket
|
|
*/
|
|
|
|
import TcpSocket from 'react-native-tcp-socket';
|
|
|
|
/**
|
|
* Constructor function. Mimicking nodejs/tls api
|
|
*
|
|
* @constructor
|
|
*/
|
|
function connect(config, callback) {
|
|
const client = TcpSocket.createConnection(
|
|
{
|
|
port: config.port,
|
|
host: config.host,
|
|
tls: true,
|
|
tlsCheckValidity: config.rejectUnauthorized,
|
|
},
|
|
callback,
|
|
);
|
|
|
|
// defaults:
|
|
this._noDelay = true;
|
|
|
|
// functions not supported by RN module, yet:
|
|
client.setTimeout = () => {};
|
|
client.setEncoding = () => {};
|
|
client.setKeepAlive = () => {};
|
|
|
|
// we will save `noDelay` and proxy it to socket object when its actually created and connected:
|
|
const realSetNoDelay = client.setNoDelay; // reference to real setter
|
|
client.setNoDelay = noDelay => {
|
|
this._noDelay = noDelay;
|
|
};
|
|
|
|
client.on('connect', () => {
|
|
realSetNoDelay.apply(client, [this._noDelay]);
|
|
});
|
|
|
|
return client;
|
|
}
|
|
|
|
module.exports.connect = connect;
|