Skip to content

Commit c176a44

Browse files
chore(release): 5.0.0 [skip ci]
# [5.0.0](v4.5.7...v5.0.0) (2021-02-26) ### Features * Add socket address properties ([#94](#94)) ([1658831](1658831)) ### BREAKING CHANGES * Events types and callbacks now match NodeJS official API.
1 parent 1658831 commit c176a44

File tree

6 files changed

+110
-50
lines changed

6 files changed

+110
-50
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# [5.0.0](https://github.com/Rapsssito/react-native-tcp-socket/compare/v4.5.7...v5.0.0) (2021-02-26)
2+
3+
4+
### Features
5+
6+
* Add socket address properties ([#94](https://github.com/Rapsssito/react-native-tcp-socket/issues/94)) ([1658831](https://github.com/Rapsssito/react-native-tcp-socket/commit/1658831bad5696c776577fc85572c04d300008f4))
7+
8+
9+
### BREAKING CHANGES
10+
11+
* Events types and callbacks now match NodeJS official API.
12+
113
## [4.5.7](https://github.com/Rapsssito/react-native-tcp-socket/compare/v4.5.6...v4.5.7) (2021-02-26)
214

315

coverage/coverage-final.json

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

lib/types/TcpServer.d.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,70 @@
11
/**
22
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
3+
*
4+
* @extends {EventEmitter<'connection' | 'listening' | 'error' | 'close', any>}
35
*/
4-
export default class TcpServer extends TcpSocket {
6+
export default class TcpServer extends EventEmitter<"error" | "close" | "connection" | "listening", any> {
57
/**
68
* @param {number} id
79
* @param {NativeEventEmitter} eventEmitter
810
* @param {(socket: TcpSocket) => void} connectionCallback
911
*/
1012
constructor(id: number, eventEmitter: NativeEventEmitter, connectionCallback: (socket: TcpSocket) => void);
13+
/** @private */
14+
private _id;
15+
/** @private */
16+
private _eventEmitter;
1117
connectionCallback: (socket: TcpSocket) => void;
1218
/** @type {TcpSocket[]} */
1319
_connections: TcpSocket[];
14-
_connectionsListener: import("react-native").EmitterSubscription | undefined;
20+
/** @private */
21+
private _localAddress;
22+
/** @private */
23+
private _localPort;
24+
/** @private */
25+
private _localFamily;
1526
/**
1627
* @param {{ port: number; host: string; reuseAddress?: boolean}} options
17-
* @param {(arg0: any) => void} [callback]
28+
* @param {() => void} [callback]
1829
* @returns {TcpServer}
1930
*/
2031
listen(options: {
2132
port: number;
2233
host: string;
2334
reuseAddress?: boolean;
24-
}, callback?: ((arg0: any) => void) | undefined): TcpServer;
35+
}, callback?: (() => void) | undefined): TcpServer;
2536
/**
2637
* @param {(arg0: number) => void} callback
2738
*/
2839
getConnections(callback: (arg0: number) => void): void;
2940
close(): void;
41+
/**
42+
* @returns {import('./TcpSocket').AddressInfo | null}
43+
*/
44+
address(): import('./TcpSocket').AddressInfo | null;
45+
ref(): void;
46+
unref(): void;
47+
/**
48+
* @private
49+
*/
50+
private _registerEvents;
51+
_errorListener: import("react-native").EmitterSubscription | undefined;
52+
_closeListener: import("react-native").EmitterSubscription | undefined;
53+
_connectionsListener: import("react-native").EmitterSubscription | undefined;
54+
/**
55+
* @private
56+
*/
57+
private _unregisterEvents;
58+
/**
59+
* @private
60+
*/
61+
private _setDisconnected;
3062
/**
3163
* @private
32-
* @param {{ id: number; address: string; }} info
64+
* @param {{ id: number; connection: import('./TcpSocket').NativeConnectionInfo; }} info
3365
*/
3466
private _onConnection;
3567
}
3668
export type NativeEventEmitter = import("react-native").NativeEventEmitter;
69+
import EventEmitter from "eventemitter3";
3770
import TcpSocket from "./TcpSocket";

lib/types/TcpSocket.d.ts

Lines changed: 55 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
*
44
* @typedef {import('react-native').NativeEventEmitter} NativeEventEmitter
55
*
6+
* @typedef {{address: string, family: string, port: number}} AddressInfo
7+
*
8+
* @typedef {{localAddress: string, localPort: number, remoteAddress: string, remotePort: number, remoteFamily: string}} NativeConnectionInfo
9+
*
610
* @typedef {{
711
* port: number;
812
* host?: string;
@@ -15,20 +19,22 @@
1519
* tlsCheckValidity?: boolean,
1620
* tlsCert?: any,
1721
* }} ConnectionOptions
22+
*
23+
* @extends {EventEmitter<'connect' | 'timeout' | 'data' | 'error' | 'close', any>}
1824
*/
19-
export default class TcpSocket extends EventEmitter {
25+
export default class TcpSocket extends EventEmitter<"connect" | "timeout" | "data" | "error" | "close", any> {
2026
/**
2127
* Initialices a TcpSocket.
2228
*
2329
* @param {number} id
2430
* @param {NativeEventEmitter} eventEmitter
25-
* @param {string} [address]
31+
* @param {NativeConnectionInfo} [connectionInfo]
2632
*/
27-
constructor(id: number, eventEmitter: NativeEventEmitter, address?: string | undefined);
28-
/** @protected */
29-
protected _id: number;
30-
/** @protected */
31-
protected _eventEmitter: import("react-native").NativeEventEmitter;
33+
constructor(id: number, eventEmitter: NativeEventEmitter, connectionInfo?: NativeConnectionInfo | undefined);
34+
/** @private */
35+
private _id;
36+
/** @private */
37+
private _eventEmitter;
3238
/** @type {number} @private */
3339
private _timeoutMsecs;
3440
/** @private */
@@ -37,23 +43,16 @@ export default class TcpSocket extends EventEmitter {
3743
private _state;
3844
/** @private */
3945
private _encoding;
40-
/**
41-
* @protected
42-
*/
43-
protected _registerEvents(): void;
44-
_dataListener: import("react-native").EmitterSubscription | undefined;
45-
_errorListener: import("react-native").EmitterSubscription | undefined;
46-
_closeListener: import("react-native").EmitterSubscription | undefined;
47-
_connectListener: import("react-native").EmitterSubscription | undefined;
48-
/**
49-
* @protected
50-
*/
51-
protected _unregisterEvents(): void;
46+
localAddress: string | undefined;
47+
localPort: number | undefined;
48+
remoteAddress: string | undefined;
49+
remotePort: number | undefined;
50+
remoteFamily: string | undefined;
5251
/**
5352
* @param {ConnectionOptions} options
54-
* @param {(address: string) => void} [callback]
53+
* @param {() => void} [callback]
5554
*/
56-
connect(options: ConnectionOptions, callback?: ((address: string) => void) | undefined): TcpSocket;
55+
connect(options: ConnectionOptions, callback?: (() => void) | undefined): TcpSocket;
5756
_destroyed: boolean | undefined;
5857
/**
5958
* Sets the socket to timeout after `timeout` milliseconds of inactivity on the socket. By default `TcpSocket` do not have a timeout.
@@ -107,26 +106,19 @@ export default class TcpSocket extends EventEmitter {
107106
* @param {number} initialDelay ***IGNORED**. Default: `0`
108107
*/
109108
setKeepAlive(enable?: boolean, initialDelay?: number): TcpSocket;
110-
address(): string | undefined;
109+
/**
110+
* Returns the bound `address`, the address `family` name and `port` of the socket as reported
111+
* by the operating system: `{ port: 12346, family: 'IPv4', address: '127.0.0.1' }`.
112+
*
113+
* @returns {AddressInfo | {}}
114+
*/
115+
address(): AddressInfo | {};
111116
/**
112117
* @param {string | Buffer | Uint8Array} data
113118
* @param {BufferEncoding} [encoding]
114119
*/
115120
end(data: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): void;
116121
destroy(): void;
117-
/**
118-
* @private
119-
* @param {string} address
120-
*/
121-
private _onConnect;
122-
/**
123-
* @private
124-
*/
125-
private _onClose;
126-
/**
127-
* @private
128-
*/
129-
private _onError;
130122
/**
131123
* Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
132124
*
@@ -137,6 +129,20 @@ export default class TcpSocket extends EventEmitter {
137129
* @param {(error: string | null) => void} [callback]
138130
*/
139131
write(buffer: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, callback?: ((error: string | null) => void) | undefined): void;
132+
ref(): void;
133+
unref(): void;
134+
/**
135+
* @private
136+
*/
137+
private _registerEvents;
138+
_dataListener: import("react-native").EmitterSubscription | undefined;
139+
_errorListener: import("react-native").EmitterSubscription | undefined;
140+
_closeListener: import("react-native").EmitterSubscription | undefined;
141+
_connectListener: import("react-native").EmitterSubscription | undefined;
142+
/**
143+
* @private
144+
*/
145+
private _unregisterEvents;
140146
/**
141147
* @private
142148
* @param {string | Buffer | Uint8Array} buffer
@@ -145,19 +151,28 @@ export default class TcpSocket extends EventEmitter {
145151
private _generateSendBuffer;
146152
/**
147153
* @private
148-
* @param {string} address
154+
* @param {NativeConnectionInfo} connectionInfo
149155
*/
150156
private _setConnected;
151-
_address: string | undefined;
152157
/**
153158
* @private
154159
*/
155160
private _setDisconnected;
156-
ref(): void;
157-
unref(): void;
158161
}
159162
export type BufferEncoding = "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex";
160163
export type NativeEventEmitter = import("react-native").NativeEventEmitter;
164+
export type AddressInfo = {
165+
address: string;
166+
family: string;
167+
port: number;
168+
};
169+
export type NativeConnectionInfo = {
170+
localAddress: string;
171+
localPort: number;
172+
remoteAddress: string;
173+
remotePort: number;
174+
remoteFamily: string;
175+
};
161176
export type ConnectionOptions = {
162177
port: number;
163178
host?: string | undefined;
@@ -170,5 +185,5 @@ export type ConnectionOptions = {
170185
tlsCheckValidity?: boolean | undefined;
171186
tlsCert?: any;
172187
};
173-
import { EventEmitter } from "events";
188+
import EventEmitter from "eventemitter3";
174189
import { Buffer } from "buffer";

lib/types/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ declare class TCPSockets {
1010
createServer(connectionListener: (socket: Socket) => void): Server;
1111
/**
1212
* @param {import('./TcpSocket').ConnectionOptions} options
13-
* @param {(address: string) => void} callback
13+
* @param {() => void} callback
1414
* @returns {Socket}
1515
*/
16-
createConnection(options: import('./TcpSocket').ConnectionOptions, callback: (address: string) => void): Socket;
16+
createConnection(options: import('./TcpSocket').ConnectionOptions, callback: () => void): Socket;
1717
}
1818
import Socket from "./TcpSocket";
1919
import Server from "./TcpServer";

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-tcp-socket",
33
"title": "React Native Tcp Socket",
4-
"version": "4.5.7",
4+
"version": "5.0.0",
55
"description": "React Native TCP socket API for Android & iOS with SSL/TLS support",
66
"main": "src/index.js",
77
"types": "lib/types/index.d.ts",

0 commit comments

Comments
 (0)