Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions examples/js/hello-sdl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -133,19 +135,33 @@
// 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,
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
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;
Expand Down Expand Up @@ -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();
}
Expand Down
38 changes: 26 additions & 12 deletions examples/node/hello-sdl-tcp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -219,4 +233,4 @@ class AppClient {
}

console.log('start app');
new AppClient();
new AppClient();
26 changes: 21 additions & 5 deletions examples/node/hello-sdl/AppClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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;
Expand All @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions examples/webengine/hello-sdl/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down