Skip to content

Commit 570ebbb

Browse files
Emit deviceIdentifier in debuggerAttached event (#3104)
`debuggerAttached` event should emit full information required for debugging. However, the deviceIdentifier is missing, so add it. Update PublicAPI.md according to latest changes.
1 parent e0b05f4 commit 570ebbb

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

PublicAPI.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const tns = require("nativescript");
3030
* [liveSyncService](#livesyncservice)
3131
* [liveSync](#livesync)
3232
* [stopLiveSync](#stopLiveSync)
33+
* [enableDebugging](#enableDebugging)
34+
* [attachDebugger](#attachDebugger)
35+
* [disableDebugging](#disableDebugging)
36+
* [getLiveSyncDeviceDescriptors](#getLiveSyncDeviceDescriptors)
3337
* [events](#events)
3438

3539

@@ -454,9 +458,9 @@ The returned Promise will be rejected in case any error occurs. It will also be
454458
* Starts debug operation based on the specified debug data.
455459
* @param {IDebugData} debugData Describes information for device and application that will be debugged.
456460
* @param {IDebugOptions} debugOptions Describe possible options to modify the behaivor of the debug operation, for example stop on the first line.
457-
* @returns {Promise<string>} URL that should be opened in Chrome DevTools.
461+
* @returns {Promise<IDebugInformation>} Device Identifier, full url and port where the frontend client can be connected.
458462
*/
459-
debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string>;
463+
debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugInformation>;
460464
```
461465
462466
The type of arguments that you can pass are described below:
@@ -515,6 +519,16 @@ interface IDebugOptions {
515519
* Default value is 02e6bde1bbe34e43b309d4ef774b1168d25fd024 which corresponds to 55.0.2883 Chrome version
516520
*/
517521
devToolsCommit?: string;
522+
523+
/**
524+
* Defines if Chrome DevTools should be used for debugging.
525+
*/
526+
chrome?: boolean;
527+
528+
/**
529+
* Defines if thе application is already started on device.
530+
*/
531+
start?: boolean;
518532
}
519533
```
520534
@@ -536,7 +550,7 @@ const debugOptions = {
536550
};
537551

538552
tns.debugService.debug(debugData, debugOptions)
539-
.then(url => console.log(`Open the following url in Chrome DevTools: ${url}`))
553+
.then(debugInfo => console.log(`Open the following url in Chrome DevTools: ${debugInfo.url}, port is: ${debugInfo.port} and deviceIdentifier is: ${debugInfo.deviceIdentifier}`))
540554
.catch(err => console.log(`Unable to start debug operation, reason: ${err.message}.`));
541555
```
542556
@@ -839,12 +853,12 @@ tns.liveSyncService.on("userInteractionNeeded", data => {
839853
});
840854
```
841855
842-
* debuggerAttached - raised whenever CLI attaches the backend debugging socket and a frontend debugging client may be attached. The event is raised with an object containing the device's identifier:
856+
* debuggerAttached - raised whenever CLI attaches the backend debugging socket and a frontend debugging client may be attached. The event is raised with an object containing the device's identifier, url for debugging and port
843857
844858
Example:
845859
```JavaScript
846860
tns.liveSyncService.on("debuggerAttached", debugInfo => {
847-
console.log(`Backend client connected, frontend client may be connected at ${debugInfo.url}`);
861+
console.log(`Backend client connected, frontend client may be connected at ${debugInfo.url} to debug app on device ${debugInfo.deviceIdentifier}. Port is: ${debugInfo.port}`);
848862
});
849863
```
850864

lib/declarations.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ interface ICreateProjectOptions extends INpmInstallConfigurationOptionsBase {
372372
pathToTemplate?: string;
373373
}
374374

375-
interface IDebugInformation extends IPort {
375+
interface IDebugInformation extends IPort, Mobile.IDeviceIdentifier {
376376
url: string;
377377
}
378378

lib/definitions/debug.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ interface IDebugServiceBase extends NodeJS.EventEmitter {
105105
* Starts debug operation based on the specified debug data.
106106
* @param {IDebugData} debugData Describes information for device and application that will be debugged.
107107
* @param {IDebugOptions} debugOptions Describe possible options to modify the behaivor of the debug operation, for example stop on the first line.
108-
* @returns {Promise<IDebugInformation>} Full url and port where the frontend client can be connected.
108+
* @returns {Promise<IDebugInformation>} Device Identifier, full url and port where the frontend client can be connected.
109109
*/
110110
debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<IDebugInformation>;
111111
}

lib/services/debug-service.ts

+6-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ export class DebugService extends EventEmitter implements IDebugService {
5858
result = await debugService.debug(debugData, debugOptions);
5959
}
6060

61-
return this.getDebugInformation(result);
61+
return this.getDebugInformation(result, device.deviceInfo.identifier);
6262
}
6363

6464
public debugStop(deviceIdentifier: string): Promise<void> {
@@ -94,20 +94,18 @@ export class DebugService extends EventEmitter implements IDebugService {
9494
platformDebugService.on(CONNECTION_ERROR_EVENT_NAME, connectionErrorHandler);
9595
}
9696

97-
private getDebugInformation(fullUrl: string): IDebugInformation {
98-
let debugInfo: IDebugInformation = {
97+
private getDebugInformation(fullUrl: string, deviceIdentifier: string): IDebugInformation {
98+
const debugInfo: IDebugInformation = {
9999
url: fullUrl,
100-
port: 0
100+
port: 0,
101+
deviceIdentifier
101102
};
102103

103104
if (fullUrl) {
104105
const parseQueryString = true;
105106
const wsQueryParam = parse(fullUrl, parseQueryString).query.ws;
106107
const hostPortSplit = wsQueryParam && wsQueryParam.split(":");
107-
debugInfo = {
108-
url: fullUrl,
109-
port: hostPortSplit && +hostPortSplit[1]
110-
};
108+
debugInfo.port = hostPortSplit && +hostPortSplit[1];
111109
}
112110

113111
return debugInfo;

test/services/debug-service.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { CONNECTION_ERROR_EVENT_NAME, DebugCommandErrors } from "../../lib/const
88

99
const fakeChromeDebugPort = 123;
1010
const fakeChromeDebugUrl = `fakeChromeDebugUrl?experiments=true&ws=localhost:${fakeChromeDebugPort}`;
11+
const defaultDeviceIdentifier = "Nexus5";
12+
1113
class PlatformDebugService extends EventEmitter /* implements IPlatformDebugService */ {
1214
public async debug(debugData: IDebugData, debugOptions: IDebugOptions): Promise<string> {
1315
return fakeChromeDebugUrl;
@@ -18,6 +20,7 @@ interface IDebugTestDeviceInfo {
1820
deviceInfo: {
1921
status: string;
2022
platform: string;
23+
identifier: string;
2124
};
2225

2326
isEmulator: boolean;
@@ -36,7 +39,8 @@ interface IDebugTestData {
3639
const getDefaultDeviceInformation = (platform?: string): IDebugTestDeviceInfo => ({
3740
deviceInfo: {
3841
status: constants.CONNECTED_STATUS,
39-
platform: platform || "Android"
42+
platform: platform || "Android",
43+
identifier: defaultDeviceIdentifier
4044
},
4145

4246
isEmulator: false
@@ -95,7 +99,7 @@ describe("debugService", () => {
9599
describe("debug", () => {
96100
const getDebugData = (deviceIdentifier?: string): IDebugData => ({
97101
applicationIdentifier: "org.nativescript.app1",
98-
deviceIdentifier: deviceIdentifier || "Nexus5",
102+
deviceIdentifier: deviceIdentifier || defaultDeviceIdentifier,
99103
projectDir: "/Users/user/app1",
100104
projectName: "app1"
101105
});
@@ -217,7 +221,8 @@ describe("debugService", () => {
217221

218222
assert.deepEqual(debugInfo, {
219223
url: fakeChromeDebugUrl,
220-
port: fakeChromeDebugPort
224+
port: fakeChromeDebugPort,
225+
deviceIdentifier: debugData.deviceIdentifier
221226
});
222227
});
223228
});

0 commit comments

Comments
 (0)