diff --git a/node_modules/alsa/alsa_bridge.js b/node_modules/alsa/alsa_bridge.js new file mode 100644 index 0000000..4924551 --- /dev/null +++ b/node_modules/alsa/alsa_bridge.js @@ -0,0 +1,87 @@ +/*! +GPII Node.js ALSA Volume Bridge + +Copyright 2013 Emergya + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +(function () { + "use strict"; + + var fluid = require("universal"); + var gpii = fluid.registerNamespace("gpii"); + var alsa = require("./nodealsa/build/Release/nodealsa.node"); + + fluid.registerNamespace("gpii.alsa"); + + fluid.defaults("gpii.alsa.getSystemVolume", { + gradeNames: "fluid.function", + argumentMap: { + } + }); + + fluid.defaults("gpii.alsa.setSystemVolume", { + gradeNames: "fluid.function", + argumentMap: { + value: 0 + } + }); + + fluid.defaults("gpii.alsa.get", { + gradeNames: "fluid.function", + argumentMap: { + payload: 0 + } + }); + + fluid.defaults("gpii.alsa.set", { + gradeNames: "fluid.function", + argumentMap: { + payload: 0 + } + }); + + gpii.alsa.getSystemVolume = function(){ + return alsa.getSystemVolume(); + }; + + gpii.alsa.setSystemVolume = function(value){ + return alsa.setSystemVolume(value); + }; + + gpii.alsa.get = function (payload){ + var app = fluid.copy(payload); + var settings = fluid.copy(app, "data.0.settings"); + + var newSettingsResponse = {masterVolume: gpii.alsa.getSystemVolume()}; + var noOptions = {settings: newSettingsResponse}; + app["data"][0] = noOptions; + + return app; + }; + + gpii.alsa.set = function (payload){ + var app = fluid.copy(payload); + var settings = app['org.alsa-project'][0].settings; + + var oldValue = alsa.getSystemVolume(); + alsa.setSystemVolume(settings['masterVolume']); + + var newSettingsResponse = {}; + newSettingsResponse['masterVolume'] = { + "oldValue": oldValue, + "newValue": settings['masterVolume'] + }; + + var noOptions = {settings: newSettingsResponse}; + fluid.set(app, ['org.alsa-project', 0], noOptions); + + return app; + }; + +})(); diff --git a/node_modules/alsa/index.js b/node_modules/alsa/index.js new file mode 100644 index 0000000..26b45a5 --- /dev/null +++ b/node_modules/alsa/index.js @@ -0,0 +1,17 @@ +/*! +GPII Node.js ALSA Volume Bridge + +Copyright 2013 Emergya + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +var fluid = require("universal"); + +var loader = fluid.getLoader(__dirname); + +loader.require("./alsa_bridge.js"); diff --git a/node_modules/alsa/package.json b/node_modules/alsa/package.json new file mode 100644 index 0000000..9d401df --- /dev/null +++ b/node_modules/alsa/package.json @@ -0,0 +1,19 @@ +{ + "name": "alsaBridge", + "description": "alsaBridge is a Node.js bridge to deal with system volumes.", + "version": "0.1", + "author": "Javier Hernández", + "bugs": "http://wiki.gpii.net/index.php/Main_Page", + "homepage": "http://gpii.net/", + "dependencies": {}, + "licenses": [ + { + "type": "BSD-3-Clause", + "url": "http://www.opensource.org/licenses/BSD-3-Clause" + } + ], + "keywords": ["gpii", "accessibility", "settings", "fluid"], + "repository": "git://github.com:GPII/linux.git", + "main": "./index.js", + "engines": { "node" : ">=0.1.9" } +} diff --git a/node_modules/alsa/test/alsaSettingsHandlerTests.js b/node_modules/alsa/test/alsaSettingsHandlerTests.js new file mode 100644 index 0000000..58c3a70 --- /dev/null +++ b/node_modules/alsa/test/alsaSettingsHandlerTests.js @@ -0,0 +1,57 @@ +/* +GPII Node.js ALSA Volume Bridge + +Copyright 2013 Emergya + +Licensed under the New BSD license. You may not use this file except in +compliance with this License. + +You may obtain a copy of the License at +https://github.com/gpii/universal/LICENSE.txt +*/ + +var fluid = require("universal"), + gpii = fluid.registerNamespace("gpii"), + jqUnit = fluid.require("jqUnit"); + +require("alsa"); +alsa = fluid.registerNamespace("gpii.alsa"); + +jqUnit.module("GPII Node.js ALSA Volume Bridge"); + +jqUnit.test("Running tests for ALSA Settings Handler", function () { + jqUnit.expect(6); + + // Check if all required methods are available through the + // ALSA Settings Handler. + // + methods = ["getSystemVolume", "setSystemVolume", "get", "set"]; + for (var method in methods) { + jqUnit.assertTrue("Checking availability of method '" + method + "'", + (methods[method] in alsa)); + } + + var payload = { + "org.alsa-project": [{ + settings: { + "masterVolume": 1 + } + }] + }; + + var returnPayload = alsa.set(payload); + + jqUnit.assertDeepEq("The system volume is being setted well", + returnPayload["org.alsa-project"][0].settings["masterVolume"].newValue, + payload["org.alsa-project"][0].settings["masterVolume"]); + + var newPayload = fluid.copy(payload); + newPayload["org.alsa-project"][0].settings["masterVolume"] = + returnPayload["org.alsa-project"][0].settings["masterVolume"].oldValue; + + lastPayload = alsa.set(newPayload); + + jqUnit.assertDeepEq("The system volume is being restored well", + returnPayload["org.alsa-project"][0].settings["masterVolume"].oldValue, + lastPayload["org.alsa-project"][0].settings["masterVolume"].newValue); +});