diff --git a/lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js b/lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js index 22783835..51a9cbfd 100644 --- a/lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js +++ b/lib/js/src/manager/screen/utils/_VoiceCommandUpdateOperation.js @@ -144,13 +144,25 @@ class _VoiceCommandUpdateOperation extends _Task { return true; // nothing to delete } - // make an AddCommand request for every voice command - const addCommands = this._pendingVoiceCommands.map(voiceCommand => { + // filter the voice command list of any voice commands with duplicate items + const addCommands = this._pendingVoiceCommands.filter(voiceCommand => { + // Sets can only hold unique values. The size will be different if there are duplicates + const uniqueList = new Set(voiceCommand.getVoiceCommands()); + if (voiceCommand.getVoiceCommands().length !== uniqueList.size) { + return false; + } + return true; + }).map(voiceCommand => { + // make an AddCommand request for every voice command return new AddCommand() .setCmdID(voiceCommand._getCommandId()) .setVrCommands(voiceCommand.getVoiceCommands()); }); + if (addCommands.length !== this._pendingVoiceCommands.length) { + console.log('One or more VoiceCommands contained duplicate items and will not be sent.'); + } + const addCommandPromises = addCommands.map(addCommand => { return this._lifecycleManager.sendRpcResolve(addCommand); });