Skip to content

Commit 98d4947

Browse files
chore(release): 3.3.1 [skip ci]
## [3.3.1](v3.3.0...v3.3.1) (2020-02-24) ### Bug Fixes * Fixed TypeScript declaration files not being a module ([3e2213a](3e2213a))
1 parent 3e2213a commit 98d4947

File tree

5 files changed

+235
-1
lines changed

5 files changed

+235
-1
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## [3.3.1](https://github.com/Rapsssito/react-native-tcp-socket/compare/v3.3.0...v3.3.1) (2020-02-24)
2+
3+
4+
### Bug Fixes
5+
6+
* Fixed TypeScript declaration files not being a module ([3e2213a](https://github.com/Rapsssito/react-native-tcp-socket/commit/3e2213a06c6917c8c0696cf31b905cd9e91f52e7))
7+
18
# [3.3.0](https://github.com/Rapsssito/react-native-tcp-socket/compare/v3.2.9...v3.3.0) (2020-02-24)
29

310

lib/types/TcpServer.d.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
export default class TcpServer extends TcpSocket {
2+
/**
3+
* @param {number} id
4+
* @param {import("react-native").NativeEventEmitter} eventEmitter
5+
* @param {(socket: TcpSocket) => void} connectionCallback
6+
*/
7+
constructor(id: number, eventEmitter: import("react-native").NativeEventEmitter, connectionCallback: (socket: TcpSocket) => void);
8+
connectionCallback: (socket: TcpSocket) => void;
9+
/** @type {TcpSocket[]} */
10+
_connections: TcpSocket[];
11+
close(): void;
12+
/**
13+
* @param {(arg0: number) => void} callback
14+
*/
15+
getConnections(callback: (arg0: number) => void): void;
16+
/**
17+
* @param {{ port: number; host: any; }} options
18+
* @param {(arg0: any) => void} callback
19+
* @returns {TcpServer}
20+
*/
21+
listen(options: {
22+
port: number;
23+
host: any;
24+
}, callback: (arg0: any) => void, ...args: any[]): TcpServer;
25+
/**
26+
* @private
27+
* @param {{ id: number; address: string; }} info
28+
*/
29+
private _onConnection;
30+
connect(options: {
31+
port: number;
32+
host?: string | undefined;
33+
timeout?: number | undefined;
34+
localAddress?: string | undefined;
35+
localPort?: number | undefined;
36+
interface?: "wifi" | undefined; /**
37+
* @param {{ port: number; host: any; }} options
38+
* @param {(arg0: any) => void} callback
39+
* @returns {TcpServer}
40+
*/
41+
reuseAddress?: boolean | undefined;
42+
}, callback?: ((address: string) => void) | undefined): TcpServer;
43+
setTimeout(msecs: number, callback?: ((...args: any[]) => void) | undefined): TcpServer;
44+
}
45+
import TcpSocket from "./TcpSocket";

lib/types/TcpSocket.d.ts

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/**
2+
* @typedef {{ port: number; host?: string; timeout?: number; localAddress?: string, localPort?: number, interface?: 'wifi', reuseAddress?: boolean}} ConnectionOptions
3+
*/
4+
export default class TcpSocket {
5+
/**
6+
* Initialices a TcpSocket.
7+
*
8+
* @param {number} id
9+
* @param {import('react-native').NativeEventEmitter} eventEmitter
10+
*/
11+
constructor(id: number, eventEmitter: import("react-native").NativeEventEmitter);
12+
_id: number;
13+
_eventEmitter: import("react-native").NativeEventEmitter;
14+
/** @type {number} */
15+
_state: number;
16+
/** @type {RemovableListener[]} */
17+
_listeners: RemovableListener[];
18+
/**
19+
* Adds a listener to be invoked when events of the specified type are emitted by the `TcpSocket`.
20+
* An optional calling `context` may be provided.
21+
* The data arguments emitted will be passed to the listener callback.
22+
*
23+
* @param {string} event Name of the event to listen to
24+
* @param {(arg0: any) => void} callback Function to invoke when the specified event is emitted
25+
* @param {any} [context] Optional context object to use when invoking the listener
26+
* @returns {RemovableListener}
27+
*/
28+
on(event: string, callback: (arg0: any) => void, context?: any): RemovableListener;
29+
/**
30+
* @private
31+
* @param {string} event
32+
* @param {function(any):void} callback
33+
* @param {any} [context]
34+
*/
35+
private _selectListener;
36+
/**
37+
* @deprecated
38+
*/
39+
off(): void;
40+
/**
41+
* @param {ConnectionOptions} options
42+
* @param {(address: string) => void} [callback]
43+
*/
44+
connect(options: {
45+
port: number;
46+
host?: string | undefined;
47+
timeout?: number | undefined;
48+
localAddress?: string | undefined;
49+
localPort?: number | undefined;
50+
interface?: "wifi" | undefined;
51+
reuseAddress?: boolean | undefined;
52+
}, callback?: ((address: string) => void) | undefined): TcpSocket;
53+
_destroyed: boolean | undefined;
54+
/**
55+
* @private
56+
* @param {number} msecs
57+
* @param {() => void} [wrapper]
58+
*/
59+
private _activeTimer;
60+
_timeout: {
61+
handle: NodeJS.Timeout;
62+
wrapper: () => void;
63+
msecs: number;
64+
} | null | undefined;
65+
/**
66+
* @private
67+
*/
68+
private _clearTimeout;
69+
/**
70+
* @deprecated
71+
* @param {number} msecs
72+
* @param {(...args: any[]) => void } [callback]
73+
*/
74+
setTimeout(msecs: number, callback?: ((...args: any[]) => void) | undefined): TcpSocket;
75+
address(): string | undefined;
76+
/**
77+
* @param {string | Buffer | Uint8Array} data
78+
* @param {BufferEncoding} [encoding]
79+
*/
80+
end(data: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): void;
81+
destroy(): void;
82+
/**
83+
* @protected
84+
*/
85+
protected _registerEvents(): void;
86+
/**
87+
* @private
88+
*/
89+
private _unregisterEvents;
90+
/**
91+
* @private
92+
* @param {string} address
93+
*/
94+
private _onConnect;
95+
/**
96+
* @private
97+
*/
98+
private _onClose;
99+
/**
100+
* @private
101+
*/
102+
private _onError;
103+
/**
104+
* Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
105+
*
106+
* The optional callback parameter will be executed when the data is finally written out, which may not be immediately.
107+
*
108+
* @param {string | Buffer | Uint8Array} buffer
109+
* @param {BufferEncoding} [encoding]
110+
* @param {(error: string | null) => void} [callback]
111+
*/
112+
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;
113+
/**
114+
* @param {string} address
115+
*/
116+
setAsAlreadyConnected(address: string): void;
117+
/**
118+
* @private
119+
* @param {string | Buffer | Uint8Array} buffer
120+
* @param {BufferEncoding} [encoding]
121+
*/
122+
private _generateSendBuffer;
123+
/**
124+
* @private
125+
* @param {string} address
126+
*/
127+
private setConnected;
128+
_address: string | undefined;
129+
/**
130+
* @private
131+
*/
132+
private setDisconnected;
133+
}
134+
export type ConnectionOptions = {
135+
port: number;
136+
host?: string | undefined;
137+
timeout?: number | undefined;
138+
localAddress?: string | undefined;
139+
localPort?: number | undefined;
140+
interface?: "wifi" | undefined;
141+
reuseAddress?: boolean | undefined;
142+
};
143+
declare class RemovableListener {
144+
/**
145+
* @param {import("react-native").EmitterSubscription} listener
146+
* @param {import("react-native").NativeEventEmitter} eventEmitter
147+
*/
148+
constructor(listener: import("react-native").EmitterSubscription, eventEmitter: import("react-native").NativeEventEmitter);
149+
_listener: import("react-native").EmitterSubscription;
150+
_eventEmitter: import("react-native").NativeEventEmitter;
151+
_removed: boolean;
152+
isRemoved(): boolean;
153+
remove(): void;
154+
}
155+
export {};

lib/types/index.d.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default tcpSockets;
2+
declare const tcpSockets: TCPSockets;
3+
declare class TCPSockets {
4+
instances: number;
5+
_eventEmitter: import("react-native").EventEmitter;
6+
/**
7+
* @param {(socket: Socket) => void} connectionListener
8+
* @returns {Server}
9+
*/
10+
createServer(connectionListener: (socket: Socket) => void): Server;
11+
/**
12+
* @param {import('./TcpSocket').ConnectionOptions} options
13+
* @param {(address: string) => void} callback
14+
* @returns {Socket}
15+
*/
16+
createConnection(options: {
17+
port: number;
18+
host?: string | undefined;
19+
timeout?: number | undefined;
20+
localAddress?: string | undefined;
21+
localPort?: number | undefined;
22+
interface?: "wifi" | undefined;
23+
reuseAddress?: boolean | undefined;
24+
}, callback: (address: string) => void): Socket;
25+
}
26+
import Socket from "./TcpSocket";
27+
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": "3.3.0",
4+
"version": "3.3.1",
55
"description": "React Native TCP socket API for Android & iOS",
66
"main": "src/index.js",
77
"types": "lib/types/index.d.ts",

0 commit comments

Comments
 (0)