Skip to content

Commit 49cd021

Browse files
chore(release): 5.3.0 [skip ci]
# [5.3.0](v5.2.1...v5.3.0) (2021-08-27) ### Features * Implement backpressure handling ([#115](#115)) ([8a90f32](8a90f32))
1 parent 8a90f32 commit 49cd021

File tree

5 files changed

+94
-9
lines changed

5 files changed

+94
-9
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [5.3.0](https://github.com/Rapsssito/react-native-tcp-socket/compare/v5.2.1...v5.3.0) (2021-08-27)
2+
3+
4+
### Features
5+
6+
* Implement backpressure handling ([#115](https://github.com/Rapsssito/react-native-tcp-socket/issues/115)) ([8a90f32](https://github.com/Rapsssito/react-native-tcp-socket/commit/8a90f32077417f0a2bb9d349470d078366e4fc6c))
7+
18
## [5.2.1](https://github.com/Rapsssito/react-native-tcp-socket/compare/v5.2.0...v5.2.1) (2021-06-09)
29

310

coverage/coverage-final.json

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

lib/types/Server.d.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/**
2-
* @extends {EventEmitter<'connection' | 'listening' | 'error' | 'close', any>}
2+
* @typedef {object} ServerEvents
3+
* @property {() => void} close
4+
* @property {(socket: Socket) => void} connection
5+
* @property {() => void} listening
6+
* @property {(err: Error) => void} error
7+
*
8+
* @extends {EventEmitter<ServerEvents, any>}
39
*/
4-
export default class Server extends EventEmitter<"error" | "close" | "connection" | "listening", any> {
10+
export default class Server extends EventEmitter<ServerEvents, any> {
511
/**
612
* @param {(socket: Socket) => void} [connectionCallback] Automatically set as a listener for the `'connection'` event.
713
*/
@@ -84,5 +90,11 @@ export default class Server extends EventEmitter<"error" | "close" | "connection
8490
*/
8591
private _buildSocket;
8692
}
93+
export type ServerEvents = {
94+
close: () => void;
95+
connection: (socket: Socket) => void;
96+
listening: () => void;
97+
error: (err: Error) => void;
98+
};
8799
import EventEmitter from "eventemitter3";
88100
import Socket from "./Socket";

lib/types/Socket.d.ts

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,27 @@
2020
* tlsCert?: any,
2121
* }} ConnectionOptions
2222
*
23-
* @extends {EventEmitter<'connect' | 'timeout' | 'data' | 'error' | 'close', any>}
23+
* @typedef {object} ReadableEvents
24+
* @property {() => void} pause
25+
* @property {() => void} resume
26+
*
27+
* @typedef {object} SocketEvents
28+
* @property {(had_error: boolean) => void} close
29+
* @property {() => void} connect
30+
* @property {(data: Buffer | string) => void} data
31+
* @property {() => void} drain
32+
* @property {(err: Error) => void} error
33+
* @property {() => void} timeout
34+
*
35+
* @extends {EventEmitter<SocketEvents & ReadableEvents, any>}
2436
*/
25-
export default class Socket extends EventEmitter<"connect" | "timeout" | "data" | "error" | "close", any> {
37+
export default class Socket extends EventEmitter<SocketEvents & ReadableEvents, any> {
2638
/** @private */
2739
private _id;
2840
/** @private */
2941
private _eventEmitter;
42+
/** @type {EventEmitter<'written', any>} @private */
43+
private _msgEvtEmitter;
3044
/** @type {number} @private */
3145
private _timeoutMsecs;
3246
/** @private */
@@ -35,6 +49,24 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
3549
private _state;
3650
/** @private */
3751
private _encoding;
52+
/** @private */
53+
private _msgId;
54+
/** @private */
55+
private _lastRcvMsgId;
56+
/** @private */
57+
private _lastSentMsgId;
58+
/** @private */
59+
private _paused;
60+
/** @private */
61+
private _resuming;
62+
/** @private */
63+
private _writeBufferSize;
64+
/** @type {{ id: number; data: string; }[]} @private */
65+
private _pausedDataEvents;
66+
readableHighWaterMark: number;
67+
writableHighWaterMark: number;
68+
writableNeedDrain: boolean;
69+
bytesSent: number;
3870
localAddress: string | undefined;
3971
localPort: number | undefined;
4072
remoteAddress: string | undefined;
@@ -124,15 +156,36 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
124156
/**
125157
* Sends data on the socket. The second parameter specifies the encoding in the case of a string — it defaults to UTF8 encoding.
126158
*
159+
* Returns `true` if the entire data was flushed successfully to the kernel buffer. Returns `false` if all or part of the data
160+
* was queued in user memory. `'drain'` will be emitted when the buffer is again free.
161+
*
127162
* The optional callback parameter will be executed when the data is finally written out, which may not be immediately.
128163
*
129164
* @param {string | Buffer | Uint8Array} buffer
130165
* @param {BufferEncoding} [encoding]
131-
* @param {(error: string | null) => void} [callback]
166+
* @param {(err?: Error) => void} [cb]
167+
*
168+
* @return {boolean}
169+
*/
170+
write(buffer: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined, cb?: ((err?: Error | undefined) => void) | undefined): boolean;
171+
/**
172+
* Pauses the reading of data. That is, `'data'` events will not be emitted. Useful to throttle back an upload.
173+
*/
174+
pause(): void;
175+
/**
176+
* Resumes reading after a call to `socket.pause()`.
132177
*/
133-
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;
178+
resume(): void;
134179
ref(): void;
135180
unref(): void;
181+
/**
182+
* @private
183+
*/
184+
private _recoverDataEventsAfterPause;
185+
/**
186+
* @private
187+
*/
188+
private _onDeviceDataEvt;
136189
/**
137190
* @private
138191
*/
@@ -141,6 +194,7 @@ export default class Socket extends EventEmitter<"connect" | "timeout" | "data"
141194
_errorListener: import("react-native").EmitterSubscription | undefined;
142195
_closeListener: import("react-native").EmitterSubscription | undefined;
143196
_connectListener: import("react-native").EmitterSubscription | undefined;
197+
_writtenListener: import("react-native").EmitterSubscription | undefined;
144198
/**
145199
* @private
146200
*/
@@ -182,5 +236,17 @@ export type ConnectionOptions = {
182236
tlsCheckValidity?: boolean | undefined;
183237
tlsCert?: any;
184238
};
239+
export type ReadableEvents = {
240+
pause: () => void;
241+
resume: () => void;
242+
};
243+
export type SocketEvents = {
244+
close: (had_error: boolean) => void;
245+
connect: () => void;
246+
data: (data: Buffer | string) => void;
247+
drain: () => void;
248+
error: (err: Error) => void;
249+
timeout: () => void;
250+
};
185251
import EventEmitter from "eventemitter3";
186252
import { Buffer } from "buffer";

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": "5.2.1",
4+
"version": "5.3.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)