Skip to content

Commit 336a659

Browse files
authored
Merge pull request #335 from smartdevicelink/feature/1.2.0-example-apps-update
Feature/1.2.0 example apps update
2 parents 65b8add + a92cd42 commit 336a659

File tree

4 files changed

+84
-31
lines changed

4 files changed

+84
-31
lines changed

examples/js/hello-sdl/index.html

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
.setLanguageDesired(SDL.rpc.enums.Language.EN_US)
5454
.setHmiDisplayLanguageDesired(SDL.rpc.enums.Language.EN_US)
5555
.setAppTypes([
56-
SDL.rpc.enums.AppHMIType.DEFAULT,
56+
SDL.rpc.enums.AppHMIType.MEDIA,
5757
])
5858
.setTransportConfig(new SDL.transport.WebSocketClientConfig('ws://localhost', 5050))
5959
.setAppIcon(file)
@@ -124,6 +124,8 @@
124124
screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
125125
screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
126126
.setFilePath(this._filePath));
127+
screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration()
128+
.setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA));
127129
}
128130

129131
async _onHmiStatusListener (onHmiStatus) {
@@ -133,19 +135,33 @@
133135
// wait for the FULL state for more functionality
134136
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
135137
const screenManager = this._sdlManager.getScreenManager();
136-
if (!this._isButtonSubscriptionRequested) {
138+
const isRpcAllowed = (rpc) => {
139+
return this._permissionManager &&
140+
this._permissionManager.isRpcAllowed(rpc);
141+
};
142+
143+
if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) {
144+
const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) {
145+
return capability.getNameParam();
146+
});
147+
137148
// add button listeners
138149
const ButtonName = SDL.rpc.enums.ButtonName;
139150
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
140151
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
141152
ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT,
142153
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
143154

155+
144156
for (const buttonName of buttonNames) {
145-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this))
146-
.catch((reason) => {
147-
console.error(`Unable to subscribe to button: ${reason}`);
157+
if (availableButtons.indexOf(buttonName) !== -1) {
158+
console.log('Subscribing to', buttonName);
159+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
160+
console.error(err);
148161
});
162+
} else {
163+
console.log('No capability found for button', buttonName);
164+
}
149165
}
150166

151167
this._isButtonSubscriptionRequested = true;
@@ -183,12 +199,9 @@
183199

184200
const count = 3;
185201
for (let i = 0; i < count; i++) {
186-
const showCountdown = new SDL.rpc.messages.Show();
187-
showCountdown.setMainField1(`Exiting in ${(count - i).toString()}`)
188-
.setMainField2('')
189-
.setMainField3('');
190-
191-
this._sdlManager.sendRpcResolve(showCountdown); // don't wait for a response
202+
screenManager.setTextField1(`Exiting in ${(count - i).toString()}`)
203+
.setTextField2('')
204+
.setTextField3('');
192205

193206
await this._sleep();
194207
}

examples/node/hello-sdl-tcp/index.js

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AppClient {
4848
.setAppName(CONFIG.appName)
4949
.setLanguageDesired(SDL.rpc.enums.Language.EN_US)
5050
.setAppTypes([
51-
SDL.rpc.enums.AppHMIType.DEFAULT,
51+
SDL.rpc.enums.AppHMIType.MEDIA,
5252
])
5353
.setTransportConfig(new SDL.transport.TcpClientConfig(CONFIG.host, CONFIG.port))
5454
.setAppIcon(file)
@@ -119,6 +119,8 @@ class AppClient {
119119
screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
120120
screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
121121
.setFilePath(this._filePath));
122+
screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration()
123+
.setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA));
122124
}
123125

124126
async _onHmiStatusListener (onHmiStatus) {
@@ -128,7 +130,17 @@ class AppClient {
128130
// wait for the FULL state for more functionality
129131
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
130132
const screenManager = this._sdlManager.getScreenManager();
131-
if (!this._isButtonSubscriptionRequested) {
133+
const isRpcAllowed = (rpc) => {
134+
return this._permissionManager &&
135+
this._permissionManager.isRpcAllowed(rpc);
136+
};
137+
138+
if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) {
139+
// Get supported buttons
140+
const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) {
141+
return capability.getNameParam();
142+
});
143+
132144
// add button listeners
133145
const ButtonName = SDL.rpc.enums.ButtonName;
134146
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
@@ -137,9 +149,14 @@ class AppClient {
137149
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
138150

139151
for (const buttonName of buttonNames) {
140-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
141-
console.error(err);
142-
});
152+
if (availableButtons.indexOf(buttonName) !== -1) {
153+
console.log('Subscribing to', buttonName);
154+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
155+
console.error(err);
156+
});
157+
} else {
158+
console.log('No capability found for button', buttonName);
159+
}
143160
}
144161

