Skip to content

Commit 86d0756

Browse files
committed
Add availabe button check to webengine app
1 parent dbc81ab commit 86d0756

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/webengine/hello-sdl/index.html

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@
171171
};
172172

173173
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+
174178
// add button listeners
175179
const screenManager = this._sdlManager.getScreenManager();
176180
const ButtonName = SDL.rpc.enums.ButtonName;
@@ -180,10 +184,14 @@
180184
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
181185

182186
for (const buttonName of buttonNames) {
183-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this))
184-
.catch((reason) => {
185-
this._logRegularMessage(`Unable to subscribe to button: ${reason}`);
187+
if (availableButtons.indexOf(buttonName) > 0) {
188+
console.log('Subscribing to', buttonName);
189+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
190+
console.error(err);
186191
});
192+
} else {
193+
console.log('No capability found for button', buttonName);
194+
}
187195
}
188196

189197
this._isButtonSubscriptionRequested = true;

0 commit comments

Comments
 (0)