1 | /*
|
2 |
|
3 | BSD LICENSED
|
4 |
|
5 | Copyright (c) 2011, Janne Julkunen
|
6 | All rights reserved.
|
7 |
|
8 | Redistribution and use in source and binary forms, with or without modification,
|
9 | are permitted provided that the following conditions are met:
|
10 |
|
11 | * Redistributions of source code must retain the above copyright notice, this
|
12 | list of conditions and the following disclaimer.
|
13 |
|
14 | * Redistributions in binary form must reproduce the above copyright notice,
|
15 | this list of conditions and the following disclaimer in the documentation
|
16 | and/or other materials provided with the distribution.
|
17 |
|
18 | *Neither the name of the Enlightened Linux Solutions nor the names of its
|
19 | contributors may be used to endorse or promote products derived from this
|
20 | software without specific prior written permission.
|
21 |
|
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
23 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
24 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
25 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
26 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
27 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
28 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
29 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
30 | OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
31 | OF THE POSSIBILITY OF SUCH DAMAGE.
|
32 |
|
33 | */
|
34 |
|
35 | var exec = require('child_process').exec;
|
36 |
|
37 | exports.setup = function(cb) {
|
38 | var child = exec("totem --help", function(error, stdout, stderr) {
|
39 | if(error)
|
40 | cb(null);
|
41 | else
|
42 | cb("totem", "Totem", "Video Player");
|
43 | });
|
44 | };
|
45 |
|
46 | exports.execute = function(req, res) {
|
47 | console.log("Executing totem command: " + req.params[0]);
|
48 |
|
49 | if(req.params[0] != "close")
|
50 | var execute_string = "pgrep totem";
|
51 | else
|
52 | var execute_string = "totem --quit";
|
53 |
|
54 | var child = exec(execute_string, function(error, stdout, stderr) {
|
55 | if((stdout.length > 0) || (req.params[0] == "start")) {
|
56 | var execute_string = "";
|
57 |
|
58 | if(req.params[0] == "start") {
|
59 | var execute_string = "totem;";
|
60 | } else if(req.params[0] == "play-pause") {
|
61 | var execute_string = "totem --play-pause;";
|
62 | } else if(req.params[0] == "seek") {
|
63 | var execute_string = "totem --seek-" + req.param("action") + ";";
|
64 | } else if(req.params[0] == "mute") {
|
65 | var execute_string = "totem --mute;";
|
66 | } else if(req.params[0] == "fullscreen") {
|
67 | var execute_string = "totem --fullscreen;";
|
68 | } else if(req.params[0] == "volume") {
|
69 | var execute_string = "totem --volume-" +
|
70 | req.param("action") + ";";
|
71 | }
|
72 |
|
73 | var child = exec(execute_string, function(error, stdout, stderr) {
|
74 | res.header('Content-Type', 'text/javascript');
|
75 |
|
76 | if(error !== null) {
|
77 | res.send({"state": "unknown"});
|
78 | } else {
|
79 | res.send({"state": "running"});
|
80 | }
|
81 | });
|
82 | } else {
|
83 | res.send({"state": "closed"});
|
84 | }
|
85 | });
|
86 | };
|
87 |
|