Skip to content

Commit

Permalink
fix: Update TypeScript declaration files
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapsssito committed Dec 23, 2020
1 parent 5186d95 commit b55a260
Show file tree
Hide file tree
Showing 7 changed files with 1,451 additions and 605 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ client.on('close', function(){
```javascript
const server = TcpSocket.createServer(function(socket) {
socket.on('data', (data) => {
socket.write('Echo server', data);
socket.write('Echo server ' + data);
});

socket.on('error', (error) => {
Expand Down
1 change: 1 addition & 0 deletions __tests__/index.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { expect, test } from '@jest/globals';
import TcpSockets from '../src/index';
import TcpServer from '../src/TcpServer';
import TcpSocket from '../src/TcpSocket';
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"@semantic-release/git": "^9.0.0",
"@semantic-release/github": "^7.0.0",
"@semantic-release/npm": "^7.0.0",
"@types/events": "^3.0.0",
"@types/jest": "^25.1.3",
"@types/react-native": "^0.61.17",
"babel-eslint": "^10.1.0",
Expand All @@ -70,13 +71,13 @@
"eslint-plugin-jest": "^23.6.0",
"eslint-plugin-jsdoc": "^21.0.0",
"eslint-plugin-prettier": "^3.1.1",
"jest": "^24.9.0",
"jest": "^26.6.3",
"metro-react-native-babel-preset": "^0.58.0",
"prettier": "^1.18.2",
"react": "16.9.0",
"react-native": "0.60.0",
"semantic-release": "^17.0.1",
"typescript": "^3.8.2"
"typescript": "^4.1.3"
},
"dependencies": {
"buffer": "^5.4.3",
Expand Down
5 changes: 4 additions & 1 deletion src/TcpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { NativeModules } from 'react-native';
const Sockets = NativeModules.TcpSockets;
import TcpSocket from './TcpSocket';

/**
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
*/
export default class TcpServer extends TcpSocket {
/**
* @param {number} id
* @param {import("react-native").NativeEventEmitter} eventEmitter
* @param {NativeEventEmitter} eventEmitter
* @param {(socket: TcpSocket) => void} connectionCallback
*/
constructor(id, eventEmitter, connectionCallback) {
Expand Down
16 changes: 12 additions & 4 deletions src/TcpSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import { NativeModules, Image } from 'react-native';
import { EventEmitter } from 'events';
const Buffer = (global.Buffer = global.Buffer || require('buffer').Buffer);
import { Buffer } from 'buffer';
const Sockets = NativeModules.TcpSockets;

const STATE = {
Expand All @@ -12,6 +12,10 @@ const STATE = {
};

/**
* @typedef {"ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"} BufferEncoding
*
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
*
* @typedef {{
* port: number;
* host?: string;
Expand All @@ -30,18 +34,22 @@ export default class TcpSocket extends EventEmitter {
* Initialices a TcpSocket.
*
* @param {number} id
* @param {import('react-native').NativeEventEmitter} eventEmitter
* @param {NativeEventEmitter} eventEmitter
* @param {string} [address]
*/
constructor(id, eventEmitter, address) {
super();
/** @protected */
this._id = id;
/** @protected */
this._eventEmitter = eventEmitter;
/** @type {number} */
/** @type {number} @private */
this._timeoutMsecs = 0;
/** @private */
this._timeout = undefined;
/** @type {number} */
/** @type {number} @private */
this._state = STATE.DISCONNECTED;
/** @private */
this._encoding = undefined;
this._registerEvents();
if (address != undefined) this._setConnected(address);
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"typeRoots": ["@types/events"]
},
"include": ["src/", "__tests__/", "__mocks__/"],
}
Loading

0 comments on commit b55a260

Please sign in to comment.