commit 7f9d611ee8701f1defa53a7b9f04d357e7e20883 Author: Fabian Stamm Date: Fri Jun 16 17:34:40 2017 +0200 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/db.json b/db.json new file mode 100644 index 0000000..9ba60fa --- /dev/null +++ b/db.json @@ -0,0 +1,12 @@ +{ + "t2mp4": [ + { + "id": "f786c17431e6", + "time": "1500", + "channel": "1", + "note": "2", + "name": "test", + "value": "5" + } + ] +} \ No newline at end of file diff --git a/files/t2.mp4 b/files/t2.mp4 new file mode 100644 index 0000000..3bf2c1c Binary files /dev/null and b/files/t2.mp4 differ diff --git a/files/testv.mp4 b/files/testv.mp4 new file mode 100644 index 0000000..26740b1 Binary files /dev/null and b/files/testv.mp4 differ diff --git a/index.js b/index.js new file mode 100644 index 0000000..bfeb3ab --- /dev/null +++ b/index.js @@ -0,0 +1,186 @@ +var low = require("lowdb"); +var db = low("db.json"); +var sid = require("short-id"); +sid.configure({length:12}); +db.defaults({}).write(); + +var http = require("http").createServer(); + +var ioClient = require("socket.io-client")("http://localhost:5000"); +var io = require("socket.io")(http); + +var activeFile = undefined; +var toTrigger = []; + +class FrameTime{ + constructor(millis){ + this.lframe = 0; + this.lseconds = 0; + this.lminutes = 0; + this.lhours = 0; + this.lmilliseconds = 0; + if(Number.isInteger(millis)){ + this.milliseconds = millis; + } else if(typeof millis === "object"){ + if(Number.isInteger(millis.frame) && Number.isInteger(millis.seconds) && Number.isInteger(millis.minutes) && Number.isInteger(millis.hours) ){ + this.lframe = millis.frame; //use the local, because its mor performant + this.lseconds = milllis.seconds; + this.lminutes = millis.minutes; + this.lhours = millis.hours; + this.calcMillis(); + } else if(Number.isInteger(millis.milliseconds)){ + this.milliseconds = millis.milliseconds; + } + } + } + + get milliseconds() { + return this.lmilliseconds; + } + + set milliseconds(val) { + this.lmilliseconds = val; + millisToFrame(); + } + + get frame(){ + return this.lframe; + } + + set frame (val) { + this.lframe = val; + calcMillis(); + } + + get seconds() { + return this.lseconds; + } + + set seconds(val){ + this.lseconds = val; + calcMillis(); + } + + get minutes() { + return this.lminutes; + } + + set minutes(val) { + this.lminutes = val; + calcMillis(); + } + + get hours(){ + return this.lhours; + } + + set hours(val){ + this.lhours = val; + calcMillis(); + } + + calcMillis(){ + this.lmilliseconds = (this.frame / 25 * 1000) + this.seconds * 1000 + this.minutes * 60 * 1000 + this.hours * 60 * 60 * 1000; + } + + millisToFrame(millis) { + this.frame = Math.floor((millis % 1000)*25/1000); + this.seconds = Math.floor((millis / 1000) % 60); + this.minutes = Math.floor((millis / (1000*60)) % 60); + this.hours = Math.floor((millis / (1000*60*60)) % 24); + } +} + +ioClient.on("update", (data)=>{ + activeFile = data.file; + var t = data.time; + var ft = new FrameTime(t); + var answer = {}; + answer.time = ft; + answer.timemillis = t; + answer.file = activeFile; + answer.playing = data.playing; + io.emit("update", answer); + +}); + +ioClient.on("playing", (data)=>{ + io.emit("playing", data); +}); + +ioClient.on("stopped", ()=>{ + io.emit("stopped") +}); + +io.on("connection", (socket)=>{ + //console.log("client connected:", socket.client.id); + socket.on("set", (data)=>{ //ToDo preset ids etc. + console.log(data); + var entry = {}; + entry.id = sid.generate(); + entry.time = new FrameTime(data.time); //typof FrameTime + entry.channel = data.channel; + entry.note = data.note; + entry.name = data.name; + data.name = data.name.replace(".", ""); + entry.value = data.value; + if(db.get(data.name).value() === undefined) { + db.set(data.name, []).write(); + } + db.get(data.name).push(entry).write(); + }); + + socket.on("get", (data)=>{ //Requires filename + var v = db.get(data.replace(".", "")).value(); + socket.emit("data", v); + }); + + socket.on("remove", (data)=>{ //requires id + db.get(data.replace(".", "")).remove({id:data}).write(); + }); + + socket.on("load_preset", (data)=>{ + toTrigger = db.get(data.replace(".", "")).value(); + }); + + socket.on("play", (data)=>{ + ioClient.emit("play", data); + }); + + socket.on("stop", (data)=>{ + ioClient.emit("stop", data); + }); +}); + +setInterval(()=>{ + var start + var update_infos = {}; + player.getOrigTime((time)=>{ + player.getTime((t)=>{ + player.getState((playing)=>{ + update_infos.file = activeFile; + update_infos.time = t; + update_infos.is_playing = playing; + update_infos.triggeredMidi = []; + if(playing){ + if(toTrigger){ + toTrigger.forEach(e=>{ + if(e.time <= t){ + var midi = {channel:e.channel, note:e.note, value:e.value} + io.emit("midi", {channel:e.channel, note:e.note, value:e.value}); + var i = toTrigger.indexOf(e); + if (i < 0) return; + toTrigger.splice(i, 1); + update_infos.triggeredMidi.push(midi); + } + }); + } + } + io.emit("update", update_infos); + //console.log(JSON.stringify(update_infos, undefined, 4)); + }) + }); + }); +}, 1000/25) + +http.listen(5000); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..82e5f2c --- /dev/null +++ b/package-lock.json @@ -0,0 +1,280 @@ +{ + "name": "node_vlc_webinterface", + "version": "0.0.1", + "lockfileVersion": 1, + "dependencies": { + "accepts": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.3.tgz", + "integrity": "sha1-w8p0NJOGSMPg2cHjKN1otiLChMo=" + }, + "after": { + "version": "0.8.2", + "resolved": "https://registry.npmjs.org/after/-/after-0.8.2.tgz", + "integrity": "sha1-/ts5T58OAqqXaOcCvaI7UF+ufh8=" + }, + "arraybuffer.slice": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/arraybuffer.slice/-/arraybuffer.slice-0.0.6.tgz", + "integrity": "sha1-8zshWfBTKj8xB6JywMz70a0peco=" + }, + "assertion-error": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.0.0.tgz", + "integrity": "sha1-x/hUOP3UZrx8oWq5DIFRN5el0js=" + }, + "backo2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/backo2/-/backo2-1.0.2.tgz", + "integrity": "sha1-MasayLEpNjRj41s+u2n038+6eUc=" + }, + "base64-arraybuffer": { + "version": "0.1.5", + "resolved": "https://registry.npmjs.org/base64-arraybuffer/-/base64-arraybuffer-0.1.5.tgz", + "integrity": "sha1-c5JncZI7Whl0etZmqlzUv5xunOg=" + }, + "base64id": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/base64id/-/base64id-1.0.0.tgz", + "integrity": "sha1-R2iMuZu2gE8OBtPnY7HDLlfY5rY=" + }, + "better-assert": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/better-assert/-/better-assert-1.0.2.tgz", + "integrity": "sha1-QIZrnhueC1W0gYlDEeaPr/rrxSI=" + }, + "blob": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/blob/-/blob-0.0.4.tgz", + "integrity": "sha1-vPEwUspURj8w+fx+lbmkdjCpSSE=" + }, + "callsite": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/callsite/-/callsite-1.0.0.tgz", + "integrity": "sha1-KAOY5dZkvXQDi28JBRU+borxvCA=" + }, + "component-bind": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz", + "integrity": "sha1-AMYIq33Nk4l8AAllGx06jh5zu9E=" + }, + "component-emitter": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/component-emitter/-/component-emitter-1.2.1.tgz", + "integrity": "sha1-E3kY1teCg/ffemt8WmPhQOaUJeY=" + }, + "component-inherit": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/component-inherit/-/component-inherit-0.0.3.tgz", + "integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "debug": { + "version": "2.6.8", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz", + "integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=" + }, + "engine.io": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/engine.io/-/engine.io-3.1.0.tgz", + "integrity": "sha1-XKQ4486f28kVxKIcjdnhJmcG5X4=" + }, + "engine.io-client": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/engine.io-client/-/engine.io-client-3.1.1.tgz", + "integrity": "sha1-QVqYUrrbFPoAj6PvHjFgjbZ2EyU=" + }, + "engine.io-parser": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/engine.io-parser/-/engine.io-parser-2.1.1.tgz", + "integrity": "sha1-4Ps/DgRi9/WLt3waUun1p+JuRmg=" + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "has-binary2": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-binary2/-/has-binary2-1.0.2.tgz", + "integrity": "sha1-6D26SfC5vk0CbSc2U1DZ8D9Uvpg=" + }, + "has-cors": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-cors/-/has-cors-1.1.0.tgz", + "integrity": "sha1-XkdHk/fqmEPRu5nCPu9J/xJv/zk=" + }, + "indexof": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/indexof/-/indexof-0.0.1.tgz", + "integrity": "sha1-gtwzbSMrkGIXnQWrMpOmYFn9Q10=" + }, + "is-promise": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-2.1.0.tgz", + "integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=" + }, + "isarray": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.1.tgz", + "integrity": "sha1-o32U7ZzaLVmGXJ92/llu4fM4dB4=" + }, + "lodash": { + "version": "4.17.4", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.4.tgz", + "integrity": "sha1-eCA6TRwyiuHYbcpkYONptX9AVa4=" + }, + "lowdb": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/lowdb/-/lowdb-0.16.2.tgz", + "integrity": "sha1-oql262bsV3lykZcPPIfNthEm+jo=" + }, + "merge-recursive": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/merge-recursive/-/merge-recursive-0.0.3.tgz", + "integrity": "sha1-3nkB78rsyQbYyrKtHpxHD1o9roQ=" + }, + "mime-db": { + "version": "1.27.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.27.0.tgz", + "integrity": "sha1-gg9XIpa70g7CXtVeW13oaeVDbrE=" + }, + "mime-types": { + "version": "2.1.15", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.15.tgz", + "integrity": "sha1-pOv1BkCUVpI3uM9wBGd20J/JKu0=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, + "oath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/oath/-/oath-1.0.0.tgz", + "integrity": "sha1-L04fd5e5A6eLJDUn3GgkWwrrDVg=" + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "object-component": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/object-component/-/object-component-0.0.3.tgz", + "integrity": "sha1-8MaapQ78lbhmwYb0AKM3acsvEpE=" + }, + "parsejson": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/parsejson/-/parsejson-0.0.3.tgz", + "integrity": "sha1-q343WfIJ7OmUN5c/fQ8fZK4OZKs=" + }, + "parseqs": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/parseqs/-/parseqs-0.0.5.tgz", + "integrity": "sha1-1SCKNzjkZ2bikbouoXNoSSGouJ0=" + }, + "parseuri": { + "version": "0.0.5", + "resolved": "https://registry.npmjs.org/parseuri/-/parseuri-0.0.5.tgz", + "integrity": "sha1-gCBKUNTbt3m/3G6+J3jZDkvOMgo=" + }, + "safe-buffer": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.0.1.tgz", + "integrity": "sha1-0mPKVGls2KMGtcplUekt5XkY++c=" + }, + "sechash": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/sechash/-/sechash-0.2.1.tgz", + "integrity": "sha1-i3H+R9aCcvR6NfFkDkzJITJbEzs=" + }, + "short-id": { + "version": "0.1.0-1", + "resolved": "https://registry.npmjs.org/short-id/-/short-id-0.1.0-1.tgz", + "integrity": "sha1-pMDzU3//RiP/hJZIgrXUMBmiQJU=" + }, + "simple-assert": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/simple-assert/-/simple-assert-1.0.0.tgz", + "integrity": "sha1-U/F5AADXFEJBJCkHgLwqPlEc8O8=" + }, + "socket.io": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/socket.io/-/socket.io-2.0.3.tgz", + "integrity": "sha1-Q1nwaiSTOua9CHeYr3jGgOrjReM=" + }, + "socket.io-adapter": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/socket.io-adapter/-/socket.io-adapter-1.1.0.tgz", + "integrity": "sha1-x6pGUB3VVsLLiiivj/lcC14dqkw=", + "dependencies": { + "debug": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.3.3.tgz", + "integrity": "sha1-QMRT5n5uE8kB3ewxeviYbNqe/4w=" + }, + "ms": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-0.7.2.tgz", + "integrity": "sha1-riXPJRKziFodldfwN4aNhDESR2U=" + } + } + }, + "socket.io-client": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/socket.io-client/-/socket.io-client-2.0.3.tgz", + "integrity": "sha1-bK9K/5+FsZ/ZG2zhPWmttWT4hzs=" + }, + "socket.io-parser": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/socket.io-parser/-/socket.io-parser-3.1.2.tgz", + "integrity": "sha1-28IoIVH8T6675Aru3Ady66YZ9/I=" + }, + "steno": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/steno/-/steno-0.4.4.tgz", + "integrity": "sha1-BxEFvfwobmYVwEA8J+nXtdy4Vcs=" + }, + "to-array": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/to-array/-/to-array-0.1.4.tgz", + "integrity": "sha1-F+bBH3PdTz10zaek/zI46a2b+JA=" + }, + "ultron": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/ultron/-/ultron-1.1.0.tgz", + "integrity": "sha1-sHoualQagV/Go0zNRTO67DB8qGQ=" + }, + "uws": { + "version": "0.14.5", + "resolved": "https://registry.npmjs.org/uws/-/uws-0.14.5.tgz", + "integrity": "sha1-Z6rzPEaypYel9mZtAPdpEyjxSdw=", + "optional": true + }, + "ws": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-2.3.1.tgz", + "integrity": "sha1-a5Sz5EfLajY/eF6vlK9jWejoHIA=" + }, + "xmlhttprequest-ssl": { + "version": "1.5.3", + "resolved": "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.5.3.tgz", + "integrity": "sha1-GFqIjATspGw+QHDZn3tJ3jUomS0=" + }, + "yeast": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/yeast/-/yeast-0.1.2.tgz", + "integrity": "sha1-AI4G2AlDIMNy28L47XagymyKxBk=" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..fb83f58 --- /dev/null +++ b/package.json @@ -0,0 +1,34 @@ +{ + "name": "node_vlc_webinterface", + "version": "0.0.1", + "description": "", + "main": "index.js", + "scripts": { + "test": "node test.js", + "start": "node index.js" + }, + "repository": { + "type": "git", + "url": "git://github.com/margau/node_vlc_rc.git" + }, + "keywords": [ + "vlc", + "media", + "player", + "streaming", + "remote", + "video" + ], + "author": "Fabian Stamm ", + "license": "MIT", + "bugs": { + "url": "https://github.com/margau/node_vlc_rc/issues" + }, + "homepage": "https://github.com/margau/node_vlc_rc#readme", + "dependencies": { + "lowdb": "^0.16.2", + "short-id": "0.1.0-1", + "socket.io": "^2.0.3", + "socket.io-client": "^2.0.3" + } +}