This repository was archived by the owner on Feb 2, 2021. It is now read-only.
File tree 2 files changed +25
-1
lines changed
2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { Socket } from "net" ;
2
+
3
+ export class IOSDeviceSocket extends Socket {
4
+ private deviceIdentifier : string ;
5
+ private fd : string ;
6
+ private iosDeviceOperations : IIOSDeviceOperations ;
7
+
8
+ public initialize ( fd : string , deviceIdentifier : string , iosDeviceOperatios : IIOSDeviceOperations ) : void {
9
+ this . fd = fd ;
10
+ this . deviceIdentifier = deviceIdentifier ;
11
+ this . iosDeviceOperations = iosDeviceOperatios ;
12
+ }
13
+
14
+ public async write ( message : string ) : Promise < number > {
15
+ const response = await this . iosDeviceOperations . sendMessageToSocket ( [ { socket : + this . fd , message : message , deviceId : this . deviceIdentifier } ] ) ;
16
+
17
+ return + _ . first ( response [ this . deviceIdentifier ] ) . response ;
18
+ }
19
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as applicationManagerPath from "./ios-application-manager";
2
2
import * as fileSystemPath from "./ios-device-file-system" ;
3
3
import * as constants from "../../../constants" ;
4
4
import * as net from "net" ;
5
+ import { IOSDeviceSocket } from "./ios-device-socket" ;
5
6
6
7
export class IOSDevice implements Mobile . IiOSDevice {
7
8
public applicationManager : Mobile . IDeviceApplicationManager ;
@@ -60,7 +61,11 @@ export class IOSDevice implements Mobile.IiOSDevice {
60
61
const deviceId = this . deviceInfo . identifier ;
61
62
const deviceResponse = ( await this . $iosDeviceOperations . connectToPort ( [ { deviceId : deviceId , port : port } ] ) ) [ deviceId ] ;
62
63
63
- this . _socket = new net . Socket ( { fd : deviceResponse [ 0 ] . response } ) ;
64
+ // HACK to override the write method of net.Socket
65
+ const fd = deviceResponse [ 0 ] . response ;
66
+ const socket = new IOSDeviceSocket ( { fd : fd } ) ;
67
+ socket . initialize ( fd , deviceId , this . $iosDeviceOperations ) ;
68
+ this . _socket = < any > socket ;
64
69
65
70
this . $processService . attachToProcessExitSignals ( this , this . destroySocket ) ;
66
71
return this . _socket ;
You can’t perform that action at this time.
0 commit comments