node_vlc_remote/index.js

54 lines
1.2 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", ()=>{
activeFile = "testv.mp4";
player.loadFile(__dirname + "/files/" + activeFile, ()=>{
player.play();
});
}
// END DEBUG
io.on("connection", (socket)=>{
//console.log("client connected:", socket.client.id);
socket.on("play", (data)=>{
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);