11import { MessagingService , Config , Device , DeviceConnectedMessage , SdkCallbacks , ConnectedDevices , FilesPayload } from "nativescript-preview-sdk" ;
2- import { PubnubKeys } from "./preview-app-constants" ;
32import { EventEmitter } from "events" ;
43const 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,15 +46,18 @@ 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 ,
60- showLoadingPage : false ,
6157 callbacks : this . getCallbacks ( ) ,
62- getInitialFiles
58+ getInitialFiles,
59+ previewAppStoreId : schema . previewAppStoreId ,
60+ previewAppGooglePlayId : schema . previewAppId
6361 } ;
6462 }
6563
0 commit comments