Skip to content

Commit

Permalink
Allow strings for deviceId & port arguments, not just numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 14, 2024
1 parent cc9953e commit 1898d26
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ export class UsbmuxClient {

readonly openTunnels: Array<net.Socket> = [];

async createDeviceTunnel(deviceId: number, port: number): Promise<net.Socket> {
async createDeviceTunnel(deviceId: string | number, port: string | number): Promise<net.Socket> {
const conn = await connectSocket(this.connectionOptions);

this.openTunnels.push(conn);
Expand All @@ -271,7 +271,7 @@ export class UsbmuxClient {
this.openTunnels.splice(index, 1);
});

conn.write(requestTunnelMessage(deviceId, port));
conn.write(requestTunnelMessage(Number(deviceId), Number(port)));
const response = await readPlistMessageFromStream(conn);

if (
Expand All @@ -286,7 +286,7 @@ export class UsbmuxClient {
return conn;
}

private async getLockdownTunnel(deviceId: number) {
private async getLockdownTunnel(deviceId: string | number) {
const tunnel = await this.createDeviceTunnel(deviceId, 62078);
tunnel.write(lockdowndMessage({ Label: 'usbmux-client', Request: 'QueryType' }));

Expand All @@ -296,15 +296,15 @@ export class UsbmuxClient {
return tunnel;
}

async queryDeviceValue<K extends LockdownKey>(deviceId: number, key: K) {
async queryDeviceValue<K extends LockdownKey>(deviceId: string | number, key: K) {
const tunnel = await this.getLockdownTunnel(deviceId);
tunnel.write(lockdowndMessage({ Label: 'usbmux-client', Request: 'GetValue', Key: key }));
const message = await readMessageFromLockdowndStream(tunnel) as GetValueResult<K>
tunnel.end();
return message.Value;
}

async queryAllDeviceValues(deviceId: number) {
async queryAllDeviceValues(deviceId: string | number) {
const tunnel = await this.getLockdownTunnel(deviceId);
tunnel.write(lockdowndMessage({ Label: 'usbmux-client', Request: 'GetValue' }));
const message = await readMessageFromLockdowndStream(tunnel) as GetValuesResult
Expand Down

0 comments on commit 1898d26

Please sign in to comment.