Skip to content

Commit

Permalink
chore(release): 4.0.0 [skip ci]
Browse files Browse the repository at this point in the history
# [4.0.0](v3.7.1...v4.0.0) (2020-06-16)

### Features

* Switch to NodeJS's EventEmitter as parent class ([#55](#55)) ([d21bb0b](d21bb0b)), closes [#41](#41)

### BREAKING CHANGES

* Sockets will no longer return RemovableListeners when calling their addListener() method. Now they inherit all the event methods from Node's EventEmitter class.
  • Loading branch information
semantic-release-bot committed Jun 16, 2020
1 parent d21bb0b commit 560c7f4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 64 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# [4.0.0](https://github.com/Rapsssito/react-native-tcp-socket/compare/v3.7.1...v4.0.0) (2020-06-16)


### Features

* Switch to NodeJS's EventEmitter as parent class ([#55](https://github.com/Rapsssito/react-native-tcp-socket/issues/55)) ([d21bb0b](https://github.com/Rapsssito/react-native-tcp-socket/commit/d21bb0b8d0ce0705c10bcde773088624a3bb95ec)), closes [#41](https://github.com/Rapsssito/react-native-tcp-socket/issues/41)


### BREAKING CHANGES

* Sockets will no longer return RemovableListeners when calling their addListener() method. Now they inherit all the event methods from Node's EventEmitter class.

## [3.7.1](https://github.com/Rapsssito/react-native-tcp-socket/compare/v3.7.0...v3.7.1) (2020-06-14)


Expand Down
4 changes: 4 additions & 0 deletions coverage/coverage-final.json

Large diffs are not rendered by default.

