Skip to content

Commit 32a96d8

Browse files
committed
Provide detailed device info types for getDevices()
1 parent 90d63b9 commit 32a96d8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/index.ts

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function requestTunnelMessage(deviceId: number, port: number) {
4545
}
4646

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

5151
type ResponseMessage =
@@ -154,6 +154,16 @@ const connectSocket = async (options: net.NetConnectOpts) => {
154154
return conn;
155155
}
156156

157+
// Most properties optional because we're not sure what's actually guaranteed:
158+
export interface DeviceInfo {
159+
DeviceID: number;
160+
ConnectionSpeed?: number;
161+
ConnectionType?: string;
162+
LocationID?: number;
163+
ProductID?: number;
164+
SerialNumber?: string;
165+
}
166+
157167
export class UsbmuxClient {
158168

159169
constructor(
@@ -209,7 +219,7 @@ export class UsbmuxClient {
209219
}
210220
}
211221

212-
private deviceData: Record<string, Record<string, string | number>> = {};
222+
private deviceData: Record<string, DeviceInfo> = {};
213223

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

232-
async getDevices() {
242+
async getDevices(): Promise<Record<string, DeviceInfo>> {
233243
await this.startListeningForDevices();
234244
return this.deviceData;
235245
}

0 commit comments

Comments
 (0)