Skip to content

Commit cd32805

Browse files
committed
feat(api): respect the correct min supported versions for ksplay schema
1 parent 882ca60 commit cd32805

File tree

5 files changed

+71
-16
lines changed

5 files changed

+71
-16
lines changed

lib/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ $injector.require("previewAppLiveSyncService", "./services/livesync/playground/p
140140
$injector.require("previewAppLogProvider", "./services/livesync/playground/preview-app-log-provider");
141141
$injector.require("previewAppPluginsService", "./services/livesync/playground/preview-app-plugins-service");
142142
$injector.require("previewSdkService", "./services/livesync/playground/preview-sdk-service");
143+
$injector.require("previewSchemaService", "./services/livesync/playground/preview-schema-service");
143144
$injector.requirePublicClass("previewDevicesService", "./services/livesync/playground/devices/preview-devices-service");
144145
$injector.requirePublic("previewQrCodeService", "./services/livesync/playground/preview-qr-code-service");
145146
$injector.requirePublic("sysInfo", "./sys-info");

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ declare global {
2222

2323
interface IPreviewSdkService extends EventEmitter {
2424
getQrCodeUrl(options: IGetQrCodeUrlOptions): string;
25-
initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
25+
initialize(projectDir: string, getInitialFiles: (device: Device) => Promise<FilesPayload>): void;
2626
applyChanges(filesPayload: FilesPayload): Promise<void>;
2727
stop(): void;
2828
}
@@ -64,4 +64,18 @@ declare global {
6464
getDevicesForPlatform(platform: string): Device[];
6565
getPluginsUsageWarnings(data: IPreviewAppLiveSyncData, device: Device): string[];
6666
}
67+
68+
interface IPreviewSchemaService {
69+
getSchemaData(projectDir: string): IPreviewSchemaData;
70+
}
71+
72+
interface IPreviewSchemaData {
73+
name: string;
74+
previewAppId: string;
75+
scannerAppId: string;
76+
msvKey: string;
77+
publishKey: string;
78+
subscribeKey: string;
79+
default?: boolean;
80+
}
6781
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class PreviewAppLiveSyncService extends EventEmitter implements IPreviewA
2828

2929
@performanceLog()
3030
public async initialize(data: IPreviewAppLiveSyncData): Promise<void> {
31-
await this.$previewSdkService.initialize(async (device: Device) => {
31+
await this.$previewSdkService.initialize(data.projectDir, async (device: Device) => {
3232
try {
3333
if (!device) {
3434
this.$errors.failWithoutHelp("Sending initial preview files without a specified device is not supported.");
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { PubnubKeys } from "./preview-app-constants";
2+
3+
export class PreviewSchemaService implements IPreviewSchemaService {
4+
private previewSchemas: IDictionary<IPreviewSchemaData> = {
5+
"nsplay": {
6+
name: "nsplay",
7+
previewAppId: "org.nativescript.preview",
8+
scannerAppId: "org.nativescript.play",
9+
msvKey: "cli",
10+
publishKey: PubnubKeys.PUBLISH_KEY,
11+
subscribeKey: PubnubKeys.SUBSCRIBE_KEY,
12+
default: true
13+
},
14+
"ksplay": {
15+
name: "ksplay",
16+
previewAppId: "com.kinvey.preview",
17+
scannerAppId: "com.kinvey.scanner",
18+
msvKey: "kinveyStudio",
19+
publishKey: PubnubKeys.PUBLISH_KEY,
20+
subscribeKey: PubnubKeys.SUBSCRIBE_KEY
21+
}
22+
};
23+
24+
constructor(private $errors: IErrors,
25+
private $projectDataService: IProjectDataService) { }
26+
27+
public getSchemaData(projectDir: string): IPreviewSchemaData {
28+
const projectData = this.$projectDataService.getProjectData(projectDir);
29+
30+
let schemaName = projectData.previewAppSchema;
31+
if (!schemaName) {
32+
schemaName = _.findKey(this.previewSchemas, previewSchema => previewSchema.default);
33+
}
34+
35+
const result = this.previewSchemas[schemaName];
36+
if (!result) {
37+
this.$errors.failWithoutHelp(`Invalid schema. The valid schemas are ${_.keys(this.previewSchemas)}.`);
38+
}
39+
40+
return result;
41+
}
42+
}
43+
$injector.register("previewSchemaService", PreviewSchemaService);

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

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { MessagingService, Config, Device, DeviceConnectedMessage, SdkCallbacks, ConnectedDevices, FilesPayload } from "nativescript-preview-sdk";
2-
import { PubnubKeys } from "./preview-app-constants";
32
import { EventEmitter } from "events";
43
const pako = require("pako");
54

@@ -13,24 +12,20 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
1312
private $logger: ILogger,
1413
private $previewDevicesService: IPreviewDevicesService,
1514
private $previewAppLogProvider: IPreviewAppLogProvider,
16-
private $projectDataService: IProjectDataService) {
15+
private $previewSchemaService: IPreviewSchemaService) {
1716
super();
1817
}
1918

2019
public getQrCodeUrl(options: IGetQrCodeUrlOptions): string {
2120
const { projectDir, useHotModuleReload } = options;
22-
const projectData = this.$projectDataService.getProjectData(projectDir);
23-
const schema = projectData.previewAppSchema || "nsplay";
24-
// TODO: Use the correct keys for the schema
25-
const publishKey = PubnubKeys.PUBLISH_KEY;
26-
const subscribeKey = PubnubKeys.SUBSCRIBE_KEY;
21+
const schema = this.$previewSchemaService.getSchemaData(projectDir);
2722
const hmrValue = useHotModuleReload ? "1" : "0";
28-
const result = `${schema}://boot?instanceId=${this.instanceId}&pKey=${publishKey}&sKey=${subscribeKey}&template=play-ng&hmr=${hmrValue}`;
23+
const result = `${schema.name}://boot?instanceId=${this.instanceId}&pKey=${schema.publishKey}&sKey=${schema.subscribeKey}&template=play-ng&hmr=${hmrValue}`;
2924
return result;
3025
}
3126

32-
public async initialize(getInitialFiles: (device: Device) => Promise<FilesPayload>): Promise<void> {
33-
const initConfig = this.getInitConfig(getInitialFiles);
27+
public async initialize(projectDir: string, getInitialFiles: (device: Device) => Promise<FilesPayload>): Promise<void> {
28+
const initConfig = this.getInitConfig(projectDir, getInitialFiles);
3429
this.messagingService = new MessagingService();
3530
this.instanceId = await this.messagingService.initialize(initConfig);
3631
}
@@ -51,11 +46,13 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
5146
this.messagingService.stop();
5247
}
5348

54-
private getInitConfig(getInitialFiles: (device: Device) => Promise<FilesPayload>): Config {
49+
private getInitConfig(projectDir: string, getInitialFiles: (device: Device) => Promise<FilesPayload>): Config {
50+
const schema = this.$previewSchemaService.getSchemaData(projectDir);
51+
5552
return {
56-
pubnubPublishKey: PubnubKeys.PUBLISH_KEY,
57-
pubnubSubscribeKey: PubnubKeys.SUBSCRIBE_KEY,
58-
msvKey: "cli",
53+
pubnubPublishKey: schema.publishKey,
54+
pubnubSubscribeKey: schema.subscribeKey,
55+
msvKey: schema.msvKey,
5956
msvEnv: this.$config.PREVIEW_APP_ENVIRONMENT,
6057
showLoadingPage: false,
6158
callbacks: this.getCallbacks(),

0 commit comments

Comments
 (0)