35 changes: 21 additions & 14 deletions lib/types/TcpServer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,22 @@ export default class TcpServer extends TcpSocket {
connectionCallback: (socket: TcpSocket) => void;
/** @type {TcpSocket[]} */
_connections: TcpSocket[];
close(): void;
/**
* @param {(arg0: number) => void} callback
*/
getConnections(callback: (arg0: number) => void): void;
_connectionsListener: import("react-native").EmitterSubscription | undefined;
/**
* @param {{ port: number; host: any; }} options
* @param {(arg0: any) => void} callback
* @param {{ port: number; host: string; reuseAddress?: boolean}} options
* @param {(arg0: any) => void} [callback]
* @returns {TcpServer}
*/
listen(options: {
port: number;
host: any;
}, callback: (arg0: any) => void, ...args: any[]): TcpServer;
host: string;
reuseAddress?: boolean | undefined;
}, callback?: ((arg0: any) => void) | undefined): TcpServer;
/**
* @param {(arg0: number) => void} callback
*/
getConnections(callback: (arg0: number) => void): void;
close(): void;
/**
* @private
* @param {{ id: number; address: string; }} info
Expand All @@ -32,17 +34,22 @@ export default class TcpServer extends TcpSocket {
host?: string | undefined;
timeout?: number | undefined;
localAddress?: string | undefined;
localPort?: number | undefined; /**
* @param {{ port: number; host: any; }} options
* @param {(arg0: any) => void} callback
* @returns {TcpServer}
*/
localPort?: number | undefined;
interface?: "wifi" | "cellular" | "ethernet" | undefined;
reuseAddress?: boolean | undefined;
tls?: boolean | undefined;
tlsCheckValidity?: boolean | undefined;
tlsCert?: any;
}, callback?: ((address: string) => void) | undefined): TcpServer;
setTimeout(msecs: number, callback?: ((...args: any[]) => void) | undefined): TcpServer;
addListener(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
on(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
once(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
removeListener(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
off(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
removeAllListeners(event?: string | symbol | undefined): TcpServer;
setMaxListeners(n: number): TcpServer;
prependListener(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): TcpServer;
}
import TcpSocket from "./TcpSocket";
72 changes: 23 additions & 49 deletions lib/types/TcpSocket.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,42 +12,31 @@
* tlsCert?: any,
* }} ConnectionOptions
*/
export default class TcpSocket {
export default class TcpSocket extends EventEmitter {
/**
* Initialices a TcpSocket.
*
* @param {number} id
* @param {import('react-native').NativeEventEmitter} eventEmitter
* @param {string} [address]
*/
constructor(id: number, eventEmitter: import("react-native").NativeEventEmitter);
constructor(id: number, eventEmitter: import("react-native").NativeEventEmitter, address?: string | undefined);
_id: number;
_eventEmitter: import("react-native").NativeEventEmitter;
/** @type {number} */
_state: number;
/** @type {RemovableListener[]} */
_listeners: RemovableListener[];
/**
* Adds a listener to be invoked when events of the specified type are emitted by the `TcpSocket`.
* An optional calling `context` may be provided.
* The data arguments emitted will be passed to the listener callback.
*
* @param {string} event Name of the event to listen to
* @param {(arg0: any) => void} callback Function to invoke when the specified event is emitted
* @param {any} [context] Optional context object to use when invoking the listener
* @returns {RemovableListener}
*/
on(event: string, callback: (arg0: any) => void, context?: any): RemovableListener;
/**
* @private
* @param {string} event
* @param {function(any):void} callback
* @param {any} [context]
* @protected
*/
private _selectListener;
protected _registerEvents(): void;
_dataListener: import("react-native").EmitterSubscription | undefined;
_errorListener: import("react-native").EmitterSubscription | undefined;
_closeListener: import("react-native").EmitterSubscription | undefined;
_connectListener: import("react-native").EmitterSubscription | undefined;
/**
* @deprecated
* @protected
*/
off(): void;
protected _unregisterEvents(): void;
/**
* @param {ConnectionOptions} options
* @param {(address: string) => void} [callback]
Expand Down Expand Up @@ -103,14 +92,6 @@ export default class TcpSocket {
*/
end(data: string | Buffer | Uint8Array, encoding?: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex" | undefined): void;
destroy(): void;
/**
* @protected
*/
protected _registerEvents(): void;
/**
* @private
*/
private _unregisterEvents;
/**
* @private
* @param {string} address
Expand All @@ -134,10 +115,6 @@ export default class TcpSocket {
* @param {(error: string | null) => void} [callback]
*/
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;
/**
* @param {string} address
*/
setAsAlreadyConnected(address: string): void;
/**
* @private
* @param {string | Buffer | Uint8Array} buffer
Expand All @@ -148,12 +125,21 @@ export default class TcpSocket {
* @private
* @param {string} address
*/
private setConnected;
private _setConnected;
_address: string | undefined;
/**
* @private
*/
private setDisconnected;
private _setDisconnected;
addListener(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
on(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
once(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
removeListener(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
off(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
removeAllListeners(event?: string | symbol | undefined): TcpSocket;
setMaxListeners(n: number): TcpSocket;
prependListener(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): TcpSocket;
}
export type ConnectionOptions = {
port: number;
Expand All @@ -167,16 +153,4 @@ export type ConnectionOptions = {
tlsCheckValidity?: boolean | undefined;
tlsCert?: any;
};
declare class RemovableListener {
/**
* @param {import("react-native").EmitterSubscription} listener
* @param {import("react-native").NativeEventEmitter} eventEmitter
*/
constructor(listener: import("react-native").EmitterSubscription, eventEmitter: import("react-native").NativeEventEmitter);
_listener: import("react-native").EmitterSubscription;
_eventEmitter: import("react-native").NativeEventEmitter;
_removed: boolean;
isRemoved(): boolean;
remove(): void;
}
export {};
import { EventEmitter } from "node/events";
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-tcp-socket",
"title": "React Native Tcp Socket",
"version": "3.7.1",
"version": "4.0.0",
"description": "React Native TCP socket API for Android & iOS with SSL/TLS support",
"main": "src/index.js",
"types": "lib/types/index.d.ts",
Expand Down

0 comments on commit 560c7f4

Please sign in to comment.