node_vlc_remote/index.js

56 lines
1.3 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");
var player = new p.VLC_RC({verbose:true, debug:false, manual:false});
var http = require("http").createServer();
var io = require("socket.io")(http);
var activeFile = undefined;
// DEBUG
if(DEBUG){
//player.loadFile(__dirname + "/files/testv.mp4", ()=>{
2017-06-20 11:01:53 +00:00
console.log("DEBUG");
2017-06-20 09:15:03 +00:00
activeFile = "testv.mp4";
player.loadFile(__dirname + "/files/" + activeFile, ()=>{
player.play();
});
}
// END DEBUG
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(()=>{
socket.emit("playing", {file: data.file});
});
});
});
socket.on("stop", (data)=>{
player.stop(()=>{
io.emit("stopped");
});
});
});
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)
http.listen(5000);