Skip to content

Commit

Permalink
docs: Added param and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito committed Feb 18, 2020
1 parent 3276559 commit bf05e66
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONTRIBUTING.md
CODE_OF_CONDUCT.md
README.md
.releaserc
jsconfig.json

# Config files
.babelrc
Expand Down
8 changes: 8 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "es6",
"allowSyntheticDefaultImports": true,
"checkJs": true
},
"exclude": ["node_modules", "coverage", ".github"]
}
17 changes: 17 additions & 0 deletions src/TcpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,35 @@ const Sockets = NativeModules.TcpSockets;
import TcpSocket from './TcpSocket';

export default class TcpServer extends TcpSocket {
/**
* @param {number} id
* @param {import("react-native").NativeEventEmitter} eventEmitter
* @param {(socket: TcpSocket) => void} connectionCallback
*/
constructor(id, eventEmitter, connectionCallback) {
super(id, eventEmitter);
this.connectionCallback = connectionCallback;
/** @type {TcpSocket[]} */
this._connections = [];
this._eventEmitter = eventEmitter;
}

close() {
this.destroy();
this._connections.forEach((clientSocket) => clientSocket.destroy());
}

/**
* @param {(arg0: number) => void} callback
*/
getConnections(callback) {
callback(this._connections.length);
}

/**
* @param {{ port: number; host: any; }} options
* @param {(arg0: any) => void} callback
*/
listen(options, callback) {
let gotOptions = {};
// Normalize args
Expand All @@ -45,6 +59,9 @@ export default class TcpServer extends TcpSocket {
return this;
}

/**
* @param {{ id: number; address: string; }} info
*/
_onConnection(info) {
const socket = new TcpSocket(info.id, this._eventEmitter);
socket._registerEvents();
Expand Down
7 changes: 7 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ class TCPSockets {
this._eventEmitter = new NativeEventEmitter(Sockets);
}

/**
* @param {(socket: Socket) => void} connectionListener
*/
createServer(connectionListener) {
return new Server(this.instances++, this._eventEmitter, connectionListener);
}

/**
* @param {{ host: string; port: number; timeout: number; }} options
* @param {(address: string) => void} callback
*/
createConnection(options, callback) {
const tcpSocket = new Socket(this.instances++, this._eventEmitter);
return tcpSocket.connect(options, callback);
Expand Down

0 comments on commit bf05e66

Please sign in to comment.