Skip to content

Commit cd77446

Browse files
Merge pull request #3788 from NativeScript/vladimirov/fix-public-api
chore: rename exposed methods and events for emulators
2 parents 5f1e276 + 9ec4ad9 commit cd77446

File tree

2 files changed

+108
-7
lines changed

2 files changed

+108
-7
lines changed

PublicAPI.md

+107-6
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ const tns = require("nativescript");
5353
* [sysInfo](#sysinfo)
5454
* [getSupportedNodeVersionRange](#getsupportednodeversionrange)
5555
* [getSystemWarnings](#getsystemwarnings)
56-
* [devicesService](#devicesService)
57-
* [getAvailableEmulators](#getAvailableEmulators)
58-
* [startEmulator](#startEmulator)
56+
* [devicesService](#devicesservice)
57+
* [getEmulatorImages](#getemulatorimages)
58+
* [startEmulator](#startemulator)
59+
* [deviceEmitter](#deviceemitter)
60+
* [events](#deviceemitterevents)
5961

6062
## Module projectService
6163

@@ -1204,8 +1206,8 @@ tns.sysInfo.getSystemWarnings()
12041206
## devicesService
12051207
The `devicesService` module allows interaction with devices and emulators. You can get a list of the available emulators or start a specific emulator.
12061208
1207-
### getAvailableEmulators
1208-
The `getAvailableEmulators` method returns object of all running and available emulators. The result is in the following format:
1209+
### getEmulators
1210+
The `getEmulators` method returns object of all running and available emulators. The result is in the following format:
12091211
```JavaScript
12101212
{
12111213
android: {
@@ -1223,7 +1225,7 @@ This method accepts platform parameter. If provided only devices by specified pl
12231225
12241226
* Usage
12251227
```TypeScript
1226-
tns.devicesService.getAvailableEmulators()
1228+
tns.devicesService.getEmulators()
12271229
.then(availableEmulatorsOutput => {
12281230
Object.keys(availableEmulatorsOutput)
12291231
.forEach(platform => {
@@ -1240,6 +1242,105 @@ tns.devicesService.startEmulator({imageIdentifier: "my emulator imageIdentifier"
12401242
.then(errors => { });
12411243
```
12421244
1245+
## deviceEmitter
1246+
This module is used to emit information for devices, applications on them, etc.
1247+
1248+
### deviceEmitterEvents
1249+
`deviceEmitter` emits the following events:
1250+
`deviceEmitter` module is used to emit different events related to devices attached to the system.
1251+
You can use `deviceEmitter` to add handles for the following events:
1252+
1253+
* `deviceFound` - Raised when a new device is attached to the system. The callback function will receive one argument - `deviceInfoData`.
1254+
Sample usage:
1255+
```JavaScript
1256+
tns.deviceEmitter.on("deviceFound", (deviceInfoData) => {
1257+
console.log("Found device with identifier: " + deviceInfoData.identifier);
1258+
});
1259+
```
1260+
1261+
* `deviceLost` - Raised when a device is detached from the system. The callback function will receive one argument - `deviceInfoData`.
1262+
Sample usage:
1263+
```JavaScript
1264+
tns.deviceEmitter.on("deviceLost", (deviceInfoData) => {
1265+
console.log("Detached device with identifier: " + deviceInfoData.identifier);
1266+
});
1267+
```
1268+
1269+
* `deviceLogData` - Raised when attached device reports any information. This is the output of `adb logcat` for Android devices. For iOS this is the `iOS SysLog`.
1270+
The event is raised for any device that reports data. The callback function has two arguments - `deviceIdentifier` and `reportedData`. <br/><br/>
1271+
Sample usage:
1272+
```JavaScript
1273+
tns.deviceEmitter.on("deviceLogData", (identifier, reportedData) => {
1274+
console.log("Device " + identifier + " reports: " + reportedData);
1275+
});
1276+
```
1277+
1278+
* `applicationInstalled` - Raised when application is installed on a device. The callback has two arguments - `deviceIdentifier` and `applicationIdentifier`. <br/><br/>
1279+
Sample usage:
1280+
```JavaScript
1281+
tns.deviceEmitter.on("applicationInstalled", (identifier, applicationIdentifier) => {
1282+
console.log("Application " + applicationIdentifier + " has been installed on device with id: " + identifier);
1283+
});
1284+
```
1285+
1286+
* `applicationUninstalled` - Raised when application is removed from device. The callback has two arguments - `deviceIdentifier` and `applicationIdentifier`. <br/><br/>
1287+
Sample usage:
1288+
```JavaScript
1289+
tns.deviceEmitter.on("applicationUninstalled", (identifier, applicationIdentifier) => {
1290+
console.log("Application " + applicationIdentifier + " has been uninstalled from device with id: " + identifier);
1291+
});
1292+
```
1293+
1294+
* `debuggableAppFound` - Raised when application on a device becomes available for debugging. The callback has one argument - `applicationInfo`. <br/><br/>
1295+
Sample usage:
1296+
```JavaScript
1297+
tns.deviceEmitter.on("debuggableAppFound", (applicationInfo) => {
1298+
console.log("Application " + applicationInfo.appIdentifier + " is available for debugging on device with id: " + applicationInfo.deviceIdentifier);
1299+
});
1300+
```
1301+
Sample result for `applicationInfo` will be:
1302+
```JSON
1303+
{
1304+
"deviceIdentifier": "4df18f307d8a8f1b",
1305+
"appIdentifier": "com.telerik.Fitness",
1306+
"framework": "NativeScript",
1307+
"title": "NativeScript Application"
1308+
}
1309+
```
1310+
1311+
* `debuggableAppLost` - Raised when application on a device is not available for debugging anymore. The callback has one argument - `applicationInfo`. <br/><br/>
1312+
Sample usage:
1313+
```JavaScript
1314+
tns.deviceEmitter.on("debuggableAppLost", (applicationInfo) => {
1315+
console.log("Application " + applicationInfo.appIdentifier + " is not available for debugging anymore on device with id: " + applicationInfo.deviceIdentifier);
1316+
});
1317+
```
1318+
Sample result for `applicationInfo` will be:
1319+
```JSON
1320+
{
1321+
"deviceIdentifier": "4df18f307d8a8f1b",
1322+
"appIdentifier": "com.telerik.Fitness",
1323+
"framework": "NativeScript",
1324+
"title": "NativeScript Application"
1325+
}
1326+
```
1327+
1328+
* `emulatorImageFound` - Raised when a new Android Emulator Image or iOS Simulator is created/installed on the system. The callback has a single argument that describes the new image:
1329+
```JavaScript
1330+
tns.deviceEmitter.on("emulatorImageFound", (emulatorImageInfo) => {
1331+
console.log("Added new emulator image", emulatorImageInfo);
1332+
});
1333+
```
1334+
`emulatorImageInfo` is of type [Moble.IDeviceInfo](https://github.com/telerik/mobile-cli-lib/blob/61cdaaaf7533394afbbe84dd4eee355072ade2de/definitions/mobile.d.ts#L9-L86).
1335+
1336+
* `emulatorImageLost` - Raised when an Android Emulator Image or iOS Simulator is removed from the system. The callback has a single argument that describes the removed image:
1337+
```JavaScript
1338+
tns.deviceEmitter.on("emulatorImageLost", (emulatorImageInfo) => {
1339+
console.log("Removed emulator image", emulatorImageInfo);
1340+
});
1341+
```
1342+
`emulatorImageInfo` is of type [Moble.IDeviceInfo](https://github.com/telerik/mobile-cli-lib/blob/61cdaaaf7533394afbbe84dd4eee355072ade2de/definitions/mobile.d.ts#L9-L86).
1343+
12431344
## How to add a new method to Public API
12441345
CLI is designed as command line tool and when it is used as a library, it does not give you access to all of the methods. This is mainly implementation detail. Most of the CLI's code is created to work in command line, not as a library, so before adding method to public API, most probably it will require some modification.
12451346
For example the `$options` injected module contains information about all `--` options passed on the terminal. When the CLI is used as a library, the options are not populated. Before adding method to public API, make sure its implementation does not rely on `$options`.

0 commit comments

Comments
 (0)