1
1
import { MessagingService , Config , Device , DeviceConnectedMessage , SdkCallbacks , ConnectedDevices , FilesPayload } from "nativescript-preview-sdk" ;
2
- import { PubnubKeys } from "./preview-app-constants" ;
3
2
import { EventEmitter } from "events" ;
4
3
const pako = require ( "pako" ) ;
5
4
@@ -13,24 +12,20 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
13
12
private $logger : ILogger ,
14
13
private $previewDevicesService : IPreviewDevicesService ,
15
14
private $previewAppLogProvider : IPreviewAppLogProvider ,
16
- private $projectDataService : IProjectDataService ) {
15
+ private $previewSchemaService : IPreviewSchemaService ) {
17
16
super ( ) ;
18
17
}
19
18
20
19
public getQrCodeUrl ( options : IGetQrCodeUrlOptions ) : string {
21
20
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 ) ;
27
22
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 } ` ;
29
24
return result ;
30
25
}
31
26
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 ) ;
34
29
this . messagingService = new MessagingService ( ) ;
35
30
this . instanceId = await this . messagingService . initialize ( initConfig ) ;
36
31
}
@@ -51,11 +46,13 @@ export class PreviewSdkService extends EventEmitter implements IPreviewSdkServic
51
46
this . messagingService . stop ( ) ;
52
47
}
53
48
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
+
55
52
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 ,
59
56
msvEnv : this . $config . PREVIEW_APP_ENVIRONMENT ,
60
57
showLoadingPage : false ,
61
58
callbacks : this . getCallbacks ( ) ,
0 commit comments