Skip to content

Commit

Permalink
chore: Improve typing on RpcClient (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 26, 2024
1 parent 93c9d69 commit 3a15572
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 25 deletions.
6 changes: 1 addition & 5 deletions lib/remote-debugger-real-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ export default class RemoteDebuggerRealDevice extends RemoteDebugger {
bundleId: this.bundleId,
platformVersion: this.platformVersion,
isSafari: this.isSafari,
host: this.host,
port: this.port,
socketPath: this.socketPath,
messageProxy: this.remoteDebugProxy,
logAllCommunication: this.logAllCommunication,
logAllCommunicationHexDump: this.logAllCommunicationHexDump,
socketChunkSize: this.socketChunkSize,
webInspectorMaxFrameLength: this.webInspectorMaxFrameLength,
udid: this.udid
udid: this.udid,
});
}
}
3 changes: 1 addition & 2 deletions lib/rpc/remote-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const COMMANDS = {
'Timeline.stop': FULL_COMMAND,
};

class RemoteMessages {
export class RemoteMessages {
constructor (isTargetBased = false) {
this.isTargetBased = isTargetBased;
}
Expand Down Expand Up @@ -249,5 +249,4 @@ class RemoteMessages {
}
}

export { RemoteMessages };
export default RemoteMessages;
19 changes: 18 additions & 1 deletion lib/rpc/rpc-client-real-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,19 @@ import RpcClient from './rpc-client';
import { services } from 'appium-ios-device';


export default class RpcClientRealDevice extends RpcClient {
export class RpcClientRealDevice extends RpcClient {
/**
* @param {import('./rpc-client').RpcClientOptions} [opts={}]
*/
constructor (opts = {}) {
super(Object.assign({
shouldCheckForTarget: false,
}, opts));
}

/**
* @override
*/
async connect () {
this.service = await services.startWebInspectorService(this.udid, {
osVersion: this.platformVersion,
Expand All @@ -24,6 +30,9 @@ export default class RpcClientRealDevice extends RpcClient {
this.isConnected = true;
}

/**
* @override
*/
async disconnect () {
if (!this.isConnected) {
return;
Expand All @@ -35,10 +44,16 @@ export default class RpcClientRealDevice extends RpcClient {
this.isConnected = false;
}

/**
* @override
*/
async sendMessage (cmd) { // eslint-disable-line require-await
this.service.sendMessage(cmd);
}

/**
* @override
*/
async receive (data) {
if (!this.isConnected) {
return;
Expand All @@ -47,3 +62,5 @@ export default class RpcClientRealDevice extends RpcClient {
await this.messageHandler.handleMessage(data);
}
}

export default RpcClientRealDevice;
43 changes: 41 additions & 2 deletions lib/rpc/rpc-client-simulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,25 @@ import net from 'net';
import RpcClient from './rpc-client';
import { services } from 'appium-ios-device';

export class RpcClientSimulator extends RpcClient {
/** @type {string|undefined} */
host;

export default class RpcClientSimulator extends RpcClient {
/** @type {number|undefined} */
port;

/** @type {any} */
messageProxy;

/** @type {import('node:net').Socket|null} */
socket;

/** @type {string|undefined} */
socketPath;

/**
* @param {import('./rpc-client').RpcClientOptions & RpcClientSimulatorOptions} [opts={}]
*/
constructor (opts = {}) {
super(Object.assign({
shouldCheckForTarget: false,
Expand All @@ -28,6 +45,9 @@ export default class RpcClientSimulator extends RpcClient {
this.socketPath = socketPath;
}

/**
* @override
*/
async connect () {
// create socket and handle its messages
if (this.socketPath) {
Expand Down Expand Up @@ -59,7 +79,7 @@ export default class RpcClientSimulator extends RpcClient {
// tcp socket
log.debug(`Connecting to remote debugger ${this.messageProxy ? 'via proxy ' : ''}through TCP: ${this.host}:${this.port}`);
this.socket = new net.Socket();
this.socket.connect(this.port, this.host);
this.socket.connect(/** @type {number} */ (this.port), /** @type {String} */ (this.host));
}

this.socket.setNoDelay(true);
Expand Down Expand Up @@ -107,6 +127,9 @@ export default class RpcClientSimulator extends RpcClient {
});
}

/**
* @override
*/
async disconnect () {
if (!this.isConnected) {
return;
Expand All @@ -118,6 +141,9 @@ export default class RpcClientSimulator extends RpcClient {
this.isConnected = false;
}

/**
* @override
*/
async sendMessage (cmd) {
let onSocketError;

Expand Down Expand Up @@ -148,6 +174,9 @@ export default class RpcClientSimulator extends RpcClient {
});
}

/**
* @override
*/
async receive (data) {
if (!this.isConnected) {
return;
Expand All @@ -166,3 +195,13 @@ export default class RpcClientSimulator extends RpcClient {
await this.messageHandler.handleMessage(data);
}
}

export default RpcClientSimulator;

/**
* @typedef {Object} RpcClientSimulatorOptions
* @property {string} [socketPath]
* @property {string} [host='::1']
* @property {number} [port]
* @property {any} [messageProxy]
*/
Loading

0 comments on commit 3a15572

Please sign in to comment.