Skip to content

Commit 5b6d659

Browse files
committed
Integrate version 0.2.0 of nativescript-preview-sdk
1 parent ef85dcc commit 5b6d659

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

lib/definitions/preview-app-livesync.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ declare global {
1414
qrCodeUrl: string;
1515
connectedDevices: Device[];
1616
initialize(): void;
17-
applyChanges(files: FilePayload[], deviceId: string): Promise<void>;
17+
applyChanges(files: FilePayload[], platform: string): Promise<void>;
1818
stop(): void;
1919
}
2020

lib/services/livesync/playground/preview-app-livesync-service.ts

+4-8
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,18 @@ export class PreviewAppLiveSyncService implements IPreviewAppLiveSyncService {
8383
const projectData = this.$projectDataService.getProjectData(projectDir);
8484
await this.preparePlatform(platform, appFilesUpdaterOptions, env, projectData);
8585

86-
// TODO: This should be refactored after implementing platform param in pubnub's meta data.
87-
const devices = this.$previewSdkService.connectedDevices.filter(device => device.platform === platform);
88-
for (const device of devices) {
89-
await this.applyChanges(projectData, device, files);
90-
}
86+
await this.applyChanges(projectData, platform, files);
9187

9288
this.$logger.info(`Successfully synced changes for platform ${platform}.`);
9389
} catch (err) {
9490
this.$logger.warn(`Unable to apply changes for platform ${platform}. Error is: ${err}, ${JSON.stringify(err, null, 2)}.`);
9591
}
9692
}
9793

98-
private async applyChanges(projectData: IProjectData, device: Device, files: string[]) {
99-
const platformData = this.$platformsData.getPlatformData(device.platform, projectData);
94+
private async applyChanges(projectData: IProjectData, platform: string, files: string[]) {
95+
const platformData = this.$platformsData.getPlatformData(platform, projectData);
10096
const payloads = this.getFilePayloads(platformData, projectData, _(files).uniq().value());
101-
await this.$previewSdkService.applyChanges(payloads, device.id);
97+
await this.$previewSdkService.applyChanges(payloads, platform);
10298
}
10399

104100
private getFilePayloads(platformData: IPlatformData, projectData: IProjectData, files?: string[]): FilePayload[] {

lib/services/livesync/playground/preview-sdk-service.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
2525
this.instanceId = this.messagingService.initialize(initConfig);
2626
}
2727

28-
public applyChanges(files: FilePayload[], deviceId: string): Promise<void> {
28+
public applyChanges(files: FilePayload[], platform: string): Promise<void> {
2929
return new Promise((resolve, reject) => {
30-
this.messagingService.applyChanges(this.instanceId, files, deviceId, err => {
30+
this.messagingService.applyChanges(this.instanceId, { files, platform }, err => {
3131
if (err) {
3232
reject(err);
3333
} else {
@@ -46,7 +46,11 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
4646
pubnubPublishKey: PubnubKeys.PUBLISH_KEY,
4747
pubnubSubscribeKey: PubnubKeys.SUBSCRIBE_KEY,
4848
callbacks: this.getCallbacks(),
49-
getInitialFiles: async () => []
49+
getInitialFiles: async () => {
50+
return {
51+
files: []
52+
};
53+
}
5054
};
5155
}
5256

0 commit comments

Comments
 (0)