Skip to content

Commit bf05e66

Browse files
committed
docs: Added param and return types
1 parent 3276559 commit bf05e66

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ CONTRIBUTING.md
77
CODE_OF_CONDUCT.md
88
README.md
99
.releaserc
10+
jsconfig.json
1011

1112
# Config files
1213
.babelrc

jsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"compilerOptions": {
3+
"target": "es6",
4+
"allowSyntheticDefaultImports": true,
5+
"checkJs": true
6+
},
7+
"exclude": ["node_modules", "coverage", ".github"]
8+
}

src/TcpServer.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,35 @@ const Sockets = NativeModules.TcpSockets;
55
import TcpSocket from './TcpSocket';
66

77
export default class TcpServer extends TcpSocket {
8+
/**
9+
* @param {number} id
10+
* @param {import("react-native").NativeEventEmitter} eventEmitter
11+
* @param {(socket: TcpSocket) => void} connectionCallback
12+
*/
813
constructor(id, eventEmitter, connectionCallback) {
914
super(id, eventEmitter);
1015
this.connectionCallback = connectionCallback;
16+
/** @type {TcpSocket[]} */
1117
this._connections = [];
18+
this._eventEmitter = eventEmitter;
1219
}
1320

1421
close() {
1522
this.destroy();
1623
this._connections.forEach((clientSocket) => clientSocket.destroy());
1724
}
1825

26+
/**
27+
* @param {(arg0: number) => void} callback
28+
*/
1929
getConnections(callback) {
2030
callback(this._connections.length);
2131
}
2232

33+
/**
34+
* @param {{ port: number; host: any; }} options
35+
* @param {(arg0: any) => void} callback
36+
*/
2337
listen(options, callback) {
2438
let gotOptions = {};
2539
// Normalize args
@@ -45,6 +59,9 @@ export default class TcpServer extends TcpSocket {
4559
return this;
4660
}
4761

62+
/**
63+
* @param {{ id: number; address: string; }} info
64+
*/
4865
_onConnection(info) {
4966
const socket = new TcpSocket(info.id, this._eventEmitter);
5067
socket._registerEvents();

src/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ class TCPSockets {
1212
this._eventEmitter = new NativeEventEmitter(Sockets);
1313
}
1414

15+
/**
16+
* @param {(socket: Socket) => void} connectionListener
17+
*/
1518
createServer(connectionListener) {
1619
return new Server(this.instances++, this._eventEmitter, connectionListener);
1720
}
1821

22+
/**
23+
* @param {{ host: string; port: number; timeout: number; }} options
24+
* @param {(address: string) => void} callback
25+
*/
1926
createConnection(options, callback) {
2027
const tcpSocket = new Socket(this.instances++, this._eventEmitter);
2128
return tcpSocket.connect(options, callback);

0 commit comments

Comments
 (0)