diff --git a/examples/js/hello-sdl/index.html b/examples/js/hello-sdl/index.html index fb0c62b6..3b3d4056 100644 --- a/examples/js/hello-sdl/index.html +++ b/examples/js/hello-sdl/index.html @@ -53,7 +53,7 @@ .setLanguageDesired(SDL.rpc.enums.Language.EN_US) .setHmiDisplayLanguageDesired(SDL.rpc.enums.Language.EN_US) .setAppTypes([ - SDL.rpc.enums.AppHMIType.DEFAULT, + SDL.rpc.enums.AppHMIType.MEDIA, ]) .setTransportConfig(new SDL.transport.WebSocketClientConfig('ws://localhost', 5050)) .setAppIcon(file) @@ -124,6 +124,8 @@ screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED); screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG) .setFilePath(this._filePath)); + screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration() + .setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA)); } async _onHmiStatusListener (onHmiStatus) { @@ -133,7 +135,16 @@ // wait for the FULL state for more functionality if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) { const screenManager = this._sdlManager.getScreenManager(); - if (!this._isButtonSubscriptionRequested) { + const isRpcAllowed = (rpc) => { + return this._permissionManager && + this._permissionManager.isRpcAllowed(rpc); + }; + + if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) { + const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) { + return capability.getNameParam(); + }); + // add button listeners const ButtonName = SDL.rpc.enums.ButtonName; const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, @@ -141,11 +152,16 @@ ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT, ButtonName.TUNEUP, ButtonName.TUNEDOWN]; + for (const buttonName of buttonNames) { - await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)) - .catch((reason) => { - console.error(`Unable to subscribe to button: ${reason}`); + if (availableButtons.indexOf(buttonName) !== -1) { + console.log('Subscribing to', buttonName); + await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { + console.error(err); }); + } else { + console.log('No capability found for button', buttonName); + } } this._isButtonSubscriptionRequested = true; @@ -183,12 +199,9 @@ const count = 3; for (let i = 0; i < count; i++) { - const showCountdown = new SDL.rpc.messages.Show(); - showCountdown.setMainField1(`Exiting in ${(count - i).toString()}`) - .setMainField2('') - .setMainField3(''); - - this._sdlManager.sendRpcResolve(showCountdown); // don't wait for a response + screenManager.setTextField1(`Exiting in ${(count - i).toString()}`) + .setTextField2('') + .setTextField3(''); await this._sleep(); } diff --git a/examples/node/hello-sdl-tcp/index.js b/examples/node/hello-sdl-tcp/index.js index 59dec415..6df69f69 100644 --- a/examples/node/hello-sdl-tcp/index.js +++ b/examples/node/hello-sdl-tcp/index.js @@ -48,7 +48,7 @@ class AppClient { .setAppName(CONFIG.appName) .setLanguageDesired(SDL.rpc.enums.Language.EN_US) .setAppTypes([ - SDL.rpc.enums.AppHMIType.DEFAULT, + SDL.rpc.enums.AppHMIType.MEDIA, ]) .setTransportConfig(new SDL.transport.TcpClientConfig(CONFIG.host, CONFIG.port)) .setAppIcon(file) @@ -119,6 +119,8 @@ class AppClient { screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED); screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG) .setFilePath(this._filePath)); + screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration() + .setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA)); } async _onHmiStatusListener (onHmiStatus) { @@ -128,7 +130,17 @@ class AppClient { // wait for the FULL state for more functionality if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) { const screenManager = this._sdlManager.getScreenManager(); - if (!this._isButtonSubscriptionRequested) { + const isRpcAllowed = (rpc) => { + return this._permissionManager && + this._permissionManager.isRpcAllowed(rpc); + }; + + if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) { + // Get supported buttons + const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) { + return capability.getNameParam(); + }); + // add button listeners const ButtonName = SDL.rpc.enums.ButtonName; const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, @@ -137,9 +149,14 @@ class AppClient { ButtonName.TUNEUP, ButtonName.TUNEDOWN]; for (const buttonName of buttonNames) { - await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { - console.error(err); - }); + if (availableButtons.indexOf(buttonName) !== -1) { + console.log('Subscribing to', buttonName); + await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { + console.error(err); + }); + } else { + console.log('No capability found for button', buttonName); + } } this._isButtonSubscriptionRequested = true; @@ -177,12 +194,9 @@ class AppClient { const count = 3; for (let i = 0; i < count; i++) { - const showCountdown = new SDL.rpc.messages.Show(); - showCountdown.setMainField1(`Exiting in ${(count - i).toString()}`) - .setMainField2('') - .setMainField3(''); - - this._sdlManager.sendRpcResolve(showCountdown); // don't wait for a response + screenManager.setTextField1(`Exiting in ${(count - i).toString()}`) + .setTextField2('') + .setTextField3(''); await this._sleep(); } @@ -219,4 +233,4 @@ class AppClient { } console.log('start app'); -new AppClient(); \ No newline at end of file +new AppClient(); diff --git a/examples/node/hello-sdl/AppClient.js b/examples/node/hello-sdl/AppClient.js index 005949f2..b4a0644e 100644 --- a/examples/node/hello-sdl/AppClient.js +++ b/examples/node/hello-sdl/AppClient.js @@ -48,7 +48,7 @@ class AppClient { .setAppName(CONFIG.appName) .setLanguageDesired(SDL.rpc.enums.Language.EN_US) .setAppTypes([ - SDL.rpc.enums.AppHMIType.DEFAULT, + SDL.rpc.enums.AppHMIType.MEDIA, ]) .setTransportConfig( new SDL.transport.WebSocketServerConfig( @@ -124,7 +124,17 @@ class AppClient { async _checkReadyState () { if (this._managersReady && this._hmiFull) { const screenManager = this._sdlManager.getScreenManager(); - if (!this._isButtonSubscriptionRequested) { + const isRpcAllowed = (rpc) => { + return this._permissionManager && + this._permissionManager.isRpcAllowed(rpc); + }; + + if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) { + // Get supported buttons + const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) { + return capability.getNameParam(); + }); + // add button listeners const ButtonName = SDL.rpc.enums.ButtonName; const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3, @@ -133,10 +143,14 @@ class AppClient { ButtonName.TUNEUP, ButtonName.TUNEDOWN]; for (const buttonName of buttonNames) { - await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)) - .catch((reason) => { - console.error(`Unable to subscribe to button: ${reason}`); + if (availableButtons.indexOf(buttonName) !== -1) { + console.log('Subscribing to', buttonName); + await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { + console.error(err); }); + } else { + console.log('No capability found for button', buttonName); + } } this._isButtonSubscriptionRequested = true; @@ -163,6 +177,8 @@ class AppClient { screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED); screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG) .setFilePath(this._filePath)); + screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration() + .setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA)); const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG) .setFilePath(this._filePath); diff --git a/examples/webengine/hello-sdl/index.html b/examples/webengine/hello-sdl/index.html index 8bbac988..e91f91b6 100644 --- a/examples/webengine/hello-sdl/index.html +++ b/examples/webengine/hello-sdl/index.html @@ -129,6 +129,8 @@ screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED); screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG) .setFilePath(sdlManifest.appIcon)); + screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration() + .setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA)); } async _onSystemCapabilityUpdatedRpcListener (capabilityMessage) { @@ -169,6 +171,10 @@ }; if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) { + const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) { + return capability.getNameParam(); + }); + // add button listeners const screenManager = this._sdlManager.getScreenManager(); const ButtonName = SDL.rpc.enums.ButtonName; @@ -178,10 +184,14 @@ ButtonName.TUNEUP, ButtonName.TUNEDOWN]; for (const buttonName of buttonNames) { - await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)) - .catch((reason) => { - this._logRegularMessage(`Unable to subscribe to button: ${reason}`); + if (availableButtons.indexOf(buttonName) !== -1) { + console.log('Subscribing to', buttonName); + await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) { + console.error(err); }); + } else { + console.log('No capability found for button', buttonName); + } } this._isButtonSubscriptionRequested = true;