diff --git a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts index 10cebd65ea..5f015aca8d 100644 --- a/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts +++ b/lib/device-sockets/ios/app-debug-socket-proxy-factory.ts @@ -1,9 +1,9 @@ import { EventEmitter } from "events"; import { CONNECTION_ERROR_EVENT_NAME } from "../../constants"; -import { PacketStream } from "./packet-stream"; import * as net from "net"; import * as ws from "ws"; import temp = require("temp"); +import { MessageUnpackStream } from "ios-device-lib"; export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebugSocketProxyFactory { private deviceWebServers: IDictionary = {}; @@ -134,11 +134,16 @@ export class AppDebugSocketProxyFactory extends EventEmitter implements IAppDebu const encoding = "utf16le"; const appDebugSocket: net.Socket = (req)["__deviceSocket"]; - const packets = new PacketStream(); + const packets = new MessageUnpackStream(); appDebugSocket.pipe(packets); packets.on("data", (buffer: Buffer) => { - webSocket.send(buffer.toString(encoding)); + const message = buffer.toString(encoding); + if (webSocket.readyState === webSocket.OPEN) { + webSocket.send(message); + } else { + this.$logger.trace(`Received message ${message}, but unable to send it to webSocket as its state is: ${webSocket.readyState}`); + } }); webSocket.on("error", err => { diff --git a/lib/device-sockets/ios/packet-stream.ts b/lib/device-sockets/ios/packet-stream.ts deleted file mode 100644 index 220d525dd5..0000000000 --- a/lib/device-sockets/ios/packet-stream.ts +++ /dev/null @@ -1,33 +0,0 @@ -import * as stream from "stream"; - -export class PacketStream extends stream.Transform { - private buffer: Buffer; - private offset: number; - - constructor(opts?: stream.TransformOptions) { - super(opts); - } - - public _transform(packet: any, encoding: string, done: Function): void { - while (packet.length > 0) { - if (!this.buffer) { - // read length - const length = packet.readInt32BE(0); - this.buffer = Buffer.allocUnsafe(length); - this.offset = 0; - packet = packet.slice(4); - } - - packet.copy(this.buffer, this.offset); - const copied = Math.min(this.buffer.length - this.offset, packet.length); - this.offset += copied; - packet = packet.slice(copied); - - if (this.offset === this.buffer.length) { - this.push(this.buffer); - this.buffer = undefined; - } - } - done(); - } -} diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index fd6b5c244f..d62842ad09 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -3893,9 +3893,9 @@ "integrity": "sha1-EEqOSqym09jNFXqO+L+rLXo//bY=" }, "ios-device-lib": { - "version": "0.4.15", - "resolved": "https://registry.npmjs.org/ios-device-lib/-/ios-device-lib-0.4.15.tgz", - "integrity": "sha512-OzyKbLxrmpTB87hPelpAsvtmPYeucSP53IaLb2QHaIDW6ZqHjJV4XCHMpwtLGvLOcMNb2WVUHxoirQ+rwC21dQ==", + "version": "0.5.0", + "resolved": "https://registry.npmjs.org/ios-device-lib/-/ios-device-lib-0.5.0.tgz", + "integrity": "sha512-EKSXHYvOhjB+R/8EaWX9Iha7AIk1U26rxvxq7Hpg/19zOXqsnjuakyJ3fDKh5BXnU7CzBpkz1V2lwi8JPvD5fw==", "requires": { "bufferpack": "0.0.6", "node-uuid": "1.4.7" diff --git a/package.json b/package.json index b3c6e2f907..af05dac8f2 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,7 @@ "gaze": "1.1.0", "iconv-lite": "0.4.11", "inquirer": "6.2.0", - "ios-device-lib": "0.4.15", + "ios-device-lib": "0.5.0", "ios-mobileprovision-finder": "1.0.10", "ios-sim-portable": "4.0.6", "istextorbinary": "2.2.1",