commit | author | age
|
60719c
|
1 |
/* |
U |
2 |
AV-Direktor - Control OMXPlayer on Raspberry Pi via HTTP |
|
3 |
Copyright (C) 2021 Ulrich Hilger |
|
4 |
|
|
5 |
This program is free software: you can redistribute it and/or modify |
|
6 |
it under the terms of the GNU Affero General Public License as |
|
7 |
published by the Free Software Foundation, either version 3 of the |
|
8 |
License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU Affero General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU Affero General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
*/ |
|
18 |
|
8e2038
|
19 |
package de.uhilger.avdirektor; |
U |
20 |
|
|
21 |
import com.sun.net.httpserver.HttpServer; |
cc2a32
|
22 |
import de.uhilger.avdirektor.handler.CmdHandler; |
ac1194
|
23 |
import de.uhilger.avdirektor.handler.FileHandler; |
0af362
|
24 |
import de.uhilger.avdirektor.handler.OMXPlayer; |
0c8d27
|
25 |
import de.uhilger.avdirektor.handler.PingHandler; |
8e2038
|
26 |
import de.uhilger.avdirektor.handler.PlayHandler; |
852f20
|
27 |
import de.uhilger.avdirektor.handler.SeekHandler; |
8e2038
|
28 |
import de.uhilger.avdirektor.handler.StopServerHandler; |
U |
29 |
import java.io.IOException; |
|
30 |
import java.util.logging.Logger; |
|
31 |
import java.net.InetSocketAddress; |
cd1557
|
32 |
import java.util.concurrent.Executors; |
8e2038
|
33 |
|
U |
34 |
/** |
|
35 |
* |
|
36 |
* @author ulrich |
|
37 |
*/ |
|
38 |
public class Server { |
|
39 |
|
|
40 |
private static final Logger logger = Logger.getLogger(Server.class.getName()); |
|
41 |
|
|
42 |
|
|
43 |
private int port; |
|
44 |
|
|
45 |
public Server(int port) { |
|
46 |
this.port = port; |
|
47 |
} |
|
48 |
|
|
49 |
public void setPort(int port) { |
|
50 |
this.port = port; |
|
51 |
} |
|
52 |
|
|
53 |
public void start() throws IOException { |
|
54 |
logger.info("Server starting on port " + port); |
0c8d27
|
55 |
|
8e2038
|
56 |
HttpServer server = HttpServer.create(new InetSocketAddress(port), 0); |
0af362
|
57 |
server.createContext("/avd/play", new PlayHandler(OMXPlayer.F_PLAY)); |
U |
58 |
server.createContext("/avd/seek", new SeekHandler(OMXPlayer.F_SEEK)); |
|
59 |
server.createContext("/avd/stop", new CmdHandler(OMXPlayer.CMD_STOP)); |
|
60 |
server.createContext("/avd/pause", new CmdHandler(OMXPlayer.CMD_PAUSE_RESUME)); |
|
61 |
server.createContext("/avd/ping", new PingHandler(OMXPlayer.F_PING)); |
8e2038
|
62 |
server.createContext("/avd/server/stop", new StopServerHandler()); |
ac1194
|
63 |
server.createContext("/avd/ui", new FileHandler(App.getInitParameter(App.IP_WWW_DATA))); |
cd1557
|
64 |
//server.setExecutor(null); // creates a default executor |
U |
65 |
server.setExecutor(Executors.newFixedThreadPool(20)); |
8e2038
|
66 |
server.start(); |
U |
67 |
} |
|
68 |
|
|
69 |
} |