145162
this._isButtonSubscriptionRequested = true;
@@ -177,12 +194,9 @@ class AppClient {
177194

178195
const count = 3;
179196
for (let i = 0; i < count; i++) {
180-
const showCountdown = new SDL.rpc.messages.Show();
181-
showCountdown.setMainField1(`Exiting in ${(count - i).toString()}`)
182-
.setMainField2('')
183-
.setMainField3('');
184-
185-
this._sdlManager.sendRpcResolve(showCountdown); // don't wait for a response
197+
screenManager.setTextField1(`Exiting in ${(count - i).toString()}`)
198+
.setTextField2('')
199+
.setTextField3('');
186200

187201
await this._sleep();
188202
}
@@ -219,4 +233,4 @@ class AppClient {
219233
}
220234

221235
console.log('start app');
222-
new AppClient();
236+
new AppClient();

examples/node/hello-sdl/AppClient.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AppClient {
4848
.setAppName(CONFIG.appName)
4949
.setLanguageDesired(SDL.rpc.enums.Language.EN_US)
5050
.setAppTypes([
51-
SDL.rpc.enums.AppHMIType.DEFAULT,
51+
SDL.rpc.enums.AppHMIType.MEDIA,
5252
])
5353
.setTransportConfig(
5454
new SDL.transport.WebSocketServerConfig(
@@ -124,7 +124,17 @@ class AppClient {
124124
async _checkReadyState () {
125125
if (this._managersReady && this._hmiFull) {
126126
const screenManager = this._sdlManager.getScreenManager();
127-
if (!this._isButtonSubscriptionRequested) {
127+
const isRpcAllowed = (rpc) => {
128+
return this._permissionManager &&
129+
this._permissionManager.isRpcAllowed(rpc);
130+
};
131+
132+
if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) {
133+
// Get supported buttons
134+
const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) {
135+
return capability.getNameParam();
136+
});
137+
128138
// add button listeners
129139
const ButtonName = SDL.rpc.enums.ButtonName;
130140
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
@@ -133,10 +143,14 @@ class AppClient {
133143
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
134144

135145
for (const buttonName of buttonNames) {
136-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this))
137-
.catch((reason) => {
138-
console.error(`Unable to subscribe to button: ${reason}`);
146+
if (availableButtons.indexOf(buttonName) !== -1) {
147+
console.log('Subscribing to', buttonName);
148+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
149+
console.error(err);
139150
});
151+
} else {
152+
console.log('No capability found for button', buttonName);
153+
}
140154
}
141155

142156
this._isButtonSubscriptionRequested = true;
@@ -163,6 +177,8 @@ class AppClient {
163177
screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
164178
screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
165179
.setFilePath(this._filePath));
180+
screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration()
181+
.setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA));
166182

167183
const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
168184
.setFilePath(this._filePath);

examples/webengine/hello-sdl/index.html

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@
129129
screenManager.setTextAlignment(SDL.rpc.enums.TextAlignment.RIGHT_ALIGNED);
130130
screenManager.setPrimaryGraphic(new SDL.manager.file.filetypes.SdlArtwork('sdl-logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)
131131
.setFilePath(sdlManifest.appIcon));
132+
screenManager.changeLayout(new SDL.rpc.structs.TemplateConfiguration()
133+
.setTemplate(SDL.rpc.enums.PredefinedLayout.NON_MEDIA));
132134
}
133135

134136
async _onSystemCapabilityUpdatedRpcListener (capabilityMessage) {
@@ -169,6 +171,10 @@
169171
};
170172

171173
if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) {
174+
const availableButtons = this._sdlManager.getRegisterAppInterfaceResponse().getButtonCapabilities().map(function (capability) {
175+
return capability.getNameParam();
176+
});
177+
172178
// add button listeners
173179
const screenManager = this._sdlManager.getScreenManager();
174180
const ButtonName = SDL.rpc.enums.ButtonName;
@@ -178,10 +184,14 @@
178184
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
179185

180186
for (const buttonName of buttonNames) {
181-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this))
182-
.catch((reason) => {
183-
this._logRegularMessage(`Unable to subscribe to button: ${reason}`);
187+
if (availableButtons.indexOf(buttonName) !== -1) {
188+
console.log('Subscribing to', buttonName);
189+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
190+
console.error(err);
184191
});
192+
} else {
193+
console.log('No capability found for button', buttonName);
194+
}
185195
}
186196

187197
this._isButtonSubscriptionRequested = true;

0 commit comments

Comments
 (0)