node_vlc_remote/index.js

56 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-06-20 09:15:03 +00:00
const DEBUG = process.env.debug | false;
var p = require("./vlc_rc");
2017-06-20 11:07:31 +00:00
var player = new p.VLC_RC({verbose:true, debug:true, manual:false});
2017-06-20 09:15:03 +00:00
var http = require("http").createServer();
var io = require("socket.io")(http);
var activeFile = undefined;
io.on("connection", (socket)=>{
2017-06-20 11:01:53 +00:00
console.log("client connected:", socket.client.id);
2017-06-20 09:15:03 +00:00
socket.on("play", (data)=>{
2017-06-20 11:01:53 +00:00
console.log("Play", data);
2017-06-20 09:15:03 +00:00
activeFile = data.file;
player.loadFile(__dirname + "/files/" + data.file, ()=>{
player.play(()=>{
2017-06-20 11:35:06 +00:00
Update.start();
2017-06-20 12:34:21 +00:00
console.log("playing");
2017-06-20 09:15:03 +00:00
socket.emit("playing", {file: data.file});
});
});
});
socket.on("stop", (data)=>{
player.stop(()=>{
2017-06-20 11:35:06 +00:00
Update.stop();
2017-06-20 09:15:03 +00:00
io.emit("stopped");
});
});
});
2017-06-20 11:35:06 +00:00
class Update {
static start() {
2017-06-20 11:52:53 +00:00
console.log("Starte updates");
2017-06-20 11:35:06 +00:00
Update.interv = setInterval(()=>{
var start
var update_infos = {};
player.getTime((t)=>{
player.getState((playing)=>{
update_infos.file = activeFile;
update_infos.time = t;
update_infos.is_playing = playing;
//update_infos.
io.emit("update", update_infos);
})
});
}, 1000/25)
}
static stop() {
clearInterval(Update.interv);
}
}
2017-06-20 09:15:03 +00:00
http.listen(5000);