Skip to content

Commit e77960f

Browse files
authored
Merge pull request #319 from LuxoftSDL/fix/fix_request_sending_on_permissions_change
Fix request sending on permissions change
2 parents e342991 + f8c40df commit e77960f

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

examples/js/hello-sdl/index.html

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898

9999
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
100100
this._sdlManager.start();
101+
this._isButtonSubscriptionRequested = false;
101102
}
102103

103104
async _onConnected () {
@@ -131,15 +132,23 @@
131132

132133
// wait for the FULL state for more functionality
133134
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
134-
// add button listeners
135135
const screenManager = this._sdlManager.getScreenManager();
136-
const ButtonName = SDL.rpc.enums.ButtonName;
137-
const buttonNames = [ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE, ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP,
138-
ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST, ButtonName.UPPER_VENT,
139-
ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT];
140-
141-
for (const buttonName of buttonNames) {
142-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this));
136+
if (!this._isButtonSubscriptionRequested) {
137+
// add button listeners
138+
const ButtonName = SDL.rpc.enums.ButtonName;
139+
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
140+
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
141+
ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT,
142+
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
143+
144+
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}`);
148+
});
149+
}
150+
151+
this._isButtonSubscriptionRequested = true;
143152
}
144153

145154
const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class AppClient {
9393

9494
this._sdlManager = new SDL.manager.SdlManager(this._appConfig, managerListener);
9595
this._sdlManager.start();
96+
this._isButtonSubscriptionRequested = false;
9697
}
9798

9899
async _onConnected () {
@@ -126,17 +127,22 @@ class AppClient {
126127

127128
// wait for the FULL state for more functionality
128129
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
129-
// add button listeners
130130
const screenManager = this._sdlManager.getScreenManager();
131-
const ButtonName = SDL.rpc.enums.ButtonName;
132-
const buttonNames = [ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE, ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP,
133-
ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST, ButtonName.UPPER_VENT,
134-
ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT];
135-
136-
for (const buttonName of buttonNames) {
137-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
138-
console.error(err);
139-
});
131+
if (!this._isButtonSubscriptionRequested) {
132+
// add button listeners
133+
const ButtonName = SDL.rpc.enums.ButtonName;
134+
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
135+
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
136+
ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT,
137+
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
138+
139+
for (const buttonName of buttonNames) {
140+
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this)).catch(function (err) {
141+
console.error(err);
142+
});
143+
}
144+
145+
this._isButtonSubscriptionRequested = true;
140146
}
141147

142148
const art1 = new SDL.manager.file.filetypes.SdlArtwork('logo', SDL.rpc.enums.FileType.GRAPHIC_PNG)

examples/node/hello-sdl/AppClient.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class AppClient {
102102
// for a cloud server app the hmi full will be received before the managers report that they're ready!
103103
this._managersReady = false;
104104
this._hmiFull = false;
105+
this._isButtonSubscriptionRequested = false;
105106
}
106107

107108
_onConnected () {
@@ -122,15 +123,23 @@ class AppClient {
122123

123124
async _checkReadyState () {
124125
if (this._managersReady && this._hmiFull) {
125-
// add button listeners
126126
const screenManager = this._sdlManager.getScreenManager();
127-
const ButtonName = SDL.rpc.enums.ButtonName;
128-
const buttonNames = [ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE, ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP,
129-
ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST, ButtonName.UPPER_VENT,
130-
ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT];
131-
132-
for (const buttonName of buttonNames) {
133-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this));
127+
if (!this._isButtonSubscriptionRequested) {
128+
// add button listeners
129+
const ButtonName = SDL.rpc.enums.ButtonName;
130+
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
131+
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
132+
ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT,
133+
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
134+
135+
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}`);
139+
});
140+
}
141+
142+
this._isButtonSubscriptionRequested = true;
134143
}
135144

136145
// add voice commands

examples/webengine/hello-sdl/index.html

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393

9494
this._currentTemplate = 'WEB_VIEW';
9595
this._isTemplateSwitchCommandAdded = false;
96+
this._isButtonSubscriptionRequested = false;
9697
this._templateSwitchCommandId = 1001;
9798
}
9899

@@ -162,18 +163,31 @@
162163

163164
// wait for the FULL state for more functionality
164165
if (hmiLevel === SDL.rpc.enums.HMILevel.HMI_FULL) {
165-
// add button listeners
166-
const screenManager = this._sdlManager.getScreenManager();
167-
const ButtonName = SDL.rpc.enums.ButtonName;
168-
const buttonNames = [ButtonName.AC_MAX, ButtonName.AC, ButtonName.RECIRCULATE, ButtonName.FAN_UP, ButtonName.FAN_DOWN, ButtonName.TEMP_UP,
169-
ButtonName.TEMP_DOWN, ButtonName.FAN_DOWN, ButtonName.DEFROST_MAX, ButtonName.DEFROST_REAR, ButtonName.DEFROST, ButtonName.UPPER_VENT,
170-
ButtonName.LOWER_VENT, ButtonName.VOLUME_UP, ButtonName.VOLUME_DOWN, ButtonName.EJECT, ButtonName.SOURCE, ButtonName.SHUFFLE, ButtonName.REPEAT];
171-
172-
for (const buttonName of buttonNames) {
173-
await screenManager.addButtonListener(buttonName, this._onButtonListener.bind(this));
166+
const isRpcAllowed = (rpc) => {
167+
return this._permissionManager &&
168+
this._permissionManager.isRpcAllowed(rpc);
169+
};
170+
171+
if (!this._isButtonSubscriptionRequested && isRpcAllowed(SDL.rpc.enums.FunctionID.SubscribeButton)) {
172+
// add button listeners
173+
const screenManager = this._sdlManager.getScreenManager();
174+
const ButtonName = SDL.rpc.enums.ButtonName;
175+
const buttonNames = [ButtonName.PRESET_0, ButtonName.PRESET_1, ButtonName.PRESET_2, ButtonName.PRESET_3,
176+
ButtonName.PRESET_4, ButtonName.PRESET_5, ButtonName.PRESET_6, ButtonName.PRESET_7, ButtonName.PRESET_8,
177+
ButtonName.PRESET_9, ButtonName.PLAY_PAUSE, ButtonName.OK, ButtonName.SEEKLEFT, ButtonName.SEEKRIGHT,
178+
ButtonName.TUNEUP, ButtonName.TUNEDOWN];
179+
180+
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}`);
184+
});
185+
}
186+
187+
this._isButtonSubscriptionRequested = true;
174188
}
175189

176-
if (!this._isTemplateSwitchCommandAdded && this._permissionManager && this._permissionManager.isRpcAllowed(SDL.rpc.enums.FunctionID.AddCommand)) {
190+
if (!this._isTemplateSwitchCommandAdded && isRpcAllowed(SDL.rpc.enums.FunctionID.AddCommand)) {
177191
this._logRegularMessage('Adding return to WEB_VIEW template command');
178192
this._isTemplateSwitchCommandAdded = true;
179193

0 commit comments

Comments
 (0)