Skip to content

Commit 52d7a4f

Browse files
author
Fatme
authored
Merge pull request #4168 from NativeScript/fatme/public-api
Docs for the public api for preview
2 parents e068886 + 384df58 commit 52d7a4f

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

PublicAPI.md

+78
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ const tns = require("nativescript");
3636
* [debug](#debug)
3737
* [liveSyncService](#livesyncservice)
3838
* [liveSync](#livesync)
39+
* [liveSyncToPreviewApp](#livesynctopreviewapp)
3940
* [stopLiveSync](#stopLiveSync)
4041
* [enableDebugging](#enableDebugging)
4142
* [attachDebugger](#attachDebugger)
@@ -58,6 +59,12 @@ const tns = require("nativescript");
5859
* [startEmulator](#startemulator)
5960
* [deviceEmitter](#deviceemitter)
6061
* [events](#deviceemitterevents)
62+
* [previewDevicesService](#previewdevicesservice)
63+
* [deviceFound](#devicefound)
64+
* [deviceLost](#devicelost)
65+
* [deviceLog](#devicelog)
66+
* [previewQrCodeService](#previewqrcodeservice)
67+
* [getPlaygroundAppQrCode](#getplaygroundappqrcode)
6168

6269
## Module projectService
6370

@@ -768,6 +775,33 @@ tns.liveSyncService.liveSync([ androidDeviceDescriptor, iOSDeviceDescriptor ], l
768775
});
769776
```
770777
778+
### liveSyncToPreviewApp
779+
Starts a LiveSync operation to the Preview app. After scanning the QR code with the scanner provided in the NativeScript Playground app, the app will be launched on a device through the Preview app. Additionally, any changes made to the project will be automatically synchronized with the deployed app.
780+
781+
* Definition
782+
```TypeScript
783+
/**
784+
* Starts LiveSync operation by producting a QR code and starting watcher.
785+
* @param {IPreviewAppLiveSyncData} liveSyncData Describes the LiveSync operation - for which project directory is the operation and other settings.
786+
* @returns {Promise<IQrCodeImageData>}
787+
*/
788+
liveSyncToPreviewApp(liveSyncData: IPreviewAppLiveSyncData): Promise<IQrCodeImageData>;
789+
```
790+
791+
* Usage:
792+
```JavaScript
793+
const liveSyncData = {
794+
projectDir,
795+
bundle: false,
796+
useHotModuleReload: false,
797+
env: { }
798+
};
799+
tns.liveSyncService.liveSyncToPreviewApp(liveSyncData)
800+
.then(qrCodeImageData => {
801+
console.log("The qrCodeImageData is: " + qrCodeImageData);
802+
});
803+
```
804+
771805
### stopLiveSync
772806
Stops LiveSync operation. In case deviceIdentifires are passed, the operation will be stopped only for these devices.
773807
@@ -1341,6 +1375,50 @@ tns.deviceEmitter.on("emulatorImageLost", (emulatorImageInfo) => {
13411375
```
13421376
`emulatorImageInfo` is of type [Moble.IDeviceInfo](https://github.com/telerik/mobile-cli-lib/blob/61cdaaaf7533394afbbe84dd4eee355072ade2de/definitions/mobile.d.ts#L9-L86).
13431377
1378+
## previewDevicesService
1379+
The `previewDevicesService` module allows interaction with preview devices. You can get a list of the connected preview devices and logs from specified device.
1380+
1381+
### previewDevicesEmitterEvents
1382+
1383+
* `deviceFound` - Raised when the QR code is scanned with any device. The callback function will receive one argument - `device`.
1384+
Sample usage:
1385+
```JavaScript
1386+
tns.previewDevicesService.on("deviceFound", device => {
1387+
console.log("Attached device with identifier: " + device.id);
1388+
});
1389+
```
1390+
1391+
* `deviceLost` - Raised when the Preview app is stopped on a specified device. The callback function will receive one argument - `device`.
1392+
Sample usage:
1393+
```JavaScript
1394+
tns.previewDevicesService.on("deviceLost", device => {
1395+
console.log("Detached device with identifier: " + device.id);
1396+
});
1397+
```
1398+
1399+
* `deviceLog` - Raised when the app deployed in Preview app reports any information. The event is raised for any device that reports data. The callback function has two arguments - `device` and `message`. <br/><br/>
1400+
Sample usage:
1401+
```JavaScript
1402+
tns.previewDevicesService.on("deviceLogData", (device, message) => {
1403+
console.log("Device " + device.id + " reports: " + message);
1404+
});
1405+
```
1406+
1407+
## previewQrCodeService
1408+
The `previewQrCodeService` exposes methods for getting information about the QR of the Playground app and deployed app in Preview app.
1409+
1410+
### getPlaygroundAppQrCode
1411+
Returns information used to generate the QR code of the Playground app.
1412+
1413+
* Usage:
1414+
```TypeScript
1415+
tns.previewQrCodeService.getPlaygroundAppQrCode()
1416+
.then(result => {
1417+
console.log("QR code data for iOS platform: " + result.ios);
1418+
console.log("QR code data for Android platform: " + result.android);
1419+
});
1420+
```
1421+
13441422
## How to add a new method to Public API
13451423
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.
13461424
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)