MCPcopy Create free account
hub / github.com/AutoCodeStack/ios-device-farm / connect

Method connect

src/modules/wda-stream/wda.stream.ts:14–41  ·  view source on GitHub ↗
(connectPort: number)

Source from the content-addressed store, hash-verified

12 }
13
14 async connect(connectPort: number): Promise<void> {
15 if (this.client) {
16 this.client.destroy(); // Clean up any existing connection
17 }
18
19 this.client = new net.Socket();
20 try {
21 // Await the connection
22 await new Promise<void>((resolve, reject) => {
23 this.client?.connect({ port: connectPort }, resolve);
24 this.client?.on("error", reject);
25 });
26
27 // Send initial message or perform initial action
28 this.client.write("hello");
29
30 // Listen for data and emit events
31 this.client.pipe(this.consumer).on("data", (data: Buffer) => {
32 this.emit("data", data); // Emit data for async processing
33 });
34
35 logger.info("Connected successfully");
36 } catch (err) {
37 console.error("Connection error:", (err as Error).message);
38 this.client?.destroy();
39 throw err;
40 }
41 }
42
43 async waitForFirstData(): Promise<Buffer> {
44 if (!this.client) {

Callers 1

startMethod · 0.80

Calls 1

destroyMethod · 0.45

Tested by

no test coverage detected