forked from BlueWallet/BlueWallet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtls.js
46 lines (38 loc) · 1.11 KB
/
tls.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**
* @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;