-
-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathios-log-parser-service.ts
53 lines (44 loc) · 2.06 KB
/
ios-log-parser-service.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { DEBUGGER_PORT_FOUND_EVENT_NAME, DEVICE_LOG_EVENT_NAME } from "../common/constants";
import { EventEmitter } from "events";
export class IOSLogParserService extends EventEmitter implements IIOSLogParserService {
private static MESSAGE_REGEX = /NativeScript debugger has opened inspector socket on port (\d+?) for (.*)[.]/;
private startedDeviceLogInstances: IDictionary<boolean> = {};
constructor(private $deviceLogProvider: Mobile.IDeviceLogProvider,
private $iosDeviceOperations: IIOSDeviceOperations,
private $iOSSimulatorLogProvider: Mobile.IiOSSimulatorLogProvider,
private $logger: ILogger,
private $projectData: IProjectData) {
super();
}
public startParsingLog(device: Mobile.IDevice): void {
this.$deviceLogProvider.setProjectNameForDevice(device.deviceInfo.identifier, this.$projectData.projectName);
if (!this.startedDeviceLogInstances[device.deviceInfo.identifier]) {
this.startParsingLogCore(device);
this.startLogProcess(device);
this.startedDeviceLogInstances[device.deviceInfo.identifier] = true;
}
}
private startParsingLogCore(device: Mobile.IDevice): void {
const logProvider = device.isEmulator ? this.$iOSSimulatorLogProvider : this.$iosDeviceOperations;
logProvider.on(DEVICE_LOG_EVENT_NAME, (response: IOSDeviceLib.IDeviceLogData) => this.processDeviceLogResponse(response));
}
private processDeviceLogResponse(response: IOSDeviceLib.IDeviceLogData) {
const matches = IOSLogParserService.MESSAGE_REGEX.exec(response.message);
if (matches) {
const data = {
port: parseInt(matches[1]),
appId: matches[2],
deviceId: response.deviceId
};
this.$logger.trace(`Emitting ${DEBUGGER_PORT_FOUND_EVENT_NAME} event`, data);
this.emit(DEBUGGER_PORT_FOUND_EVENT_NAME, data);
}
}
private startLogProcess(device: Mobile.IDevice): void {
if (device.isEmulator) {
return this.$iOSSimulatorLogProvider.startNewMutedLogProcess(device.deviceInfo.identifier);
}
return this.$iosDeviceOperations.startDeviceLog(device.deviceInfo.identifier);
}
}
$injector.register("iOSLogParserService", IOSLogParserService);