Skip to content

Commit

Permalink
Provide detailed device info types for getDevices()
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Jun 13, 2024
1 parent 90d63b9 commit 32a96d8
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function requestTunnelMessage(deviceId: number, port: number) {
}

type ResultMessage = { MessageType: 'Result', Number: number };
type AttachedMessage = { MessageType: 'Attached', DeviceID: number, Properties: Record<string, string | number> };
type AttachedMessage = { MessageType: 'Attached', DeviceID: number, Properties: DeviceInfo };
type DetachedMessage = { MessageType: 'Detached', DeviceID: number };

type ResponseMessage =
Expand Down Expand Up @@ -154,6 +154,16 @@ const connectSocket = async (options: net.NetConnectOpts) => {
return conn;
}

// Most properties optional because we're not sure what's actually guaranteed:
export interface DeviceInfo {
DeviceID: number;
ConnectionSpeed?: number;
ConnectionType?: string;
LocationID?: number;
ProductID?: number;
SerialNumber?: string;
}

export class UsbmuxClient {

constructor(
Expand Down Expand Up @@ -209,7 +219,7 @@ export class UsbmuxClient {
}
}

private deviceData: Record<string, Record<string, string | number>> = {};
private deviceData: Record<string, DeviceInfo> = {};

// Listen for events by using readMessageFromStream in an async iterator:
async listenToMessages(socket: net.Socket) {
Expand All @@ -229,7 +239,7 @@ export class UsbmuxClient {
}
}

async getDevices() {
async getDevices(): Promise<Record<string, DeviceInfo>> {
await this.startListeningForDevices();
return this.deviceData;
}
Expand Down

0 comments on commit 32a96d8

Please sign in to comment.