UNPKG

domotz-remote-pawn

Version:

Domotz Agent

63 lines (57 loc) 2.28 kB
/** This file is part of Domotz Agent. * Copyright (C) 2016 Domotz UK LLP * * Domotz Agent is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Domotz Agent is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Domotz Agent. If not, see <http://www.gnu.org/licenses/>. **/ /** * * Created by Massimiliano Cuzzoli <massi@domotz.com> on 26/08/16. * */ var PROTOCOL_VERSION = 1; var messageBuilderFactory = function (resourceLocator) { var sortedHashTable = resourceLocator.utils.dataStructure.sortedHashTable; var sortedDictionaryKeys = resourceLocator.utils.dataStructure.sortedDictionaryKeys; return { buildSuccessMessage: function (message_payload) { return { error: false, payload: message_payload }; }, buildErrorMessage: function (error_level, error_status_code, error_description) { return { error: true, level: error_level, status_code: error_status_code, description: error_description }; }, buildUpnpDeviceMessageForEngine: function (message_payload) { var cloned_payload = JSON.parse(JSON.stringify(message_payload)); // Sorting relevant fields of the message to ease message comparison cloned_payload = sortedHashTable(cloned_payload); for (var location in cloned_payload) { if (cloned_payload.hasOwnProperty(location)) { cloned_payload[location].uuid = sortedDictionaryKeys(cloned_payload[location].uuid); } } return { version: PROTOCOL_VERSION, location: cloned_payload }; } }; }; module.exports.factory = messageBuilderFactory;